There are a few different ways to communicate wirelessly.  Wifi is the one we use most often in our Smart Homes. But there are also some really useful devices that use Radio Frequency or RF.  So how do you get your RF devices to communicate with your Wifi devices? You grab one of these. The Sonoff RF Bridge.

 

So, why would you need an RF bridge?  Well, if you have RF devices and you want to be able to interact with them through Home Assistant or some other hub that is connected to your home network, you need some way for those RF messages to be converted or relayed to the wifi network.  That’s what the RF bridge does. It receives RF signals and passes them on through your wifi network. It also can receive wifi commands and convert them to RF signals to send commands to RF enabled devices that are capable of acting on those messages.

 

The most common RF Smart Home Devices are motion sensors, door or window sensors, doorbells, and RF remote control buttons.  I actually wasn’t using any RF devices prior to getting this RF Bridge. I had a lot of requests for a video explaining how to make it interact with Home Assistant, and the good folks at Banggood were kind enough to send me one to try.

 

The device I have included a motion detector and 2 door/window sensors.  Like all Sonoff devices they work out of the box with the eWeLink app. But you know me.  I love Sonoff, but I’m more interested in getting inside and replacing the firmware with something we can use with Home Assistant.  And you know my firmware of choice has been Tasmota. Now, are you ready for the plot twist? In this case…. I’m not going to use Tasmota. Bum bum bummmm.  Tasmota does work with the RF bridge. And I loaded Tasmota onto this Bridge, but the output it gives is a bit tricky to deal with after. When the sensors send the RF signal to the Bridge, the Bridge outputs an MQTT message that includes a lot of information.  I couldn’t reliably extract that information to use it with Home Assistant. I got a lot of help from Donka and others in the HA discord chat, and I know it’s possible because there are people using it, but in the end I gave it up for a simpler solution. I’m still pretty much married to Tasmota, and I’m sure at some point I’ll figure it out and make another tutorial using Tasmota with the RF bridge, but for the sake of getting this baby working I went with a different solution. Still love you Theo!

 

Huge thanks here to Jafterdark. This guy is a genius.  He introduced me to a different firmware called OpenMQTTGateway, we’re going to call it OMGeeee. (sorry, I won’t do that again) It is similar to Tasmota in that it can be used on ESP8266 based devices, but in this case it outputs a simple code when it receives an RF signal, that is easy to use in Home Assistant.  There’s a github page with all the instructions for loading it on a variety of devices. But, to make things super easy for us Sonoffophiles, Jafterdark ignored his kids and other life responsibilities for hours to create a binary file to make flashing the Sonoff RF Bridge as easy as possible.

Here’s the flashing process:

Download the ESPeasy flashing tool (FlashEZ) the version changes, but this link should always get you the file we really want.

https://github.com/letscontrolit/ESPEasy/releases/download/mega-20180513/ESPEasy_mega-20180513.zip

Open the zip and extract everything.

 

Then download this binary file:  https://tinyurl.com/ybyx2g3z

And save it to the folder that contains FlashESP8266.exe

 

Now get access to the guts of your RF Bridge. Flip this little switch to OFF.  Connect your FTDI adapter to the serial pins here. If you don’t have one, I’ve included a link to the one I use.  On the RF Bridge, the “learn” button here on the side is connected to GPIO-0, so with your FTDI adapter connected, you hold down this button then plug the usb cord into your computer. Then open FlashEZ, select your com port, and the OpenMQTTGateway.bin file and offerup a burnt sacrifice…

Once that is successful (I’m sure it’ll be the first try :), then get on your phone or other wifi device and find the wifi network called OpenMQTTGateway. In this case you can’t use Termite.  At least I don’t know the serial commands that OMG uses. When you connect to that network you’ll be able to put in your home wifi info and mqtt broker info. After that, OMG will be working. Now there isn’t a webUI for OMG like we’re used to with Tasmota.  So to see the MQTT topics the RF Bridge is now able to publish we need some way to monitor what messages our broker is receiving. When an RF device sends a signal and it is received by the RF Bridge, the Bridge publishes an MQTT message to the topic “home/OpenMQTTGateway/SRFBtoMQTT” with a payload that is unique for each sensor.  So to find out what the code is that belongs to your sensor you need to subscribe to that topic. There’s a bunch of ways to do that. A couple options I’ve used are MQTTlens and MQTT.fx

http://mqttfx.jensd.de/index.php/download

https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm

 

For either, you’ll need your MQTT broker IP address, user/pw, and then the topic for the RF Bridge.  What you’re doing really is subscribing to that topic and just displaying the payload. Now with the RF bridge powered up and connected to your network and your MQTT borker, when you activate an RF sensor (let’s use the motion sensor to start with) you’ll see a code displayed.  That code is what will link Home Assistant to that sensor, via the bridge.

