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

By Atomstar on Monday 11 November 2019 09:00 - Comments (3)
Categories: HTPC, Linux, Views: 1.676

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:
  • Harmony remote controls all devices
  • AppleTV and Harmony can both navigate Kodi
  • Harmony shuts down Kodi and NUC
What's not working:
  • Kodi doesn't detect all keys from Apple TV remote (e.g. KEY_OK / KEY_MENU / KEY_BACKSPACE). Workaround: use KEY_DELETE and remap in Kodi's keyboard.xml
What's unclear:
  • Why does evtest show two IR event inputs?
  • Why does Kodi have multiple keymaps?

Ingredients

I'd like to control the following devices, using two remotes:
  • Receiver: Pioneer VSX-S510
  • TV: Samsung UE32D5000
  • HTPC: Intel NUC5i3RYH
  • Old remote: A1294 AppleTV
  • New remote: Logitech Harmony 650

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
Solved - Intel NUC htpc setup, IR, harmony remote - esp. 'Problem 6'
  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:NUC Infrared Kodi Lirc architecture

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
Use
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:
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, 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:

48a49,50
>       <delete>Back</delete>
>       <escape mod="ctrl">Powerdown</escape>
206d207
<       <delete>Delete</delete>
215d215
<       <delete>Delete</delete>
226d225
<       <delete>Delete</delete>
237d235
<       <delete>Delete</delete>
260d257
<       <delete>Delete</delete>
269d265
<       <delete>Delete</delete>
279d274
<       <delete>Delete</delete>
289d283
<       <delete>Delete</delete>
310d303
<       <delete>Delete</delete>
320d312
<       <delete>Delete</delete>
330d321
<       <delete>Delete</delete>
589d579
<       <delete>Delete</delete>
594d583
<       <delete>Delete</delete>
603d591
<       <delete>Delete</delete>
611d598
<       <delete>Delete</delete>
775d761
<       <delete>Delete</delete>


Enable shutdown from Harmony remote
[ol]
• Using MyHarmony, add custom command for shutdown, e.g. Ctrl-ESC
• 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:

Volgende: Flash problems to ESP8266 boards 21-11 Flash problems to ESP8266 boards
Volgende: Automated full-disk backup on Linux/Ubuntu 04-10 Automated full-disk backup on Linux/Ubuntu

Comments


By Tweakers user vanaalten, Monday 11 November 2019 09:19

Hmmm, I can confirm that IR on Linux is total HELL. I've a small Intel NUC with Debian Linux, Kodi and a Logitech Harmony for some time now; twice I upgraded the OS whenever a new 'stable' Debian release came out - and each time IR broke down and I spend time getting it fixed (and never completely understanding how it works).

Looking at the current situation, I've got it working using LIRC and 'mceusb.lircd.conf' as config.

Content of my /etc/lircd/lirc_options.conf:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[lircd]
nodaemon        = False
driver          = default
device          = auto
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/x86_64-linux-gnu/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600
logfile        = /var/log/lirc.log
loglevel       = debug

[lircmd]
uinput          = False
nodaemon        = False


...just in case it helps anyone.

By Jasper, Monday 11 November 2019 10:01

Just use this one;

https://flirc.tv/more/flirc-usb

Been using it for years now, with Kodi and Harmony. No problems setting up, when updating or usage in general.

By Tweakers user The Zep Man, Tuesday 12 November 2019 18:06

Can confirm. FLIRC USB is the way to go, and avoids maintenance hell. Aside of standard keyboard keys, it also supports the first 256 commands of the USB HID Consumer Usage Page, which contains most common media buttons ('play', 'stop', 'fast forward', 'select', 'menu back', etc.). These are natively supported by Kodi. Using media buttons, you really can make something that does not require any maintenance whatsoever after initial configuration.

That is if you want to fully customize it. It has an embedded Kodi profile that most likely suits your situation perfectly. With a FLIRC USB you will probably be up and running in less than 15 minutes, which includes the time needed to load the relevant profile into your Logitech Harmony. Bonus points for that the FLIRC USB is usable with Kodi (and anything else) on any device that has USB keyboard support.

[Comment edited on Tuesday 12 November 2019 18:17]


Comment form
(required)
(required, but will not be displayed)
(optional)