This article is about building your own infrared bridge based on a Raspberry Pi Zero. Of cause it will not be so comfortable to configure like a Logitech Harmony Hub, but it will be much cheaper – down to 12€.
- Raspberry Pi Zero WH (Amazon* Link, Buyzero Link)
- Micro SD Card (min. 4GB) (check the Bundles at Buyzero if you need one)
- Power Supply with Micro-USB-Plug, recommended 2,5A or more (check the Bundles at Buyzero if you need one)
- Optional: Case for Rapsberry Pi Zero WH (check the Bundles at Buyzero if you need one)
- Infrared Diode (I used this one: Reichelt Link)
- Transistor (I used this one: Reichelt Link)
- Resistor (I used this one: Reichelt Link)
- Jumpercables (makes life much easier) or other kind if cables to connect everything (Amazon* Link)
- Maybe Optional: USB SD-Card-Reader (if you don’t have a Card Reader in your device) (Amazon* Link)
- Optional: Infrared receiver (if you like to capture your own remote signal) (I used this one: Reichelt Link)
- Optional, not required for this how-to: MicroUSB to USB Adapter (to connect a keyboard to the Raspberry Pi Zero) (Amazon* Link)
- Optional, not required for this how-to: MiniHDMI to HDMI Adapter (to connect a screen to the Raspberry Pi Zero) (Amazon* Link)
Attach all parts:
In the first step we will mount the hardware parts to the Raspberry Pi Zero. I just used tape to fix the jumpercables to the pins if the diode, resistor, transistor and IR receiver. Just the connection between the resistor and the transistor is soldered, but you can also connect this like all the other connections.
This is how I did it for my prototype:
In the final layout, you can solder all connections and use shorter cables. But for testing the tape-fixing also works pretty well. Just be sure the plug is completely attached to the pins.
Setup the Raspberry Pi Zero
Setup the Raspberry Pi Zero to configure our bridge later on. I documented the setup of a Raspberry Pi Zero in this Blog post: Setup Raspberry Pi Zero
Install and configure LIRC
To start with install and configure, connect to the RaspberryPi via SSH if you are not already connected.
To install LIRC running the following command:
sudo apt-get -y install lirc
Now we need to configure the boot configuration. Execute the following command to configure the GPIO access:
sudo nano /boot/config.txt
In the file close to the end is a line starting with “#dtoverlay“. Remove the leading hashtag and add the following to the line: ,gpio_in_pin=23,gpio_out_pin=22
This should look like this now:
Press Ctrl+O to write the changes and Ctrl+X to leave the editor. Now we need to edit the next file. Run the following command:
sudo nano /etc/modules
Add the following to the end of the file:
lirc_rpi gpio_in_pin=23 gpio_out_pin=22
Press Ctrl+O to write the changes and Ctrl+X to leave the editor. Now we will create a new file and add some content. Execute:
sudo nano /etc/lirc/hardware.conf
Add the following to the file:
Press Ctrl+O to write the changes and Ctrl+X to leave the editor. Now we need to edit the last file. Execute:
sudo nano /etc/lirc/lirc_options.conf
Search for the line that starts with “driver” and change the value after the = to “default“. After that search for the line starting with “device” and change the value to “/dev/lirc0“.
Scroll down and edit the line starting with “#listen” and remove the leading hashtag. Now change the value after the = to “0.0.0.0:8765“. This will tell LIRC to listen on any local ethernet adapter on port 8765 for commands send by a LIRC client.
Press Ctrl+O to write the changes and Ctrl+X to leave the editor.
Finally we need to run a command to be able to upload our remote conf-files later on. This sets the permissions in the config directory of LIRC.
sudo chmod -R a+rwX /etc/lirc/lircd.conf.d
Reboot the Raspberry using the following command:
The configuration of LIRC is done. In the next step we need to teach LIRC the IR-Commands to send.
Use IR commands to control a device
We will configure LIRC to control a device like a TV or audio device via IR commands. The RaspberryPi will act like the original remote you are using normally. We can download a configuration from the online database or create our own remote configuration.
Using a known command set
If you do not have installed the IR receiver to the RaspberryPi or you are too lazy to configure a new command set, you can use command sets that are in a online database. The link to this database is http://lirc-remotes.sourceforge.net/remotes-table.html. Search for a remote that matches one of your devices. The list is ordered by manufacturer. For this tutorial I will use the config for the remote of my Logitech Z5500 sound system. If you have found your device, hopefully it is in that list, download the .conf file.
Now we need to connect to the RaspberryPi using WinSCP (Download). Start WinSCP. Select “New Site” on the left and enter the hostname (or IP) of your IR Bridge-Raspberry, User name and password and click on “Save”.
Enter a name for the connection. For example the hostname. Click on OK.
The new connection will now appear on the left.
Doubleclick the connection to start the session and enter your password. In the right area doubleclick the “..” entry at the top two times. You should be in the root folder of your Raspberry now.
Doubleclick the Folder “etc” and after that “lirc” and “lird.conf.d“. Your right area of WinSCP should look like this now:
On the left site of WinSCP navigate to the place where you stored your downloaded conf-file with the remotes configuration. Typically it is the Downloads-Folder of Windows. Right click the conf-file and select “Upload” and click “OK”.
You should see the file on the right side now. After a restart of the LIRC services, LIRC knows our conf-file. To restart the services execute:
sudo systemctl restart lircd
Now we will see if the conf was recognized. Execute the following command to show all known remotes:
irsend list "" ""
You should now see some default configs and the one you uploaded.
Note the name of your remote that is shown in the list.
We will now test if the remote works. I assume you have a remote that has a volume up key. We will press this button once using the IR Bridge to test our hard- and software configuration. Execute this command:
irsend SEND_ONCE <your devicename> KEY_VOLUMEUP
in my case:
irsend SEND_ONCE logitech_z5500 KEY_VOLUMEUP
Your device should act like the volume up key on your original remote was pressed.
That’s it so far. Your RaspberryPi IR Bridge knows the commands of your remote. This is what we will trigger later on from our OpenHab device.
But what if the database that is linked at the beginning does not contain your remote? In that case you have to use your bridge setup including the IR-receiver and you need the original remote.
Teach the IR bridge a new remote
If you need to teach your IR bridge a new remote because the online database don’t know it, follow the steps in this chapter.
An additional small tip before we start: Prepare a box and a towel. We will need this. The IR receiver is receiving ALL IR waves. That results in heavy noise when we try to record our remote. If we place the RaspberryPi and the remote in the box covered by the towel and record the commands, we reduce this disturbances very much or completly.
First you have to stop the lircd service because it blocks the access to the IR receiver.
sudo systemctl stop lircd
Now execute the following command. You can rename the file from “myremote.conf” to any other valid name that ends with “.conf”.
irrecord -n -d /dev/lirc0 ~/myremote.conf
You will see the following output.
When you like to start press return.
In case your RaspberryPi was not already in the covered box, you will see the message (highlighted in yellow) below.
As it is mentioned in the message, you should press Ctrl+C and check your cover of the box! This is strongly recommended! Otherwise your work will be worthless! After you checked your cover, repeat the irrecord-command from above again.
If everything is ready for record and well covered, you should see the message blow (highlighted in yellow).
Now you can name your remote. I recommend to use the same name you use for the file. In my case it will be “myremote”.
After that you will see a message to press many different buttons on your remote. This is to calibrate the receiver and get the format of the IR-commands. Don’t stop pressing the buttons until the console shows the next output. Press return to start the recording.
While pressing (covered, in your box) it looks like this:
When you are done, you will be asked to enter the name of the next button you will press. This is the name, you have to state later on when you want to simulate the button by the IR bridge. There are many standard names like the KEY_VOLUMEUP button we used before. If possible, use this standard names. You can find a list of standard names here: https://gist.github.com/unforgiven512/0c232f4112b63021a8e0df6eedfb2ff3.
For demonstration purposes, I will show how to record the power and the volume up key. So the name of the first button will be “KEY_POWER“.
Remark: When you mistyped a key name, don’t correct it with backspace, del or cursor key. This will not work! We will correct this later!
After pressing return, irrecord will ask you to press and hold the button. Do so. When you are done, the console will ask for the name of the next button.
I will enter “KEY_VOLUMEUP” for the volume up button of my remote. After that I press return and hold the volume up button of the remote.
You can program all of your keys that way. When you are done leave the name empty and press return. Now you are asked to press the SAME button for your remote repeatedly as fast as possible. Don’t hold the button! Press return to start.
When everything was successful, you will see this output:
Now start WinSCP and connect to your IR Bridge-Raspberry Pi. Change to the home folder of the pi user (/home/pi). You will see a file called myremote.lircd.conf (or the name you have chosen).
If you mistyped a key name, we have to correct this. Doubleclick your conf-file. Scroll down a bit. There will be a section that starts with “begin codes”. After this there are your key names. You can rename them here. Don’t use any special characters or spaces! When you are done, press Ctrl+S to save the changes. You may have to reenter your password. You can close the editor now.
Now we have to move the config to the lirc-directory. Right click the file and select “Move To…”.
In the dialog enter the following path: /etc/lirc/lircd.conf.d
The conf-file is now in the lirc directory where the remote configurations are stored. Change back to your putty session. Execute this command to start the lirc service.
sudo systemctl start lircd
Now we will check if our configuration can accessed by lirc. Execute this command to list all known remotes:
irsend list "" ""
Our new remote will be in the list (hopefully). Here it is “myremote”.
Now let’s check if it works. Place your Raspberry that it can “see” the device you want to control. Execute the following command to send a IR command to the device. Depending on your configuration you have to replace the remotes name (here: myremote) and the command to send (here: KEY_POWER) by your own.
irsend SEND_ONCE myremote KEY_POWER
Your device should now act like if you pressed the original remote.
Control the IR Bridge using OpenHab
Now we will configure the LIRC IR Bridge based on Raspberry Pi Zero in OpenHab using the PaperUI.
In the PaperUI click on “Add-ons” (1) and select the tab “Bindings” (2). Search for “LIRC” (3) and click on “install” (4) next to the LIRC-Binding caption.
Now we need to configure the address of the IR Bridge. Click on “Configuration” > “Things” and the big blue + bubble.
In the next dialog select “LIRC Binding” followed by “LIRC Server”.
Enter a name of the LIRC Server (the IR bridge)(1). I chose the name of the RaspberryPi to make it easier to identify it later on. Now you need to state the IP of the IR Bridge (2) and in case you are using a non-default port the port (3). In this documentation we are using the default port. When you are done click the check at the top in the blue bubble.
You will be forwarded to the things view. In case everything went well, you will see the thing online in the list.
You will also see some items in the Inbox. This will be the available remotes in the config folder of the IR Bridge Raspberry Pi.
To add the Remote Control, click the check in the blue bubble in front of the Remote Control text (1). After this you can change the name of the Remote Control for OpenHab (2) and finally click on “Add as Thing” (3). Now the Remote Control is available in OpenHab.
No Open the added Thing and click on the blue bubble in front of the “Transmit Command” channel (1). A new window will open. Select “Create new Item” (2).
Confirm the dialog with the standard settings by click on “Link” on the bottom right. Now we have the channel available that is able to send Keys to the IR Bridge to send the IR commands to the devices you want to control.
Send IR Buttons using HabPanel
In the HabPanel change to an existing Dashboard or create a new one. In the Dashboard change to the edit-mode by hover the mouse over the Labs name and click the pencil on the right.
At the top right click on “Add Widget” > “Add Button”
Click on the three dots at the top right and select “Edit…”
Enter a name for the button. This name will be displayed on the button. Don’t change the “Action type” and select the openHAB Item that represents your Remote followed by “Transmit Command” (here “Logitech_Z5500_TransmitCommand”). Finally enter the name of the button that is used in the config file of the remote on the IR Bridge. To power on/off a device the command should always be “KEY_POWER”. Click on “Save”.
At the top of the page click on “Run” so we can test our Setup. Your device should now react on the click on the button.
You can do everything of this the same way for any command that is available in the Remotes conf-File on the IR Bridge. You can also rebuild the whole remote control if you like. A very basic interface for my Logitech Z5500 can look like this if you want to do so. You can find a picture to of the original remote here on Amazon*: Link
Basically that’s it. That way you can use your IR Bridge based on a Raspberry Pi Zero WH like a Harmony by using OpenHab but for much less money.
Product links marked with * are affiliate links. That means I get some percent of the money you will spend when you are using this links. I’m not trying to influence you. In most cases there are also links for other sellers for the products where I don’t get money for. I am not trying to influence you to spend more money than you need. If you are using this links, you don’t have to pay anything extra. It is the same price as if you enter the shop on your own. Please also keep in mind: This website is completely ad free. Thank you for your support.