Skip to content
A Raspberry Pi infrared remote control. The Python app has three parts: Functions to send commands to the infrared transmitter. A Flask web service to accept television command requests (e.g. volume decrease, volume increase). A scheduler that automatically sends remote control commands at programmed times (e.g. mute during TV commercials).
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
data Revert "Change QuietTime from start and end (both datetime.time) to s… Feb 19, 2019
tests Revert "Change QuietTime from start and end (both datetime.time) to s… Feb 19, 2019
.gitignore In .gitignore don't ignore *.txt Feb 12, 2019
LICENSE Add comment Apr 23, 2019 add project files Jan 20, 2019
environment.yaml Add environment.yaml Feb 10, 2019 In log statement delete unneeded \n. When running app it isn't needed… Feb 16, 2019 Add Reference Feb 16, 2019 In docstring fix missing key "start" Mar 8, 2019 Revise docstrings and comments Feb 11, 2019 In service.volume_decrease_increase() parse request.form key duration… Apr 26, 2019 use get_json() Apr 26, 2019 Move some constants to service_constants Apr 24, 2019


Make a Raspberry Pi infrared remote control. The device can programmatically control television sound bar audio volume. The Raspberry Pi uses LIRC (Linux Infrared Remote Control) to send commands to an attached infrared transmitter.

The Python app has three main parts:

  • Functions to send commands to the infrared transmitter, which then transmits the commands to the television sound bar
  • A Flask web service to accept television command requests (e.g. volume decrease, volume increase)
  • A scheduler that automatically sends remote control commands at programmed times (e.g. mute during TV commercials)


Infrared transmitter

Install hardware

Raspberry Pi IR Control Expansion Board. This uses gpio pins 17 out (IR LED), pin 18 in (IR receiver).

I bought Icstation 38KHz IR Infrared Remote Control Transceiver Shield for Raspberry Pi 2 3 Module B B+

connect to raspberry pi

Can attach keyboard and monitor to pi. Alternatively, can connect from another computer on local network via ssh.

ssh -v pi@

install LIRC

Michael Traver's excellent "Raspberry Pi IR Remote Control" has helpful up to date suggestions for configuring current versions of LIRC (0.9.4) and Raspbian (Stretch) and warnings about outdated online info.

sudo apt-get install lirc
The following additional packages will be installed:
  libftdi102 liblirc0 python3-yaml
Suggested packages:
  lirc-compat-remotes lirc-drv-irman lirc-doc lirc-x setserial ir-keytable

don't install package lirc-compat-remotes

This package is outdated, contains remote definitions which were part of lirc up to 0.9.0.

enable lirc-rpi

Add the following content to /boot/config.txt


enable transmitting

In /etc/lirc/lirc_options.conf

  • change driver to default
  • change device to /dev/lirc0

don't add or edit hardware.conf

LIRC 0.9.4 does not use hardware.conf

Add remote control config files

lirc looks in a configuration directory for files ending in .conf

/etc/lirc/lircd.conf.d has config files for many remotes. You can try any of these to see if they work with your device.

I added cxa_cxc_cxn.lircd.conf

pi@raspberrypi:/etc/lirc/lircd.conf.d $ sudo cp ~/beepscore/rpi-ir-remote/config/lirc/cxa_cxc_cxn.lircd.conf .

list cambridge_cxa configuration defined keys

Use lirc command irsend

irsend list cambridge_cxa ""

000000000000140c KEY_POWER
000000000000140e KEY_POWER_ON
000000000000140f KEY_POWER_OFF
000000000000140d KEY_MUTE
0000000000001432 KEY_MUTE_ON
0000000000001433 KEY_MUTE_OFF
0000000000001410 KEY_VOLUMEUP
0000000000001411 KEY_VOLUMEDOWN

send a key

irsend SEND_ONCE cambridge_cxa KEY_VOLUMEDOWN

The front facing camera on iPhone doesn't filter IR. It showed the raspberry pi is lighting the transmit infrared LED. However the remote configuration cambridge_cxa doesn't work with my Polk sound bar receiver.

Disable incorrect remote configuration files To disable a configuration file change extension from .conf to e.g. .dist

cd /etc/lirc/lircd.conf.d
sudo mv devinput.lircd.conf devinput.lircd.dist

Use infrared receiver to generate a new configuration file.

lirc-remotes has lots of files, but none named polk. Could try existing ones but this could be time consuming. Instead use an existing handheld remote transmitter to "teach" the Raspberry Pi how to act like that remote. The Raspberry Pi IR Control Expansion Board has an infrared receiver. LIRC command irrecord records button press infrared signals.