Now we can setup the Motion Sensor in HA. First add a new binary_sensor to your Configuration.yaml file, like this:

 

# binary_sensor
– platform: mqtt
name: “Garage Motion”
state_topic: “home/OpenMQTTGateway/SRFBtoMQTT”
payload_on: “123456”
payload_off: “123456off”
device_class: Motion
optimistic: false
qos: 1
retain: false

Replace “123456” with the code that we got from MQTTLens when we activated the motion sensor. For the “payload_off” we have to just create a fake payload. That’s because there’s no “no motion” code.  Meaning the sensor doesn’t send a message when there’s no motion. It just doesn’t send anything. So to get our sensor state in Home Assistant go revert back to “no motion” we have to make a “fake” off state and set up an automation to set to back to “no motion” after a period of time. If we don’t do that, then after one “motion detected” message the sensor state in HA would just stay on. For simplicity, we’re going to use the same RF code we used for the “on” state and just add “off” to the end of it.  That way we know we’ll have a unique payload that only applies to this sensor.

 

Open your automations.yaml file and put this:

 

– alias: Reset RF Motion State
hide_entity: true
initial_state: ‘on’
trigger:
– platform: state
entity_id: binary_sensor.garage_motion
to: ‘on’
for:
seconds: 5
action:
– service: mqtt.publish
data:
topic: home/OpenMQTTGateway/SRFBtoMQTT
payload: 123456off

 

I put my motion sensor in the garage. And I made another automation that will turn the garage lights off if there’s no motion detected for more than 30 min.

 

– alias: Garage Lights Off

hide_entity: true

initial_state: ‘on’

trigger:

– platform: state

entity_id: binary_sensor.garage_motion

from: ‘on’

to: ‘off’

for:

minutes: 30

action:

– service: switch.turn_off

data:

entity_id: switch.garage_lights

 

Now this kit also came with some door sensors. We can set them up the same way. Open MQTTlens, activate the sensor, copy the code from the payload, and use that to make the component entry. In the configuration.yaml the entry looks like this:

 

# binary_sensor
– platform: mqtt
name: “Shop Door”
state_topic: “home/OpenMQTTGateway/SRFBtoMQTT”
payload_on: “234567”
payload_off: “234567off”
device_class: Door
optimistic: false
qos: 1
retain: false

 

And we set up an automation to turn it back to off the same way:

 

– alias: Reset RF Shop Door
hide_entity: true
initial_state: ‘on’
trigger:
– platform: state
entity_id: binary_sensor.shop_door
to: ‘on’
for:
seconds: 5
action:
– service: mqtt.publish
data:
topic: home/OpenMQTTGateway/SRFBtoMQTT
payload: 234567off

 

Now I need to address a potential shortcoming of these door sensors.  They only send one RF code. That means, they send a code or a message that says, “I’m Open” but they don’t have the ability to send another message that says “I’m closed”.  So when the door gets opened, the sensor activates, that’s great. But when the door gets closed… we don’t know it. We can handle it the same as we did with the Motion sensor, but that’s not a great solution either, because the automation will send the “door closed” message after 5 seconds, but the door might still be open.  There are other sensors that send one code when they are opened and one when they are closed. But these are not those sensors. These are:

https://amzn.to/2JoTrpB

Those sensor send one code when the door opens and another when it closes. If you want to use the RF for an alarm system, you probably want to get some 2-code sensors.

 

These single code sensors are best for places where you don’t normally expect it to be opened, or where you don’t really care about the current state, just that there was a change from closed to open. I’m using mine just as a trigger and not really as a state sensor.  Here’s the automation I’m using with these single code door sensors.

 

– alias: Garage Lights On

hide_entity: true

initial_state: ‘on’

trigger:

– platform: state

entity_id: binary_sensor.shop_door

to: ‘on’

– platform: state

entity_id: binary_sensor.garage_door

to: ‘on’

– platform: state

entity_id: binary_sensor.garage_motion

to: ‘on’

condition:

– condition: state

entity_id: switch.garage_lights

state: ‘off’

action:

service: switch.turn_on

data:

entity_id: switch.garage_lights

 

When the sensor on my shop door activates I want the lights to turn on.  That’s it. I don’t care if the door closes or not, I just want to trigger the lights.  Then as long as there is motion the PIR will keep the lights on and turn them off when there’s no motion.  Or if you want to sound an alarm when someone opens the fridge after midnight…

 

That’s it. The Sonoff RF Bridge, flashed with OpenMQTTGateway, and integrated into Home Assistant via MQTT.  My overall impression is definitely positive. I’m impressed with the range of these RF devices. And they are very reliable.  More so than wifi, at least at my house.

 

You’ll need these A23 batteries for the door sensors: https://amzn.to/2l1sZ7A