Skip to main content

Add IR remote control using Flirc USB

Introduction

Many of you will have an infrared (IR) remote to control the volume, mute, and separate software on a phone, tablet or computer to play, pause, skip next and skip back. This topic shows you how you can set up the software playback controls for the IR remote and only use the remote to control playback.

 

Prerequisites

  1. Flirc USB receiver to plug into USB port.  This can be purchased from your local shop or from Amazon.
  2. Music player which can accept keyboard commands or shortcuts. Almost all SnakeOil players have this capability.
  3. Your IR remote control uses the NEC protocol, which is the common protocol for non-European equipment.  If the remote protocol is Phillips (RC5, RC6), mostly for European equipment, then you will need a learning IR remote (see end of article).
  4. A willingness to use commands. While Flirc USB has a GUI, you will be using the advanced features found only in the CLI.

 

How does it work

Flirc USB is seen by the computer as a keyboard.  When you press the IR remote, Flirc USB will replay the recorded keyboard strokes.

 

How to set up

There are 2 parts to the set up.  Firstly, identify the keyboard commands that can be used to control the music playback. Then record the keyboard strokes on the Flirc USB for use with the IR remote. 

While this article discusses LMS extensively, the approach can equally apply to other music players, discussed later.

Identify LMS commands 

LMS has a command line interface, with individual commands to control everything. LMS requires the unique ID of the Squeezelite player to control playback. Use this command to get the ID:

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["00:00:00:00:00:00",["player", "id", "0", "?"]]}' http://192.nnn.n.nnn:9000/jsonrpc.js

Please change ip address to that of your LMS server. Use the player id in the response for the next commands. Note that the command is a long single line (which shows up as multiple lines in Wiki).

These are some of the commands that you can use:

Play

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["00:04:20:ab:cd:ef",["play"]]}' http://192.nnn.n.nnn:9000/jsonrpc.js

Please change dummy id 00:04:20:ab:cd:ef and ip address.  

Pause

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["00:04:20:ab:cd:ef",["pause"]]}' http://192.nnn.n.nnn:9000/jsonrpc.js

Please change dummy id 00:04:20:ab:cd:ef and ip address.

Skip to next song

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["00:04:20:ab:cd:ef",["playlist","index","+1"]]}' http://192.nnn.n.nnn:9000/jsonrpc.js

Please change dummy id 00:04:20:ab:cd:ef and ip address.

Skip back to previous song

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["00:04:20:ab:cd:ef",["playlist","index","-1"]]}' http://192.nnn.n.nnn:9000/jsonrpc.js

Please change dummy id 00:04:20:ab:cd:ef and ip address.

These curl commands are long, so create a bash script file for each command and name it with a single letter. This will make it easy to execute the command  e.g. to pause, bash p. It also makes it easier to program the remote (see below).

 

Setting up Flirc USB

You can run the Flirc software either on a Linux, Windows or MacOS computer. Plug the device into the USB port of the computer.  For Linux install:

sudo curl apt.flirc.tv/install.sh | sudo bash

Start up the flirc shell.

flirc_util shell
 

Alternately, download (scroll down page, click on download tab)  Windows or MacOS software.

On Windows 11,  open Command Prompt and start up the Flirc shell

cd "C:\Program Files (x86)\flirc"
flirc_util.exe shell

 

Start recording process

Using the command "bash p" as an example, start the recording process for first keyboard stroke

record b

Press your selected remote button

Record next keyboard stroke of the macro

record_macro a

Press same remote button

Repeat the record_macro command for s, h, space (for spacebar), p, enter (for enter key stroke).  Follow the same process for the other remote buttons.  
 

There are other useful Flirc commands including format (to clear everything) and settings (to show your recorded macro). You should save your recordings using saveconfig filename. To get a list of Flirc commands, use help.

 

Testing the Remote

Flirc emulates a keyboard when you press the recorded macro button.  You can easily test it by pressing the recorded button and see it in command line. If you are using a SSH session connected to the LMS computer, pressing the remote button will execute the keyboard command e.g. pause music.

Of course the ultimate test is plugging the USB receiver into the computer (which can do the keyboard commands) and try your IR remote to control your playback. 

Initially, attach a monitor, and watch how well the remote and Flirc USB work in your setup.   Responsiveness depends on signal strength of remote and your room. If poor, try using a USB A extension cable and a paper cone around the Flirc USB.

You can also fine tune things such as shortening the macro command (e.g. ./p to pause), disabling command feedback and error handling.

 

Other considerations

All keyboard commands and shortcuts will only work if the SnakeOil user is logged in to the computer. You can either login manually, change the instance to auto login or program a remote button to log in. 

LMS commands will work on any terminal connected to server or player.  For other software players, you will need to check whether the player needs to be enabled to allow the keyboard command or shortcut to work.

Please note that if you intend to use volume control within software players like LMS and Mpd, you can degrade audio quality. Specifically, it can reduce the signal-to-noise ratio and potentially the bit depth, leading to a loss of resolution and dynamic range.  Roon and HQPlayer have DSP volume control, which should not affect sound quality.

 

Setting up other music players

Mpd

Install a command client like mpc

sudo apt install mpc

Mpc gives you full control of mpd. For example, to go to the next song

mpc next

Use help to list the mpc commands. Create a macro for the commands you want to use on the infrared remote.

 

Mpd, with mpc, has been tested, but not the following players. If you have successfully included a remote with one of these players, please post your experience in the forum.

 

Roon

Roon provides keyboard shortcuts for Windows and OSx. Shortcuts can be recorded in one step using this command:

record_api x y where x is the modifier key and y is the HID key

Please read this Flirc forum post that explains how to specify the modifier key and HID key.  For example, control-k skips to the next track and you can use this command.

record_api 1 14

where 1 is for left control and 14 is for k

There is a user extension that can run keyboard shortcuts on the console, but have not investigated further.

 

JRMC

Record their hot keys for  Windows with this command: 

record_api x y where x is the modifier key and y is the HID key

Please read this Flirc forum post that explains how to specify the modifier key and HID key. For example, control-N skips to the next track and you can use this command:

record_api 1 17

where 1 is for left control and 17 is for N

 

upmpdcli

If used with LMS, then all LMS curl commands will work. It will also likely work with a mpd command client like mpc. 

 

HQPlayer

There are keyboard shortcuts with the Desktop player. 

 

MinimServer

If used together with a hardware UPnP renderer, then it may come with an infrared remote which does the playback control. There is no need to do anything extra 

If used together with upmpdcli, then it may work with a mpd command client like mpc (see above).

If used with another software UPnP renderer, then it may work if the software has keyboard shortcuts. Otherwise, unlikely to work.

 

Learning IR Remote and Philips Protocol

The Philips (RC5, RC6) protocol alternates the output between button presses. Flirc USB struggles with this protocol. The solution is to use a learning IR remote to do "dual protocol".  Use the Philips protocol to control your Hi-fi and NEC protocol to do the rest of the playback controls with the Flirc USB.

You will need to teach the learning IR remote about the Philips buttons that are used to control volume, mute of your Hi-Fi. Then, learn the buttons from a NEC protocol remote (for another device), and use these buttons with the Flirc USB.  

This "dual protocol" approach has been tested with different protocol combinations (Philips with NEC, Apple which is modfied NEC with NEC), and with different learning remotes (Arcam, Logitech Harmony).

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Contents