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 |
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?
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
I took the original idea from this gist.
Options
On: turns on the display and the HDMI port.
Off: turns off the display and the HDMI port.
Status: prints the currents status of the display and HDMI port.
Important
For it to work your display must have CEC and you need to install cec-utils, you can do the latter by running
sudo apt-get install cec-utils
.(If your display doesn't have CEC you can delete lines: 10, 11, 12, 13, 17, 22, 34, 35, 36, 37, 38 & 39 to make it work without using CEC).
Sources: Rpi CEC - HowTo Shell Script - vcgencmd