irrecord error need to stop lirc daemon

irrecord -d /dev/lirc0 ~/lircd.conf

Using driver default on device /dev/lirc0
Could not init hardware (lircd running ? --> close it, check permissions)
view running processes
stop lirc daemon process by name
sudo killall -9 lircd
list valid key names that are available to be assigned to a remote configuration file
irrecord --list-namespace
irrecord -d didn't work with polk remote, it never got enough info to make a .conf file.

In repo remy_python I added directory config to keep polk.lircd.conf in version control.

cd remy_python/config
irrecord -d /dev/lirc0 ./polk.lircd.conf
fix recording failing using option -f --force raw mode
irrecord -f -d /dev/lirc0 ~/polk.lircd.conf

Enter valid key names e.g. KEY_VOLUMEDOWN

For LIRC to use configuration file, copied it to


add more keys using option -u --update

cd remy_python/config
irrecord -f -u ./polk.lircd.conf

Then copy updated file to


list polk configuration defined keys

irsend list polk ""

0000000000000001 KEY_MUTE
0000000000000002 KEY_POWER
0000000000000003 KEY_VOLUMEUP
0000000000000004 KEY_VOLUMEDOWN
0000000000000005 KEY_UP
0000000000000006 KEY_DOWN

To run Flask web service

connect to raspberry pi

ssh -v pi@

cd to project directory

cd ~/beepscore/remy_python

If using conda (e.g. via miniconda), activate environment

source activate remy_python

start Flask web server

* Running on (Press CTRL+C to quit)
* Restarting with stat

Now clients on local network can see the remote control service.




Send a remote control command.


GET requests can be made via a browser such as Firefox or mobile Safari. POST requests can be made via clients such as terminal curl or POSTMAN or iOS

curl --request POST

server log

pi terminal shows client's ip address and request info - - [23/Jan/2019 23:39:22] "POST /api/v1/tv/volume-decrease/ HTTP/1.1" 200 - - - [23/Jan/2019 23:39:26] "POST /api/v1/tv/volume-increase/ HTTP/1.1" 200 -


install apscheduler

On macOS, can install via conda navigator. However I couldn't find conda apscheduler for raspberry pi. So install via pip.

source activate remy_python
pip install apscheduler


To run server and scheduler

source activate remy_python

To run scheduler but not server

source activate remy_python


Currently unused. Could be used together with closed caption text or speech recognition to detect commercials. Some commercials don't say product/service/company name until late in the commercial.

unit tests

Can run tests on macOS by temporarily commenting out Not sure how to run tests on pi yet.

python -m unittest discover

throws RuntimeError: working outside of request context


Raspberry Pi infrared remote control for a television sound bar

Network enabled Raspberry Pi tv remote control

Python Data Analysis to Automatically Detect and Mute Television Commercials



Remote control television by sending commands from iOS device to a server.

Similar remote control projects

Raspberry Pi IR Remote Control 2018, uses Go

by Michael Traver

LIRC Debian Stretch Raspberry Pi 2018

How to get LIRC running on the Raspberry Pi 2017

Setting up a remote control using lirc

Raspberry Pi IR remote 2015

Creating A Raspberry Pi Universal Remote With LIRC 2017

Open Source Universal Remote 2013

Open Source Universal Remote - Parts & Pictures 2013



lirc_node is an npm module that acts as a very thin shim between LIRC and Node.

LIRC Linux Infrared Remote Control

Infrared remote control hardware

Raspberry Pi IR Control Expansion Board

Icstation 38KHz IR Infrared Remote Control Transceiver Shield for Raspberry Pi 2 3 Module B B+

Raspberry Pi IR Control Expansion Board

Raspberry pi 3 B+ 38KHz IR Infrared Remote Expansion Board

WINGONEER 38KHz IR Infrared Remote Control Transceiver Shield for Raspberry Pi 2 3 Module B

Raspberry Pi Zero Universal Remote 2018

IR Board for Arduino

SparkFun WiFi IR Blaster (ESP8266)

ir blaster software


Build a Python-powered web server with Flask


Serving Raspberry Pi with Flask

Using a Raspberry Pi to end an iPhone phone call

Raspberry Pi GPIO projects


A simple Python flask web service to read and write Raspberry Pi GPIO.

Raspberry Pi GPIO API

Raspberry Pi Web Server using Flask to Control GPIOs

Inspirational projects

Enough Already by Matt Richardson

TV-B-Gone Kit


You can’t perform that action at this time.