#!/bin/bash -e | |
# /usr/local/sbin/raspi-monitor | |
# Script to enable and disable the HDMI signal of the Raspberry PI | |
# Inspiration: http://www.raspberrypi.org/forums/viewtopic.php?t=16472&p=176258 | |
CMD="$1" | |
function on { | |
/opt/vc/bin/tvservice --preferred | |
# Hack to enable virtual terminal nr 7 again: | |
chvt 6 | |
chvt 7 | |
} | |
function off { | |
/opt/vc/bin/tvservice --off | |
} | |
function must_be_root { | |
if [ $USER != root ]; then | |
echo "ERROR: Script must be executed as the root user" | |
exit 1 | |
fi | |
} | |
function main { | |
must_be_root | |
if [ "$CMD" == "on" ]; then | |
on | |
elif [ "$CMD" == "off" ]; then | |
off | |
else | |
echo "Usage: $0 <on|off>" | |
exit 1 | |
fi | |
exit 0 | |
} | |
main |
# /etc/cron.d/raspi-monitor-scheduler | |
# Enable the monitor every weekday morning at 8:00 | |
0 8 * * 1,2,3,4,5 root /usr/local/sbin/raspi-monitor on > /dev/null 2>&1 | |
# Disable the monitor every weekday evening at 17:30 | |
30 17 * * 1,2,3,4,5 root /usr/local/sbin/raspi-monitor off > /dev/null 2>&1 |
This comment has been minimized.
This comment has been minimized.
Thanks a lot. Is there any way to remove or hide the "No Signal" message on tv? |
This comment has been minimized.
This comment has been minimized.
My graphical Display is on 2, so I had to change chvt 7 to chvt 2! |
This comment has been minimized.
This comment has been minimized.
You can get your current VT with fgconsole. This would let you check and be sure to change to a different one, as well as change back to the original VT. |
This comment has been minimized.
This comment has been minimized.
If you'd like to use a Python script to turn off an HDMI-connected monitor when the screensaver "blanks" the screen, this one seems to work on my Raspberry Pi 3. To run this script at login, you can put it script in a file in your .local/bin directory and add a line to your lxsession autostart file, e.g.: Assumption: xscreensaver is installed.
|
This comment has been minimized.
This comment has been minimized.
Apparently, this is the better way to turn off and turn on the display power now:
This is reflected in @sinrig's post but it's hard to spot. |
This comment has been minimized.
This comment has been minimized.
Is there any way of forcing the HDMI to only display a Framebuffer from a certain virtual console and block the Raspberry from switching automatically to the virtual console 1 when something is typed in the keyboard? |
This comment has been minimized.
This comment has been minimized.
Sinrig's solution works fine, with a couple of minuses.
I included a line 'time.sleep(0.5)' in the loop (and ' import time' near the top) to prevent 2, but haven't found a solution for 1 yet. Not that it happens a lot that I log off, usually power down or reboot. --Edit I have to take my words back on 1, it stopped now. Earlier today I found I had 3 copies running at 100% CPU and a thermometer warning icon at the right hand top of my desktop after logging off and back on a couple of times, can't explain why. |
This comment has been minimized.
This comment has been minimized.
Unfortunately, this no longer works on the Raspberry Pi 4. |
This comment has been minimized.
This comment has been minimized.
now works again |
This comment has been minimized.
It worked perfectly! Thanks for sharing!