#!/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 |
This comment has been minimized.
This comment has been minimized.
Just a note to other users, the fgconsole command must be called with sudo privileges or you will get an error:
|
This comment has been minimized.
This comment has been minimized.
@Chalta - are you saying you modified the line from: |
This comment has been minimized.
This comment has been minimized.
Hello |
This comment has been minimized.
This comment has been minimized.
@IBKDan I found some comments suggesting vcgencmd instead of tvservice (info here). I forked this and used vcgencmd instead. So far no issues, and no need for sudo. |
This comment has been minimized.
This comment has been minimized.
Hi all. I am trying to use this script to turn my raspberry pi on/off at different times depending if its a work day or a weekend. My requirements: Sat-Sun: (leave it on all day) So since I have a global on and off time of 7AM and 11PM every day we could say: Then for the weekdays: My question to you is one of order — how do I know if these will be executed in this order? Is there a better way to write this? |
This comment has been minimized.
This comment has been minimized.
@leemcarthur: Did you ever figure out a solution to that? |
This comment has been minimized.
This comment has been minimized.
@leemcarthur: Did you ever figure out a solution? Here's the solution. I think you will have problem each on/off for each day. See http://ediy.com.my/index.php/tutorials/item/106-raspberry-pi-schedule-turn-off-on-display |
This comment has been minimized.
This comment has been minimized.
@Chalta if you add sudo to all of the commands, that should fix teh Couldn't get a file descriptor referring to the console error, #!/bin/sh Enable and disable HDMI output on the Raspberry Piis_off () case $1 in |
This comment has been minimized.
This comment has been minimized.
Hi, never done any coding whatsoever before, but thought I’d try my hand with dakboard. I’ve loaded it up and working on my monitor through raspberry pi, and followed the script above but I’m getting lost with how to complete the rest of it. Is there an idiots guide to getting this to work? |
This comment has been minimized.
This comment has been minimized.
@usafle & @wmcollins - yes I did figure it out. I wrote out the syntax here after much trial and error: I have a whole other issue with crontab not running at all, or rather, running two processes right now: ps -eaf | grep cron Output is: root 360 1 0 20:58 ? 00:00:00 /usr/sbin/cron -f So its running as the pi user as well as root? Could this be the issue why my rpi-hdmi.sh script isn't running? |
This comment has been minimized.
This comment has been minimized.
@leemcarthur - not sure if you got your answer, but the second cron you see is actually capturing that the second part of your command (grep cron) is running. |
This comment has been minimized.
This comment has been minimized.
Couldn't make this script work right on Pi3's.. screen would go off, then never go back on, error message was "failed to set" Searched and found:tvservice is not the best to turn off and on the screen. Much better way to do this (found after a day of searching) is using vcgencmd command (more on this here).
|
This comment has been minimized.
This comment has been minimized.
I am a senior citizen, with the ambition to use DAKboard to coordinate daily activities between myself and my wife. We have entered the stage in life were we often forget what we are told by the other. DAKboard is perfect for the purpose to keep each other updated on what is coming up the next days. I am not at all familiar with coding, but my experience is good with cut and paste. So DIASHER (my screen also does not come back on in he morning), what would the totalt script look like? Are you able to give me a hand? |
This comment has been minimized.
This comment has been minimized.
Hi @DonSpain, in case you haven't found an answer yet I made a small script that uses vcgencmd and works with DAKboard. |
This comment has been minimized.
This comment has been minimized.
@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? |
This comment has been minimized.
This comment has been minimized.
It works on Raspberry Pi 4, but is necessary run it twice for HDMI poweroff. |
This comment has been minimized.
This comment has been minimized.
@quelleck, your fork worked perfectly on my Raspberry PI with the latest version of Rasbian as of Jan 2020. Thank you! |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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? |
This comment has been minimized.
This comment has been minimized.
sudo vcgencmd display_power 0 Turns off video output. sudo vcgencmd display_power 1 Turns on video output. More easy no? |
This comment has been minimized.
This comment has been minimized.
don't work... |
This comment has been minimized.
I have a standard console on VT1 and X11 on VT2. When I ran your script initially, it wasn't working. I poked around a bit and it seems that the VT numbers were getting mixed up for some reason. I added some sleeps in between the
chvt
commands and that seems to have fixed things. I let it burn in for a few hours running:while true; do sudo ./rpi-hdmi off; sleep 10; sudo ./rpi-hdmi on; sleep 60; done
...and it seems to be working consistently now. Thanks for your help with this solution!