Hardware setup

First, the RF Transmitter Module needs to be installed on the Raspberry Pi. Check your RF Module and Raspberry Pi for the correct connections (I will not go into detail here as a lot of tutorials are already available online).

The RF Transmitter module has three pins: Ground, VCC and Data. In my case, I needed to connect Data with GPIO 17:

I also soldered an antenna to the transmitter which tremendously increased the range.

Software installation/configuration

First, we need to install wiringPi (library to access the GPIO pins of the Raspberry Pi) as it is a prerequisite for rcswitch-pi (library to talk to the RF Transmitter):

where 11111 is the System-Code and 3 is the unit-code according to our DIP-switch settings on the remote power switch to be controlled. The last parameter is 1 (ON) or 0 (OFF).

OpenHAB configuration

exec binding

First, if not done already, we need to copy the exec binding (included in the openHAB addons package) to our openHAB/addons directory. This binding enables us to later call the command line (and therefore rc-switch) from openHAB.

Switch scripts

Now we can create two shell scripts in folder /opt/rc-switch/ to be called from openHAB: switchOn.sh and switchOff.sh:

#!/bin/bash
for run in {1..5}
do
/opt/rc-switch/rcswitch-pi/send 11111 $1 1
done

And also make them executable:

sudo chmod +x switchOn.sh switchOff.sh

The unit-code is passed as the first parameter ($1) to the script. The system-code (11111) is hard-coded. If we’d have more than one system-code, we need to pass it as a parameter, too.

On the one hand, these two scripts simplify calls from openHAB (as we will see soon). On the other hand, it increases the chance for successfully transmitting the command by sending it multiple (5) times. As there is no message to acknowlegde retrieval of the command by the remote switch and messages sometimes get lost/distorted, this is probably the easiest way to make sure the switch command gets through eventually.

Allow execution of the switch scripts as root

If we run openHAB as user ‘openhab’ (i.e. not as root), we need to make sure user ‘openhab’ is allowed to run the switch scripts as root without the need to enter a password, because wiringPi needs to be run as root.

One way to achieve this is to run sudo visudo and allow user openhab to run scripts on path /opt/rc-switch/switch* (which includes switchOn.sh and switchOff.sh) as root without entering a password:

This will add an item to openHAB to turn our remote switch with unit-code 1 on and off. After adding the item to our sitemap, the switch should appear in openHAB:

Disadvantages

Even though this solution is a great way to add smart lamps to one’s home, it has two disadvantages:

One-way communication: The communication is only from the RF Transmitter / Raspberry Pi to the power switch. We neither get feedback if the light on/off signal really reached the power switch nor it is possible to check the current state of the remote switch. – No security (can be controlled from the outside / from neighbours)

No Security: The communication channel is not secure, which means anybody who is in transmission range and knows/guesses the system and unit code of the power switches can switch our lights on and off. This might be acceptable for LED lamps, but I wouldn’t connect devices like an electricity heater.

Summary

All in all, if one can live with these disadvantages and the manual configuration, this is probably the cheapest solution for smart lamps and a great way to get started with a smart home!

Here is a video with the smart lamps in action, controlled via HABDroid (Android mobile client for openHAB):