Skip to content

Instantly share code, notes, and snippets.

@neaxi
Created September 30, 2020 20:40
Show Gist options
  • Save neaxi/2779ff00496bf2e9cf44fd8e5847f853 to your computer and use it in GitHub Desktop.
Save neaxi/2779ff00496bf2e9cf44fd8e5847f853 to your computer and use it in GitHub Desktop.
RasPi - Turn HDMI on or off based on current state
# if the status contains "TV is off", turn it on
# otherwise turn it off
# /opt/vc/bin/tvservice -s | grep "TV is off" > /dev/null && /opt/vc/bin/tvservice -p || /opt/vc/bin/tvservice -o
# tvservice leaves blank screen without refresh
# https://www.raspberrypi.org/forums/viewtopic.php?t=249308
# workarounds:
# a) use `fbset -depth 8 && fbset -depth 16` after turning on the display
# b) use `vcgencmd display_power`
# https://www.raspberrypi.org/documentation/raspbian/applications/vcgencmd.md
vcgencmd display_power | grep 0 > /dev/null && vcgencmd display_power 1 || vcgencmd display_power 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment