Kodi Community Forum

Full Version: XBMC on Pi: Add TV/monitor Power Save support when idle?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11
Just wondering why XBMC on the Pi never allows the TV/monitor screen to switch off when XBMC is idle - at least, it's not happening for me with OpenELEC and an LG monitor which supports power save.

I'm using the "Dim" screensaver, set to 3 minutes, and it forever remains on dim when I would expect it to eventually switch off the monitor after the screen has been dimmed for several minutes - this is how it works on x86 builds of OpenELEC, so why not the Pi?
cec settings?
Its a monitor - it has no CEC support,, though CEC shouldn't be a pre-requisite for power saving, this has been a standard for 15+ years.
I've seen it discussed before. IIRC, the PI can't reliably cut power to just HDMI on-the-fly without going into a kind of suspend mode that requires a reboot to get out of.
(2013-04-23, 19:57)Ned Scott Wrote: [ -> ]I've seen it discussed before. IIRC, the PI can't reliably cut power to just HDMI on-the-fly without going into a kind of suspend mode that requires a reboot to get out of.

There certainly seems to be some truth to this, as you can turn off the HDMI with
Code:
tvservice -o

but turning HDMI back on with:
Code:
tvservice -p
doesn't work. Although the monitor comes out of power save mode, and tvservice thinks the status of HDMI has now been restored, the on screen image remains black (the monitor backlight is on, it's just that nothing is visible).

So is this just a firmware issue? It would be really nice if power save could be implemented successfully.
(2013-04-23, 19:57)Ned Scott Wrote: [ -> ]I've seen it discussed before. IIRC, the PI can't reliably cut power to just HDMI on-the-fly without going into a kind of suspend mode that requires a reboot to get out of.

Sure it can.
"tvservice -o" will power off hdmi. "tvservice -p" will power it back on. Try it. Then re-launch xbmc and it will be fine.

One issue is once it's powered back on the EGL context need to be recreated (hence the need to relaunch xbmc).

But, I'm not aware of xbmc having any infrastructure for this - does it?
(2013-04-23, 20:09)popcornmix Wrote: [ -> ]One issue is once it's powered back on the EGL context need to be recreated (hence the need to relaunch xbmc).

Ah right, yes that works...
Code:
rpi512:~ # tvservice -o
Powering off HDMI
rpi512:~ # tvservice -p
Powering on HDMI with preferred settings
rpi512:~ # killall xbmc.bin

and when XBMC restarts it is displayed correctly.

(2013-04-23, 20:09)popcornmix Wrote: [ -> ]But, I'm not aware of xbmc having any infrastructure for this - does it?

I'm guessing a lot of work will be needed to get it implemented, is there any way to preserve the EGL context (no idea what this means btw!)

Or maybe we need a "special" Raspberry Pi screensaver that handles all of this, including re-creating the EGL context (preferably without restarting XBMC).
EGL Context i the window and what creates the GLES context (what we use for rendering). The current code isn't really written to handle a restart of just that subsystem afaik. But it might not be extremely hard to abstract it so that it can.

Generally game engine uses handle based abstraction for this. Something which should be very doable to add to current code afaik. The code for general GUI rendering is semi localized to a few classes.
That sounds promising, maybe something can be added in future updates to help the Pi. Assuming the Pi becomes extremely popular as an XBMC target (which seems fairly likely), enabling power saving features would be most beneficial (for the environment blah blah).
I vote to make this possible as well, my relatives require this functionality because they go asleep fairly often while they watch movies and letting TV be always on is very bad for both environment and our electricity bills.
Any development about this Add-On!?!?

Just installed my Pi on a tv that have a shuntdown timer when no signal is detected!!
If anyone is desperate for a power saving feature - no matter how clunky - you might want to give the following script a go. It's been tested on the latest OpenELEC Gotham and Raspbmc builds.

Does work with OpenELEC Frodo 3.x.x builds, however requires an extra hack to work around a couple of problems with OpenELEC Frodo.

Installation
SSH into your OpenELEC Pi as root, then run the following commands:
Code:
curl -Ls http://is.gd/XGXbTG -o /storage/texturecache.py
chmod +x /storage/texturecache.py
echo "(sleep 20 && /storage/texturecache.py @logfile= @xbmc.host=localhost rbphdmi) &" >> /storage/.config/autostart.sh
sync
reboot

And for Raspbmc owners:
Code:
wget -q http://is.gd/XGXbTG -O ~/texturecache.py
chmod +x ~/texturecache.py
~/texturecache.py @logfile= @xbmc.host=localhost @bin.tvservice=/opt/vc/bin/tvservice rbphdmi
(Not entirely sure what options Raspbmc owners have for automatically starting a script at boot - TBC).

