💻 HDMI monitor standby on Raspbian

14 Jul 2015

Last week project was to get a cheap TV in the bedrooms of the house, but cheap things have cons of course. After some research a HDMI monitor hooked on Raspberry Pi seemed the solution. It was a good choice, though i had a hard time to put the screen standby together. Since there is no working screen standby in XBMC/Kodi for the Raspi. In case you use the “tvservice” command then you have to restart the XBMC/Kodi, to get out of blank screen.

I was using the following python snippet, because this way there is nothing pops up (like terminal) and it’s just works.

[code language=”python”] #!/usr/bin/python

import subprocess import string import os.path

if (os.path.isfile("/tmp/screen.state") == False): subprocess.call( "touch /tmp/screen.state", shell=True)

result = subprocess.check_output("cat /tmp/screen.state", shell=True)

if (result.find ("f") >0 ): subprocess.call( "/opt/vc/bin/vcgencmd display_power 1", shell=True ) subprocess.call( "echo ‘On’ > /tmp/screen.state" , shell=True ) else: subprocess.call( "/opt/vc/bin/vcgencmd display_power 0", shell=True ) subprocess.call( "echo ‘Off’ > /tmp/screen.state", shell=True ) [/code]

Save it as sleepstate.py in your home directory:

[code language=”bash”]nano ~/sleepscreen.py[/code]

Then it’s possible to call the script from XBMC/Kodi:

[code language=”xml”]RunScript("/home/osmc/sleepscreen.py")[/code]

For example to map it on the power button of the remote, create a keymap.xml in your .kodi/userdata/keymaps:

[code language=”bash”]nano ~/.kodi/userdata/keymaps/keymap.xml[/code]

Then paste the following example:

[code language=”xml”] <keymap> <global> <remote> <red>RunScript("/home/osmc/sleepstate.py")</red> </remote> </global> </keymap> [/code]