Configuring a HDMI-CEC remote in Kodi

I’ve been using Raspbmc for a while now, but I only just saw that it has been superseded by OSMC (and XBMC is now called Kodi, so with the long weekend I thought I’d upgrade.

The upgrade process is really simple. I backed up my existing installtion of Raspbmc, downloaded the offical OSMC installer from their site, installed it over the top and booted it up.

From here, there are only a few things to do. I entered my MPG2 and WVC1 codecs, setup my video sources and kicked off the scrapers and installed a few addons. The only other thing is setting up my TV remote. (I did this last time but forgot how, so this time I thought I’d blog it!)

Out of the box, my Samsung “Smart Touch” Remote (this one if you’re wondering) mostly just works, the only problem is the back button opens the context menu instead of going back!

To fix this, the first step is to find out what each button on the remote maps to in Kodi. Thanks to this great forum post by a user called “Knapster” this is really easy.

Just SSH to the pi, create a new file ~/.kodi/userdata/keymaps/remote.xml and paste this contents in it. Now reboot Kodi and everytime you press a button, you’ll get a notification on the screen of what command it is sending.

A quick way of doing that from an SSH session is like this:
(The default username and password are both osmc)

ssh osmc@<kodi-ip-address>
curl > ~/.kodi/userdata/keymaps/remote.xml
sudo reboot

In my case, everything seemed to make sense except the back button, which was actually sending title instead of back. As I don’t have a title button, I’m going to reassign that to be a back button instead.

First, lets replace our remote.xml with the default configuration, you can get these mappings from the installed Kodi files:

cp /usr/share/kodi/system/keymaps/remote.xml ~/.kodi/userdata/keymaps/remote.xml

This file has what every command does in every context and makes it easy to modify. Here is a diff of the changes I made for my remote:

<       <title>ContextMenu</title>
>       <title>Back</title>
<       <guide>ActivateWindow(TVGuide)</guide>
>       <guide>ActivateWindow(Home)</guide>
<       <red>ActivateWindow(TVChannels)</red>
>       <red>ContextMenu</red>

I’ve made the “title” button send the back command and because I don’t have a TV tuner connected, I’ve also re-assigned the “TV Guide” button to go to the home screen and the “Red” button to be the context menu button.
Interestingly, the channel up and down buttons on my remote we already assigned to page up and page down, which suits me great while I don’t have a TV Tuner.

After rebooting, I now have a functional remote control!