The script is normally silent, but if you add @debug=yes to the command line it will generate some output, eg.:
Code:
Nov 26 10:01:39 rpi512 sh[1429]: [rbphdmi] Connecting to XBMC...
Nov 26 10:01:39 rpi512 sh[1429]: [rbphdmi] HDMI power management thread - initialising XBMC and HDMI state
Nov 26 10:01:39 rpi512 sh[1429]: [rbphdmi] HDMI is [on], Screensaver is [inactive], Player is [inactive], Library scan [inactive]
...
Nov 26 10:03:03 rpi512 sh[1429]: [rbphdmi] Screensaver has activated
Nov 26 10:03:03 rpi512 sh[1429]: [rbphdmi] HDMI power off in 900 seconds unless cancelled
...
Nov 26 10:10:25 rpi512 sh[1429]: [rbphdmi] Screensaver has deactivated
Nov 26 10:10:25 rpi512 sh[1429]: [rbphdmi] HDMI power-off cancelled
...
Nov 26 10:11:36 rpi512 sh[1429]: [rbphdmi] Screensaver has activated
Nov 26 10:11:36 rpi512 sh[1429]: [rbphdmi] HDMI power off in 900 seconds unless cancelled
...
Nov 26 10:26:36 rpi512 sh[1429]: [rbphdmi] HDMI has been powered off
...
Nov 26 10:27:44 rpi512 sh[1429]: [rbphdmi] Screensaver has deactivated
Nov 26 10:27:44 rpi512 sh[1429]: [rbphdmi] HDMI has been powered on
Nov 26 10:27:44 rpi512 sh[1429]: [rbphdmi] Sending Application.Quit() to XBMC
Nov 26 10:27:44 rpi512 sh[1429]: [rbphdmi] Disconnected from XBMC - waiting for restart
Nov 26 10:27:59 rpi512 sh[1429]: [rbphdmi] Connecting to XBMC...
Nov 26 10:27:59 rpi512 sh[1429]: [rbphdmi] HDMI power management thread - initialising XBMC and HDMI state
Nov 26 10:28:00 rpi512 sh[1429]: [rbphdmi] HDMI is [on], Screensaver is [inactive], Player is [inactive], Library scan [inactive]
...

To view these lines, use the following commands:
OpenELEC Gotham:
Code:
journalctl --follow | grep rbphdmi
OpenELEC Frodo:
Code:
tail -f /var/log/messages | grep rbphdmi

Remember there is a 20 second delay before the script starts (when using OpenELEC), as it needs to wait until the JSON RPC server is enabled. Increase this "sleep" value if your system is slower to start. You'll also need to enable the following two options in Settings -> Services -> Remote control:
Code:
Allow programs on this system to control XBMC
Allow programs on other systems to control XBMC

If you also want CEC control whenever HDMI is disabled or enabled, see the instructions in post #17.

This is not an addon or a screensaver, it's a script (daemon) that monitors JSON notifications and when it sees that the screensaver has been activated it starts a timer that will, when it elapses (default 900 seconds), remove HDMI power with a call to "tvservice --off".

If the screensaver is deactivated before the timer has elapsed, the timer is cancelled and the system continues normally.

When the screensaver is deactivated through user activity and HDMI power is off, the HDMI power will be restored (tvservice --preferred) followed by a JSON call to Application.Quit() so that XBMC terminates and is automatically restarted - not rebooted - and the EGL context restored. This takes about 15 seconds from deactivating the screensaver to the menu re-appearing on a 1GHz Pi running a nightly build of OpenELEC Gotham.

Update: When using Raspberry Pi firmware from 23 May 2014 onwards (check with vcgencmd version), "vcgencmd display_power 0" and "vcgencmd display_power 1" will be used to disable/enable HDMI as this method does NOT require xbmc.bin to be restarted. See this post for further details.

Configure the delay between the screensaver starting and HDMI power being terminated by specifying a value (in seconds) in /storage/.config/autostart.sh, for instance if you want a delay of 30 minutes (1800 seconds) change the line to:
Code:
(sleep 20 && /storage/texturecache.py @logfile= @xbmc.host=localhost rbphdmi 1800) &

Yes, it's a clunky solution but hey, it does at least work and until there's a proper solution, it's all there is! Smile
Updated previous post to reflect the fact that Raspberry Pi HDMI power management is now an integrated function of texturecache.py (it's got all the JSON and auto-update plumbing, so the extra code isn't significant even if it doesn't seem like the obvious choice). This makes it a much more efficient and lighter weight process, plus it's a bit smarter as it now won't disable HDMI while a player or library scan is active - it will wait until both the player and library are inactive.
Does this confer any significant power savings on the RPi itself or is it only for the display, so that if I'm turning off the TV when not watching it, it's not worth doing?
Correct, not worth doing if you normally turn off the display. Its primary purpose is to save TV power consumption if you have a tendency to leave the display on while the Pi is not being used.

You could still use this script even if you normally turn off your display, as it will not do anything if it can detect when the display has been powered off, and will only kick in whenever you actually leave the display on. However not all displays will indicate if they are on or off, check if "tvservice --status" returns a different status when your display is on and then when powered off. If the status is the same then the script will not be able to detect when the display is off, and will always power off the HDMI (requiring an XBMC restart) even if you power off the display, in which case you'll have to decide if this script is useful for you or not (minor inconvenience and only a small power saving).

For those that leave their display on often, they should see a minor inconvenience (xbmc restart) but fairly significant power saving.
Pages: 1 2 3 4 5 6 7 8 9 10 11