Vero 4k Remote.xml - Switch TV on/off using CEC

Hey

I created a keymap and a couple of python scripts which you can use to switch your CEC capable tv on or off.

So long press home = off
Home = On

Long press i = home
i - info

return = return

Playing a video - long press playlist = playlist
playlist = codecinformation

So the kemap xml file is a follows:

<keymap>
<global>
<keyboard>
<key id="61576">runscript(/home/osmc/scripts/home.cec.on.py)</key>
<key id="61576" mod="longpress">runscript(/home/osmc/scripts/home.cec.off.py)</key>
<key id="61448">Back</key>
<key id="61513" mod="longpress">activatewindow(home,return)</key>
<key id="61507">ContextMenu</key>
</keyboard>
</global>
<fullscreenvideo>
<keyboard>
<key id="61507">CodecInfo</key>
<key id="61507" mod="longpress">Playlist</key>
</keyboard>
</fullscreenvideo>
</keymap>

With the off script:

/home/osmc/scripts/home.cec.off.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
bashCommand = 'kodi-send --action="Notification(Powering Off TV,OFF,500)"'
output = subprocess.check_output(['bash','-c', bashCommand])
bashCommand = '/bin/echo "standby 0" | /usr/osmc/bin/cec-client -s'
output = subprocess.check_output(['bash','-c', bashCommand])
bashCommand = 'kodi-send --action="PlayerControl(stop)"'
output = subprocess.check_output(['bash','-c', bashCommand])

And the on script:

/home/osmc/scripts/home.cec.on.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
bashCommand = 'kodi-send --action="CECActivateSource"'
output = subprocess.check_output(['bash','-c', bashCommand])

I found this stuff on the forums, im not good with python so this is just the first way I could get it to work.
If anyone has any suggestions to improve the python scripts, make them run faster, im all ears.

3 Likes