Last Updated on 2015-02-23.
You are running multiple OpenELEC systems with mixed hardware (PCs like Zotac Zbox, ARM devices like Raspberry Pi) and different HDMI displays (TV or PC monitors).
You maybe run a server where you use advancedsettings.xml to substitute paths to, like for userdata or remote.xml, if you use the same USB remote control for every device.
The files on the clients are quite the same everywhere, so for additional devices you only have to copy an image.
Main problems with controlling monitors and suspend
You need the USB remote to stay always active to catch “Power On” signals. This works for common PCs which are sent to sleep instead of full shutdown, but the Raspberry Pi does not have a suspend feature. According to some forum threads, there is a “virtual suspend” being worked on, but not yet finished.
Another problem appears if some monitors are CEC capable and some are not. E.g. most current TVs support CEC, but no common PC monitor. For the latter, it would be enough to just switch off the HDMI port, most displays go into sleep mode then.
One solution could be creating individual remote.xml files for every system, but imho this is not a clean way.
I created a script which you can download below. You might have to fit it according to your environment. I use it for the following combinations:
- various Zotac ZBox IDxx (standby compatible; no CEC but using Pulse-Eight HDMI adapter)
- various Raspberry Pi Model B, B+ and 2 (integrated CEC; no standby mode)
- various TVs like Philips, Grundig (all CEC compatible)
- various PC monitors like Benq 27″ (no CEC)
This happens in the script when you turn OpenELEC / Kodi on or off:
- CEC TV with RPi: TV is switched off, RPi keeps running with Kodi closed
- PC monitor with RPi: HDMI port is switched off, display goes into sleep mode, RPI keeps running with Kodi closed
- CEC TV with PC: TV is switched off, PC goes into standby
- PC monitor with PC: Monitor goes into sleep mode (missing HDMI signal because of PC sleep)
- Download the script: onOffHelper
- Extract and save it to /storage/.kodi/userdata/onOffHelper.sh. Alternatively copy it to \\[yourOESystem]}UserData or distribute it like in this tutorial.
- Edit your remote.xml, located under /storage/.kodi/userdata/keymaps. If you do not have this file or want to use the addon Keymap Editor, start it and delete the mapping of the Power key. You can also copy the whole original file from /usr/share/kodi/system/keymaps/remote.xml to /storage/.kodi/userdata/keymaps. Anyway, in any case the <power> tag should not contain anything:
- Create file /storage/.kodi/userdata/.lircrc and add:
begin prog = irexec button = KEY_POWER config = /storage/.kodi/userdata/onOffHelper.sh & end
#From OE6 onwards some remote power commands are captured by button name "sleep", so we need the same paragraph again: begin prog = irexec button = KEY_SLEEP config = /storage/.kodi/userdata/onOffHelper.sh & end
User command “irw” to get your KEY_XX power button name if it does not work.
- Create or edit /storage/.config/autostart.sh and add:
/usr/bin/irexec -d /storage/.kodi/userdata/.lircrc
- Give the main scripts execution permissions:
chmod +x /storage/.kodi/userdata/onOffHelper.sh chmod +x /storage/.config/autostart.sh
- Reboot and you should be done
- Test it, e.g. press power button of your remote or run the script manually
- You might want to check logs in /storage/.kodi/temp/onOffHelper.log
Note: The locations I used might not be the best ones, but in most cases they seem to be the most comfortable to use for deploying.
Recommended GUI settings
If the monitor of the station is not CEC compatible, disable the CEC device (if available) under Kodi GUI -> Settings -> System -> Input Devices. So the script gets the information whether it should use CEC or only power off HDMI (e.g. on Raspberry Pi).
If your TV is CEC compatible, make sure you set the appropriate settings for your devices (setting “enabled” and your required actions what should be done on startup and standby/shutdown).
Default shutdown setting in GUI should be “Suspend”. If the setting is not available, you can try this.
In OE System settings, make sure you have set “default shutdown action” not to shutdown, but e.g. to suspend or completely off.
When editing .lircrc, you might also want to add a button for reboot, so can restart your system even if Kodi is hanging:
begin prog = irexec button = KEY_BLUE config = /usr/sbin/reboot & end
As soon as devices like Raspberry Pi get an official “virtual suspend” feature in OpenELEC or Kodi, please remove this script 🙂
For testing purposes
If you encounter problems using the script, have a look at the code snippets below, maybe they are useful for your environment:
#note for cec-client: not always available, e.g. with pulse8 device is busy when kodi opened #echo "standby 0" | cec-client -s -o XBMC #0 = tv, 5 = audio #echo "standby 5" | cec-client -s -o XBMC #echo "on 5" | cec-client -s #echo "on 0" | cec-client -s #systemctl suspend #echo "as" | cec-client -s #optional; sets this device as current hdmi source
Update 2015-11-25: Added command “tvservice -p” to onOffHelper.sh script. This seems to be needed from OpenELEC v6 upwards on RPi. Also the script now supports custom autostart and shutdown files or commands.
Update 2016-02-29: Added additional “standby 0” CEC command to onOffHelper.sh script. The default Kodi shutdown call seems to not always work with all CEC compatible TVs. E.g. for Grundig TVs, this bugfix might help you.[:]