This article is about building your own infrared bridge based on a Raspberry Pi Zero. Of cause it will not so comfortable to configure like a Logitech Harmony Hub, but it will be much cheaper – down to 12€.

Prerequirements:

Hardware:

  • 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)
  • Optional: Infrared receiver (if you like to capture your own remote signal) (I used this one: Reichelt Link)
  • Optional: USB SD-Card-Reader (if you don’t have a Card Reader in your device) (Amazon* Link)
  • Optional, not required for this how-to: MicroUSB to USB Adapter (to connect a keyboard to the Raspberry Pi Zero)
  • Optional, not required for this how-to: MiniHDMI to HDMI Adapter (to connect a screen to the Raspberry Pi Zero)

Software:

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:

Raspberry Pi Zero IR Bridge LayoutConnected IR Bridge LayoutConnected IR Bridge Layout Reverse

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

If you have a Mini-HDMI to HDMI-Adapter and a Micro-USB to USB-Adapter, you can connect directly to the Zero. But you do not need this for this tutorial! The following steps can be used to install the Raspberry Pi Zero without any adapters. The basic setup will be done on your Windows machine.

Step 1: Download the image for the Raspberry Pi Zero. Download the Lite-Version of the latest OS (at time of writing, it is “Stretch”): https://www.raspberrypi.org/downloads/raspbian/

 

Step 2: Flash the SD card

Save the file on your local PC somewhere where you will find the file. When the download is done, you have to extract the image the from downloaded zip-file. To do so, right click the file and select “Extract all..” and click “Extract” at the bottom of the window.

 

After this is done, a window will open with the “2018-06-27-raspbian-stretch-lite.img”-File. Maybe the file is named slightly different in your download. If you have this, the img-file is ready to be copied to the SD Card.

Now copy the downloaded image to the SD Card. Plug in your card reader with your SD Card in the SD Slot or in case of a build-in card reader, just plug in the SD Card. You also need a software to copy the image. I recommend “Win32 Disk Imager”. That one is free and easy to use. You can download it here: https://sourceforge.net/projects/win32diskimager/
After the download, please install and start the software. You will see this window:

 

In the first field, select the img file you just extracted and select the SD Card-Reader drive at the right (1). If you have no USB Stick or external HDD connected to your system, the SD-Card Reader should be the only drive that is available (2). After you entered this options, click the “Write”-Button (3).

Finally you will get a success message and the write process is done.

 

Step 3: Configure the Raspberry
Windows will now find a new drive called “boot“. Usually it has the drive letter, that was used during the image writing (arrow with point 2 above). To be able to access the Raspberry after the setup via SSH, we will create a file called “ssh“. Important: Lower case and no file extension. To create such a file, change to the “View“-Tab of the file explorer (1) and check “File name extensions” (2). Perform a right click in an empty area of the explorer (3) and select “New” (4) => “Text Document” (5).

A new file will be shown in the explorer. Name it “ssh” without any extensions. Windows will ask you if you are sure to do so: Yes we are. We do not need to write any content to the file. It is just important that the file is present. When the Raspberry starts, it will automatically start the SSH services. This allows us to connect to the Raspberries console.

To be able to connect to the Raspberry, it also need a Wifi connection. To configure this, we will need Notepad++ (Download here). Windows Notepad or Wordpad will not work because we have to take care about the Unix line feed format. This is different between Windows and Linux/Unix.
Create a new file called “wpa_supplicant.conf” next to the ssh-file the same way we did before. Right click the file and select “Edit with Notepad++“.

Paste the following text into the editor. Replace the country-, ssid- and psk-values with yours. (i.e. country=US, ssid=”myWifi”, psk=”myTopSecretWifiPassword”).

country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="MyWifi"
    scan_ssid=1
    psk="IdontTell"
    key_mgmt=WPA-PSK
}

Next take a look at the lower right of the editors window. Doubleclick the “Windows (CR LF)“-Text in the Statusbar and select “Unix (LF)“.

Save the file and close the editor.

 

Step 4: Start and continue to configure the Raspberry
Remove the SD Card from the card reader and plug it into the Raspberry. After about a minute you should find your Raspberry in your network (if you are using DHCP). The easiest way to figure out the IP is to ping the name “raspberrypi” using IPv4 protocol. To do so press the Windows-Key and “R” and enter “cmd“.

Press OK. Enter “ping raspberrypi -4” into the console and press enter (1). It will ping the raspberry four times and shows the IP-Address (2). In the screenshot it is 192.168.0.145. Note the IP-Address for future use.

Now we can connect to the Raspberry via SSH. We will need Putty for this (Download here). After starting Putty, enter the IP of your Raspberry (1). To save the settings for future connections, enter a name in the “Saved Sessions” field (2) and click save (3). The name will appear in the list below.

Now doubleclick on the saved session to connect. The username (“Login”) is “pi” and the default password is “raspberry“. You will see the following after login:

You already see the hint, that you should change the default password. We will do it now. Type the following command into the console and press enter:

passwd

Now enter the current password (“raspberry”) and enter your new secret password twice. Remember: if you type a password in any Linux system, it is not shown. You will see no stars or any other character. It is like you didn’t type anything. If this was successful it will look like this and you password was changed:

Now we will change the default hostname to a unique one. You should do this because any other new RaspberryPi in your network will have the same name and this will cause problems in the network communication. To change the hostname, execute the following commands:

sudo hostname -b <your unique hostname>
sudo nano /etc/hosts

Now you are in a texteditor of Linux. Go to the line that starts with “127.0.1.1“, followed by “raspberrypi“. Replace the “raspberrypi” with your new hostname. And press Ctrl+O followed by return-key to write the changes. Now press Ctrl+X to exit the editor. At the end the file should look like this, where “rp-irbridge1” is the new hostname in my case:

Now execute the command

sudo nano /etc/hostname

and replace “raspberrypi” again with your new hostname. After you changed the name, press Ctrl+O, return, Ctrl+X to save the changes and quit the editor.

Reboot the Raspberry with the following command to apply the changes:

sudo reboot

After about a minute the Raspberry should be back online and you can connect via Putty using your saved session. After you logged in with the user “pi” and your new password, you will see that new lines are now starting with “pi@<your hostname>:“. The part after the @ is the new hostname of your Raspberry. Also the hint for the password is gone.

Now the final step to setup the Raspberry: Updates. Login and execute the following commands:

sudo apt-get update
sudo apt-get -y dist-upgrade

The first command will take a moment. The second one will take ten moments. After that the Raspberry is setup and up to date.

 

 

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_dev
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:

LIRCD_ARGS=”–uinput”
LOAD_MODULES=true
DRIVER=”default”
DEVICE=”/dev/lirc0″
MODULES=”lirc_rpi”

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:

sudo reboot

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.

 

Remarks:
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 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.