Skip to content

Instantly share code, notes, and snippets.

@SirCrocker
Last active April 5, 2023 11:07
Show Gist options
  • Save SirCrocker/937d06f8f2c1227a83802b9b77f60ba0 to your computer and use it in GitHub Desktop.
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.
#!/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
@JMS1717
Copy link

JMS1717 commented Apr 4, 2019

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?

@SirCrocker
Copy link
Author

SirCrocker commented Apr 5, 2019

Yes, if you installed cec-utils it should work. For me at least, its been working with no problems.

@Some1Elsewhere
Copy link

works perfectly. Thank you!

@TheDarkerPath
Copy link

Works perfectly, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment