Tim's blah blah blah

Infrared remote control hell with an Intel NUC, Logitech Harmony, lirc, ir-keymap and Kodi

(Updated: )

So I got a new (second hand) Harmony Remote and would like to control my AV setup with this. I document my findings in the jungle of IR control on Linux here.

  1. Old situation: Kodi (on Intel NUC/Ubuntu 18.04) controlled via LIRC using Apple TV remote
  2. Desired situation: Samsung TV + Pioneer AV receiver + Kodi on NUC controlled with Logitech Harmony and Kodi also with the Apple TV remote. What’s working:


I’d like to control the following devices, using two remotes:

Setting scenes with Harmony

The easiest part is to turn all devices on using the Logitech Harmony, based on these Kodi threads: Win - HOW TO - Configure a Logitech Harmony Remote for Kodi (kodi.tv) Solved - Intel NUC htpc setup, IR, harmony remote - esp. ‘Problem 6’ (kodi.tv)

  1. Add new activity (e.g. Watch TV)
  2. Add devices you want to control (see above in my case)
  3. Add extra devices to send to Kodi later on: Windows Media Center SE & Microsoft Media Player
  4. Following the configuration menu to turn on the relevant devices
  5. Later: customize buttons for Watch TV activity and use the Windows MCE and WMP keys to send commands

Controlling Kodi

The next step is to control Kodi menus using both the Harmony remote as well as the Apple TV remote.

Infrared architecture

So I’m not exactly sure how infrared commands get processed, but this is how far I got based on these sources:

In words:

  1. The remotes generate infrared commands with some encoding (e.g. NEC for Apple TV remote, RC-6 and MCE_KBD for the Harmony as configured)
  2. The IR commands are received by two devices (/dev/input/event7 and /dev/input/event15) – why two? I don’t know
  3. Afterwards (or instead of), these commands are parsed according to ir-keytable or lirc configuration
  4. With ir-keytable, these commands are immediately available for Kodi and are activated according to e.g. keyboard.xml or remote.xml (why are there multiple files? I don’t know)
  5. With LIRC an additional step is needed to map LIRC commands to Kodi commands, via Lircmap.xml (note the capital L) As said, this is a sketch, and some parts are probably wrong or missing. Does anyone have a better picture?

Diagnose and debug

Because stuff goes wrong, start the diagnostics:

Debug infrared using evtest:

sudo evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event7:	Nuvoton w836x7hg Infrared Remote Transceiver
/dev/input/event15:	MCE IR Keyboard/Mouse (nuvoton-cir)    

Then choose event 7 or 15 to listen/debug. This allows you to diagnose IR commands received by ir-keytable via either of the two event inputs.

Detect infrared using ir-keytable, an alternative detection mechanism, use -p all to enable all protocols:

sudo ir-keytable -p all
Found /sys/class/rc/rc0/ (/dev/input/event7) with:
	Driver nuvoton-cir, table rc-rc6-mce
	Supported protocols: other lirc rc-5 jvc sony nec sanyo mce-kbd rc-6 sharp xmp 
	Enabled protocols: lirc nec rc-6 
	Name: Nuvoton w836x7hg Infrared Remote
	bus: 25, vendor/product: 1050:00c3, version: 0x0033
	Repeat delay = 500 ms, repeat period = 125 ms    

Enable debug logging in Kodi, this allows you to diagnose the end point and see which commands Kodi receives: Kodi -> options -> system -> logging -> debug

tail -f ~/.kodi/temp/kodi.log

Disable LIRC

We don’t need LIRC and it might even interfere with our configuration (because it might capture the IR commands). Disable it or remove it:

sudo systemctl disable lircd.service
sudo systemctl disable lircd.socket
sudo systemctl disable lircd
sudo systemctl disable lirc
# The above commands were not sufficient for me, this is more permanent and worked:
sudo apt remove lirc

Map AppleTV commands


sudo ir-keytable -v -t -p all

to check Apple TV remote commands, then store this as a rc_keymap. You can use one of the existing keymaps in /lib/udev/rc_keymaps. My /etc/rc_keymaps/apple_tv_A1294 looks as follows:

# table apple_tv_A1294, type: NEC
0x87ee660b KEY_UP
0x87ee660d KEY_DOWN
0x87ee6608 KEY_LEFT
0x87ee6607 KEY_RIGHT
0x87ee665d KEY_ENTER
0x87ee6602 KEY_DELETE # This is the menu button but KEY_MENU is not recognised by Kodi?
0x87ee665e KEY_PLAY

For each remote, make this keymap and store it in e.g. /etc/rc_keymaps. Then add these to /etc/rc_maps.cfg to auto-load, e.g.:

nuvoton-cir	rc-rc6-mce	/etc/rc_keymaps/apple_tv_A1294
nuvoton-cir	rc-rc6-mce	/etc/rc_keymaps/rc6_mce    

To make this stick after reboot, you need to manually start it (is there a better way?), I added these commands to /etc/rc.local (askubuntu.com):

ir-keytable -p all -w /etc/rc_keymaps/rc6_mce
ir-keytable -p all -w /etc/rc_keymaps/apple_tv_A1294    

Configure Harmony remote

Follow guide on the Kodi forum (kodi.tv), choose buttons to your liking.

Be sure to set Input Repeat and Input Delay to lower values for the MCE and Keyboard devices in MyHarmony (under ‘Change Device settings’), else the remote experience can be a bit laggy.

Configure Kodi to behave

Now that our IR commands are received by the hardware, drivers, and then converted to commands, it’s time to have Kodi receive.

Most commands work out of the box (following the default Kodi keymap). There are two tweaks to make:

1. Fix AppleTV menu button works. We use KEY_DELETE and give it the same command as KEY_BACKSPACE, which is ‘Back’.
2. Enable shutdown from Harmony remote

Fix Apple TV menu button

Add <delete>Back</delete> to relevant places in /usr/share/kodi/system/keymaps/keyboard.xml (e.g. everywhere the backspace key appears, I only added it to <global>). Delete all other <delete> entries. Diff:

>       <delete>Back</delete>
>       <escape mod="ctrl">Powerdown</escape>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>
<       <delete>Delete</delete>

Enable shutdown from Harmony remote

  1. Using MyHarmony, add custom command for shutdown, e.g. Ctrl-ESC
  2. For Kodi, add new command to shutdown on this trigger to keyboard.xml, namely > <escape mod="ctrl">Powerdown</escape> (see above as well)

Sources & rererences

Other guides on getting IR to work for Kodi:

#HTPC #Linux