Last active
April 5, 2023 11:07
-
-
Save SirCrocker/937d06f8f2c1227a83802b9b77f60ba0 to your computer and use it in GitHub Desktop.
Turn off and on the HDMI port and the TV. Options: on, off & status.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Enable and disable TV/HDMI | |
hdmi_status () | |
{ | |
vcgencmd display_power | grep "display_power=0" >/dev/null | |
} | |
cec_status () | |
{ | |
echo pow 0 | cec-client -s -d 1 | grep "power status: standby" >/dev/null | |
} | |
case $1 in | |
on) | |
echo on 0 | cec-client -s -d 1 | grep "opening a connection to the CEC adapter..." >/dev/null | |
vcgencmd display_power 1 | grep "display_power=1" >/dev/null | |
echo "Display and HDMI have been turned on by user." | |
;; | |
off) | |
echo standby 0 | cec-client -s -d 1 | grep "opening a connection to the CEC adapter..." >/dev/null | |
vcgencmd display_power 0 | grep "display_power=0" >/dev/null | |
echo "Display and HDMI have been turned off by user." | |
;; | |
status) | |
if hdmi_status | |
then | |
echo "The HDMI port is OFF" | |
else | |
echo "The HDMI port is ON" | |
fi | |
if cec_status | |
then | |
echo "The display is turned OFF" | |
else | |
echo "The display is turned ON" | |
fi | |
;; | |
*) | |
echo "Usage: $0 on|off|status" >&2 | |
exit 2 | |
;; | |
esac | |
exit 0 |
Yes, if you installed cec-utils it should work. For me at least, its been working with no problems.
works perfectly. Thank you!
Works perfectly, thanks so much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I was having a problem with my previous rpi-hdmi-tv.sh so can I just copy and paste this in that file in that file and it will work?