Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable and disable the HDMI port on the Raspberry Pi: `rpi-hdmi on` to turn on, `rpi-hdmi off` to turn off. X is properly reinitialized when re-enabling.
#!/bin/sh
# Enable and disable HDMI output on the Raspberry Pi
is_off ()
{
tvservice -s | grep "TV is off" >/dev/null
}
case $1 in
off)
tvservice -o
;;
on)
if is_off
then
tvservice -p
curr_vt=`fgconsole`
if [ "$curr_vt" = "1" ]
then
chvt 2
chvt 1
else
chvt 1
chvt "$curr_vt"
fi
fi
;;
status)
if is_off
then
echo off
else
echo on
fi
;;
*)
echo "Usage: $0 on|off|status" >&2
exit 2
;;
esac
exit 0
@SirCrocker
Copy link

SirCrocker commented Mar 8, 2019

Hi @DonSpain, in case you haven't found an answer yet I made a small script that uses vcgencmd and works with DAKboard.
(Link to it: https://gist.github.com/SirCrocker/937d06f8f2c1227a83802b9b77f60ba0)

@JMS1717
Copy link

JMS1717 commented Apr 4, 2019

@SirCrocker can you copy and paste this INSTEAD of the TV Service one or do you have to do other stuff in crontab to accommodate?

@LFAB3
Copy link

LFAB3 commented Sep 2, 2019

It works on Raspberry Pi 4, but is necessary run it twice for HDMI poweroff.
Thanks!

@manconti
Copy link

manconti commented Jan 29, 2020

@quelleck, your fork worked perfectly on my Raspberry PI with the latest version of Rasbian as of Jan 2020. Thank you!

@jomy-matthews
Copy link

jomy-matthews commented May 3, 2020

Good script. Is there a similar script to disable the SPI port at night time? I have a youtube subscribers LCD running along with the Dakboard setup and I want them both to turn off at the same time. Will the same code above also work for the SPI port? Thanks in advance.

@JeedHome44
Copy link

JeedHome44 commented Jan 22, 2021

hello, my raspberry Pi3B + Recalbox activates my automatic HDMI switch even when the Pi has no power. So this script allows you to completely disable the HDMI port when the Pi is turned off?

@JeedHome44
Copy link

JeedHome44 commented Jan 22, 2021

sudo vcgencmd display_power 0

Turns off video output.

sudo vcgencmd display_power 1

Turns on video output.

More easy no?

@JeedHome44
Copy link

JeedHome44 commented Jan 22, 2021

don't work...

@macninja
Copy link

macninja commented Jul 29, 2021

I couldn't get it to work so I rewrote it to use cec-hdmi instead.

https://gist.github.com/macninja/6c13596f06206eec162f9dce1fc4313b

I have it working on a Raspberry Pi 4. But only in HDMI port 2.

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