FLIRC for IR remotes
Product website: https://flirc.tv/products/flirc-usb-receiver They also sell a programmable remote (the Skip 1s), but any IR remote will work.
What it is
This allows you to do anything you want on the Raspberry Pi when pressing buttons on an IR (infrared) remote. This page explains how to make your own custom script.
The FLIRC is a USB dongle that can receive the IR signal from any IR remote. Towards the Raspberry Pi the USB dongle looks like a keyboard and generic HID (human interface device).
Installing software
The instructions from https://flirc.com/ubuntu-software-installation-guide work on Raspberry Pi OS Lite (based on Debian version 12/bookworm). This will get you the flirc_util command:
curl apt.flirc.tv/install.sh | sudo bash
At least as of April 2025, the instructions on https://flirc.gitbooks.io/flirc-instructions/content/installation/linux-installation-guide.html do not work. It adds a Debian package repository that is not accepted. You can remove the line from /etc/apt/sources.list to fix it and then follow the instructions above.
Alternative: You can also use the Windows or MacOS software from the product website instead to program the mapping of remote buttons.
Mapping remote buttons
The flirc_util command must be used to map a button press on your remote to some keyboard key. It can be used as follows.
# Forget all learned remote buttons
flirc_util format
# List all supported key names
flirc_util record
# Examples to record remote buttons. After each command you need
# to press the desired button on the remote.
flirc_util record vol_up
flirc_util record vol_down
flirc_util record mute
flirc_util record 0
flirc_util record 1
If you make your own script (like the example below), then it doesn't actually matter what keyboard key you map each button to as long as you use the same key in the script. But just for your own sanity it might be good to use logical key names such as vol_up for a “volume up” button on your remote.
Example Python script
This is an example script to get you started:
#!/usr/bin/python
import evdev
# If this isn't the device name for you, check what devices exist
# in directory /dev/input/by-id/ and replace the device name below.
flirc=evdev.InputDevice(dev='/dev/input/by-id/usb-flirc.tv_flirc-if01-event-kbd')
flirc.grab()
def main():
for event in flirc.read_loop():
if event.type == evdev.ecodes.EV_KEY:
attrib = evdev.categorize(event)
# attrib.keystate values: 0=button up (not pressed), 1=down (pressed), 2=hold
###########################################################################
# Remote button is pressed once
###########################################################################
if (attrib.keystate == 1):
print("Keycode value for pressed button: " + str(attrib.keycode))
if attrib.keycode == 'KEY_VOLUMEUP':
# Mapped on Linux command line with: flirc_util record vol_up
print("Pressed: volume up")
elif attrib.keycode == 'KEY_VOLUMEDOWN':
# Mapped on Linux command line with: flirc_util record vol_down
print("Pressed: volume down")
elif attrib.keycode == ['KEY_MIN_INTERESTING', 'KEY_MUTE']:
# Mapped on Linux command line with: flirc_util record mute
print("Pressed: mute")
elif attrib.keycode == 'KEY_0':
# Mapped on Linux command line with: flirc_util record 0
print("Pressed: 0")
elif attrib.keycode == 'KEY_1':
# Mapped on Linux command line with: flirc_util record 1
print("Pressed: 1")
###########################################################################
# Remote button is held down
###########################################################################
if attrib.keystate == 2:
if attrib.keycode == 'KEY_VOLUMEUP':
print("Holding down: volume up")
elif attrib.keycode == 'KEY_VOLUMEDOWN':
print("Holding down: volume down")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
Save this script as e.g. my_flirc_handler.py. Then you can make it executable and run it:
chmod +x my_flirc_handler.py
./my_flirc_handler.py
The key names you mapped the remote buttons to with flirc_util are not exactly the keycode value for this Python library (evdev), although most are pretty close. The easy way to learn the keycode is with the line in this example script: show the value of attrib.keycode. After running the script, press a button on the remote and the keycode value will be shown.
Creating a service
Once you've completed your script to handle the FLIRC remote, you likely want to let it always run in background as a service. If you use Raspberry Pi OS, then you add it as a service for systemd. See the section about systemd to learn how to do that.
Alternatives
- Wireless Remote Control from HiFiBerry. It's a package with a USB dongle and remote. The communication is not with infrared, but radio transmission. (An advantage is that you don't need to point the remote to the Pi. An advantage of a programmable IR remote is that it can replace other IR remotes.) The USB dongle acts as USB keyboard for Linux, just like the FLIRC.
- Connect an IR receiver diode directly to the GPIO pins of the Pi. Example instructions: https://www.instructables.com/Add-Infrared-Interface-to-Your-Raspberry-Pi/