Skip to content

Remote control input in the odio API

The input backend lets a physical remote drive the node directly, with no client involved. It reads Linux input devices (/dev/input/event*) through evdev and turns key presses into actions on the other backends: play/pause, next, volume, mute, power off, restart a service.

Since v0.18.0. Disabled by default; the odio installer enables it on headless nodes. For a step-by-step setup, see Remote controls.

Which devices are handled is decided from sysfs, before any device is opened:

KindDevicesHandled
irInfrared receivers, kernel rc devices: gpio-ir, MCE USB receiversAutomatically
cecHDMI-CEC adapters, such as vc4-hdmi on a Raspberry PiOnly with input.cec: true
gpiogpio-keys and gpio-keys-polled buttonsAutomatically
forcedAnything else, typically a Bluetooth or USB remoteOnly when named in input.devices

Nothing else is ever opened: keyboards, mice and touchscreens are left alone unless you list them.

Handled devices are grabbed. Their keys reach odio only, no longer the console, the desktop or another application such as Kodi. The grab covers the whole device, so a keyboard with a built-in touchpad loses its pointer too.

Hotplug is handled by watching /dev/input: a remote plugged in later, or a Bluetooth remote that sleeps and reconnects, is picked up without a restart.

GET /input

Returns the handled devices and the effective bindings, defaults and overrides merged:

{
"devices": [
{ "path": "/dev/input/event0", "name": "vc4-hdmi", "kind": "cec", "state": "active" },
{ "path": "/dev/input/event2", "name": "Logitech K400", "kind": "forced", "state": "active" }
],
"bindings": [
{ "key": "KEY_MUTE", "action": "volume.mute" },
{ "key": "KEY_NEXTSONG", "action": "player.next" },
{ "key": "KEY_PLAYPAUSE", "action": "player.playpause" },
{ "key": "KEY_RED", "action": "service.restart", "unit": "kodi.service" }
]
}
stateMeaning
openingThe device was just detected and is being opened
activeKeys are being read
deniedThe device is not readable, see System setup

A device that is unplugged leaves the list.

Media keys work without any configuration:

KeyAction
KEY_PLAYPAUSEplayer.playpause
KEY_PLAYplayer.play
KEY_PAUSEplayer.pause
KEY_STOPCDplayer.stop
KEY_NEXTSONGplayer.next
KEY_PREVIOUSSONGplayer.previous
KEY_FASTFORWARDplayer.forward
KEY_REWINDplayer.rewind
KEY_VOLUMEUPvolume.up
KEY_VOLUMEDOWNvolume.down
KEY_MUTEvolume.mute

input.bindings overrides or extends these. Key names are the kernel’s, as shown by evtest.

ActionEffectBackend to enable
player.playpause, player.play, player.pause, player.stop, player.next, player.previousControls the active playerMPRIS
player.forward, player.rewindSeeks 10 s in the active playerMPRIS
volume.up, volume.downMoves the default output by pulseaudio.volumeStepPulseAudio
volume.muteToggles mute on the default outputPulseAudio
power.poweroff, power.rebootPowers off or reboots the nodePower
service.start, service.stop, service.restartActs on the user unit given as unit, which must be listed in systemd.userSystemd
bluetooth.powerup, bluetooth.powerdownPowers the Bluetooth adapter on or offBluetooth
bluetooth.pairingOpens pairing mode, powering the adapter on if neededBluetooth
noneUnmaps the key, typically a default

An action only works when its backend is enabled: bluetooth.pairing needs bluetooth.enabled: true, power.poweroff needs power.enabled: true, and so on.

Holding a key repeats volume.up, volume.down, player.forward and player.rewind. Every other action fires once per press.

A binding that cannot work is skipped with a warning in the log, without failing startup: an unknown key name, an unknown action, or an action whose backend is disabled. An entry with no key or no action is a configuration error and stops the API from starting.

EventTrigger
input.keyA bound key was pressed or released
input.updatedA device was added, removed, or changed state

input.key carries the device name, the key and the action it is bound to:

{ "device": "Logitech K400", "key": "KEY_PLAYPAUSE", "code": 164, "state": "pressed", "action": "player.playpause" }

state is pressed or released. Auto-repeat of a held key is not published.

Only keys with a binding are published. Keys without one are dropped, so a handled keyboard never sends what is typed to the event stream.

input.updated carries the device list, in the same form as devices in GET /input.

input:
enabled: true
cec: true # also handle HDMI-CEC adapters (TV remote)
devices: # Bluetooth / USB remotes, by device name
- "flirc.tv flirc"
bindings: # override or extend the default media keys
- { key: KEY_POWER, action: power.poweroff }
- { key: KEY_RED, action: service.restart, unit: kodi.service }
- { key: KEY_MUTE, action: none } # unmap a default
KeyDefaultNotes
enabledfalseInfrared and GPIO devices are handled as soon as the backend is enabled.
cecfalseAlso handles HDMI-CEC adapters. A Raspberry Pi has one per HDMI port, present whether a TV is plugged in or not, which is why it is a separate switch. The odio installer turns it on.
devicesnoneNames of the other devices to handle, as listed in /proc/bus/input/devices. The whole name must match, case aside.
bindingsnoneEntries with a key, an action, and a unit for service.* actions.

In a drop-in, bindings replaces the list from config.yaml, it is not appended to it.

The step of volume.up and volume.down is set on the PulseAudio backend, with pulseaudio.volumeStep (default 0.05, from 0.01 to 1).

With logLevel: debug, each key pressed on a handled device that has no binding is named in the log:

[input] unmapped KEY_Q (Logitech K400)

evtest shows the same names, but only while odio-api is stopped, since a grabbed device sends nothing to other readers.

odio-api doesn’t run as root, so the user running it must belong to the input group to read /dev/input/event*. The odio installer handles this automatically. For standalone installations:

Terminal window
sudo usermod -aG input <username>

Then reboot. The group only applies to a new user session, restarting odio-api is not enough. Until then, devices are listed as denied and a warning is logged.

An infrared receiver also needs its kernel keymap loaded for the remote in use, see ir-keytable. On a Raspberry Pi with an I2S DAC, it must also be wired to a pin other than GPIO 18. Buttons wired to the header need the gpio-key overlay, see push buttons.

The input group lets any process of that user read every input device, keyboards included. odio-api itself only opens infrared receivers, gpio-keys devices, HDMI-CEC adapters when input.cec is set, and the devices named in input.devices.

Listing a keyboard in input.devices is safe for the event stream, since unbound keys are never published. At logLevel: debug they are named in the log, so keep that level for setup only.