Control a Mopidy server through an IR receiver.
It's made of two simple components:
- A systemd oneshot unit to configure the infrared cell of the running host.
- A systemd unit to listen to kernel input events and translate them to Mopidy commands.
The first components is based on a trivial Bash script. It uses
ir-keytable thus nothing special is required with recent
kernels.
The event translator and consumer is written in Python3 using
python-evdev and aiohttp.
Start by fetching this repository:
$ git clone https://github.com/orontee/mopidyir.git
Then install dependencies at system level:
$ sudo apt install -y git ir-keytable python3-evdev python3-aiohttp
Make sure there's a fix path to the IR receiver device: Eg using an udev rule:
$ echo 'KERNELS=="input[0-9]*", SUBSYSTEMS=="input", ATTRS{name}=="gpio_ir_recv", SYMLINK+="input/ir-recv", ENV{SYSTEMD_WANTS}+="setup-ir.service"' | sudo tee /etc/udev/rules.d/99-gpio_ir_recv.rules
$ sudo udevadm control --reload
$ sudo udevadm trigger
A remote control keymap must be configured for IR scancodes to be converted to Linux keycode. This keymap depends on the remote control that will be used.
This configuration must be done in the setup-ir.sh
script where the KEYMAP_PATH value is expected to match the path to
a remote control keymap describing the remote control that will be
used.
System keymaps, usually under /lib/udev/rc_keymaps, can be used.
One can also build a custom keymaps (read rc_keymap manual page
for details on the expected format); Eg using ir-keytable --test to
identify scancodes. It then must be saved in the rc_keymaps/
</rc_keymaps> directory to be copied to /etc/rc_keymaps during
installation.
💡 The default value of KEYMAP_PATH match the remote control of a
s.m.s.l A8 amplifier; The keymap file
can be found in rc_keymaps/smsl_a8.toml.
The file mopidyir.yaml contains:
The configuration of the Mopidy server (currently, only the URL can be configured)
The path of the IR receiver device to listen events from
The mapping from Linux keycodes to Mopidy actions.
Actions are identified by names:
next_track,previous_track,scan_forward,scan_backward,pause_or_resume,play_favorite_stream,play_random_album,mute_unmute,volume_up,`volume_down.
The default configuration and action names should be self explanatory…
Finally run:
$ pushd mopidyir mopidyir$ sudo make install
and check:
mopidyir$ sudo systemctl status setup-ir.service
Makefile targets are defined to install single components; See make
help for details.
One must first stop the service (if installed):
mopidyir$ sudo systemctl stop ir-event-listening
Then simply:
mopidyir$ sudo ./mopidyir --debug --config mopidyir.yaml
For a list of supported command line arguments and defaults:
mopidyir$ ./mopidyir --help