LIRC - ArchWiki

# LIRC

Related articles

- LIRC Device Examples

This article covers setup and usage of LIRC "Linux Infrared Remote Control" with serial or USB infrared devices.

## Overview

LIRC is a daemon that can translate key presses on a supported remote into program specific commands. In this context, the term, "program specific" means that a key press can do different things depending on which program is running and taking commands from LIRC.

### The Central Dogma of LIRC

The list below attempts to show the flow of information from the remote to the application using LIRC:

- User hits a button on the remote causing it to transmit an IR or RF signal.
- The signal is received by the receiver connected to the Linux box.
- The kernel (via the correct module) uses `/dev/lirc0` to characterize the pulse-length information from the receiver.
- `/usr/bin/lircd` uses the information from `/etc/lirc/lircd.conf.d/foo.conf` to convert the pulse-lengths into button press information.
- Programs that use LIRC translate the button press info from `/usr/bin/lircd` into user-defined actions according to `~/.lircrc` or to program-specific mappings.

### Required Files

- `/etc/lirc/lircd.conf.d/foo.conf` - System-level config translating scancodes --> keys. This directory may contain multiple conf files and each one is specific to each remote control/receiver on the system.

Note: These are user-created config files not directly supplied by the main package.

### Optional Files

Depending on the application using LIRC, the following are optional. For example, mplayer and mythtv use the these files to define key maps and actions. Not every application will need these. kodi for example, uses its own xml files to achieve these mappings.

- `~/.lircrc` - File containing an include statement pointing to each program's lirc map, i.e., `~/.lirc/foo`, `~/.lirc/bar`, etc.
- `~/.lirc/foo` - User-level config translating of keys --> actions. Is specific to each remote and to application foo.

## Installation

Install the lirc package, which is available in the official repositories.

Note: Support for older remotes have been officially dropped upstream. Search the AUR for packages to build a module if using unsupported hardware.

## Setup

Some remotes are identified as keyboards and function as such without LIRC providing input as physical key presses. This is problematic and can result in a doubling of commands. Test if this is the case by opening a shell or a text editor, and by pressing buttons on the remote itself. If letters/numbers appear, or if the up/down/left/right arrow keys behave as the up/down/left/right arrow keys on the physical keyboard, a workaround to disable this is required. See, LIRC#Remote_functions_as_a_keyboard for a solution before continuing.

### The LIRC Config File

The definition of scancodes to keymaps is required to allow LIRC to manage a remote. Copy the corresponding conf file into `/etc/lirc/lircd.conf.d` to achieve this mapping.

Note: Common configs are provided by lirc, like those bundled with TV cards that can be installed automatically. The primary source of config files is the LIRC homepage. Check the official list of supported hardware to know, which kernel modules and lircd drivers are required.

#### Option 1. Upstream provided config files

Identify which remote/receiver is to be used and see if `/usr/share/lirc/configs` contains a pre-built config file for it. Once identified, copy the needed conf to `/etc/lirc/lircd.conf.d` to allow the daemon to initialize support for it.

#### Option 2. User created config files

Users with unsupported hardware will need to either find a config file someone else has created (i.e. google) or create one. Creating one is fairly straightforward using the included `/usr/bin/irrecord` program which guides users along the needed process. If using a detected remote, invoke it like so:

    irrecord --device=/dev/lirc0 MyRemote

The program will ask users to begin hitting keys on the remote in an attempt to learn it. If all goes well, the user will be prompted to map out each key press to a specific scancode LIRC uses to identify that specific key press. The process should take no more than 10 minutes. When finished, save the resulting file to `/etc/lirc/lircd.conf.d/foo.conf` and proceed.

Note: Consider sending the finished config file to the email address mentioned in the program so it can be made available to others.

## Testing the Remote

Start `lircd.service` and enable it to run at boot time/shutdown (highly recommended).

Test the remote using `/usr/bin/irw`, which simply echos anything received by LIRC when users push buttons on the remote to stdout.

Example:

    $ irw
    000000037ff07bfe 00 One mceusb
    000000037ff07bfd 00 Two mceusb
    000000037ff07bfd 01 Two mceusb
    000000037ff07bf2 00 Home mceusb
    000000037ff07bf2 01 Home mceusb

## Program Specific Configuration

LIRC has the ability to allow for different programs to use the same keypress and result in unique commands. In other words, mplayer and vlc can respond differently to a given key press.

Decide which programs are to use LIRC commands. Common programs include: mplayer, mythtv, totem, vlc, and kodi.

Note: Kodi implements LIRC in a non-standard way. Users must edit `~/.xbmc/userdata/Lircmap.xml` which is a unique xml file, rather than the LIRC standard files the rest of the programs use. Interested users should consult the Kodi#Using a remote controller article.

Users should create the expected files showing LIRC where the various program-specific maps reside:

    $ mkdir ~/.lirc
    $ touch ~/.lircrc

- Populate `~/.lirc` with the program specific config files named for each program.

Example:

    $ ls ~/.lirc
    mplayer
    mythtv
    vlc

Note: Providing an exhaustive listing of keymaps for each program is beyond the scope of this wiki article. Many pre-made files unique to each remote/program are available via googling.

- Edit `~/.lircrc` to contain an include statement pointing to `~/.lirc/foo` and repeat for each program that is to be controlled by LIRC.

Example:

    ~/.lircrc

    include "~/.lirc/mplayer"
    include "~/.lirc/mythtv"
    include "~/.lirc/vlc"

## Troubleshooting

### Remote functions as a keyboard

Xorg detects some remotes, such as the Streamzap USB PC Remote, as a Human Interface Device (HID) which means some or all of the keys will show up as key strokes as if entered from the physical keyboard. This behavior will present problems if LIRC is to be used to manage the device. To disable, create the following file and restart X:

    /etc/X11/xorg.conf.d/90-streamzap.conf

    Section "InputClass"
      Identifier "Ignore Streamzap IR"
      MatchProduct "Streamzap"
      MatchIsKeyboard "true"
      Option "Ignore" "true"
    EndSection

Don't forget to alter the `MatchProduct` property according to one shown in `Name` from output of

    $ cat /proc/bus/input/devices | grep -e IR

For example `WinFast` for `N: Name="cx88 IR (WinFast DTV2000 H rev."`

## See also

- MythTV Wiki:Remotes article
- Official list of supported hardware

Categories:

- Other hardware
- Audio/Video