CEC remote control

I have an Onkyo receiver the tx sr 333 and I want to use its remote to control Rasplex through CEC.
I followed the guide online about the keymap.xml but rasplex doesn’t respond to the remote.
(I’ve tried multiple variants of the xml file)
However, when I use the command cec-client through ssh I see the buttons I press on the remote coming by.
What am I missing here?

So because I couldn’t find a direct solution. I made this workaround:

I created the following simple python script:

#!/usr/bin/python
import sys
import re
import os

host = "127.0.0.1"
port = "9777"
key_map = {
    "exit":"back",
    "F4 (yellow)":"NextSubtitle",
    "F1 (blue)":"AudioNextLanguage",
    "forward":"NextScene",
    "backward":"PreviousScene",
    "Fast forward":"StepForward",
    "rewind":"StepBack",
    "contents menu":"ContextMenu",
}

def send_action(key):
    action = key_map[key] if key in key_map else key
    cmd_str = 'xbmc-send --host=' + host + ' --port=' + port + ' --action="' + action + '"'
    os.system(cmd_str)

while 1:
    line = sys.stdin.readline()
    searchObj = re.search( r'^.*key pressed\:\s(.*)\s\(.*,\s0\)$', line, re.M|re.I)
    if searchObj:
        key = searchObj.group(1)
        sys.stdout.write("Sending " + searchObj.group(1))
        sys.stdout.write("\n")
        send_action(key)

and saved it to /storage/.config/remote.py

Then I created an autostart.sh file:

#!/usr/bin/bash
cec-client | python /storage/.config/remote.py &

and saved that to /storage/.config/autostart.sh

The key_map variable depends on your remote and can be determined by reading the output of cec-client in a ssh session.

It uses: key:action
where the actions can be found at: https://kodi.wiki/index.php?title=Action_IDs
It seems that capitalization does not matter for the actions.

Now restart your raspberrypi and you should be good to go.

Hope this helps someone!

Actually created a better version of the script using jsonrpc, resulting in faster responses.

#!/usr/bin/python
import sys
import re
import os
import urllib2

host = "127.0.0.1"
port = "3005"
key_map = {
    "exit":"Input.Back",
    "F4 (yellow)":"NextSubtitle",
    "F1 (blue)":"AudioNextLanguage",
    "forward":"Player.Seek",
    "backward":"Player.Seek",
    "Fast forward":"Player.Seek",
    "rewind":"Player.Seek",
    "contents menu":"Input.ContextMenu",
    "play":"Player.PlayPause",
    "pause":"Player.PlayPause",
}

params_map = {
    "Fast forward":'"value":"smallforward", "playerid":1',
    "rewind":'"value":"smallbackward", "playerid":1',
    "play":'"playerid":1',
    "pause":'"playerid":1',
    "forward":'"value":100, "playerid":1',
    "backward":'"value":0, "playerid":1',
}

def send_action(key):
    action = key_map[key] if key in key_map else "Input." + key
    params = ',"params":{{ {0} }}'.format(params_map[key]) if key in params_map else ""
    url_str = 'http://{0}:{1}/jsonrpc?request={{"jsonrpc":"2.0","id":1,"method":"{2}" {3} }}'.format(host,port,action,params)
    result = urllib2.urlopen(url_str).read()
    print(result)

print "starting"
while 1:
    line = sys.stdin.readline()
    #sys.stdout.write(line)
    searchObj = re.search( r'^.*key pressed\:\s(.*)\s\(.*,\s0\)$', line, re.M|re.I)
    if searchObj:
        key = searchObj.group(1)
        sys.stdout.write("Sending " + searchObj.group(1))
        sys.stdout.write("\n")
        send_action(key)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.