Processing signals from 433MHz RF Devices to automate a Smart Home using MQTT/Nodered

I have been using a Sonoff RF bridge in my network to connect the 433MHz RF devices I have with the home network. In fact, there are two of these in my home to provide better coverage for the 433MHz devices.

I flashed the Sonoff RF bridge with Tasmota firmware rather than using the factory firmware that came with it, so I don’t have to use the eWeLink app. After getting Tasmota, it it’s all in my control and I use MQTT and Nodered to process the RF signals and issue commands to other Smart Home devices (or other RF devices) to get things done.

There are some great tutorials (one here) on how to get Tasmota on the Sonoff RF bridge, so I will not cover flashing Tasmota in this post. I will focus more on using Nodered to process the MQTT messages generated from the RF bridge to get things done.

After flashing Tasmota and configuring MQTT on the RF bridge we will have to check the Tasmota console to see the RF raw data published corresponding to the events detected by 433MHz RF Sensors or 433MHz switches. For this demo I’m using an 8 Button wall mountable RF remote/switch from Sonoff. This remote/switch is cheap but it works! You can use any compatible 433MHz device for this.

There’s no need to pair this switch (or sensors) with the RF Bridge when using Tasmota because the RF bridge will be accept any incoming RF signals it can capture and dump the raw data to the MQTT topic. What we do with that MQTT payload is up to us. The MQTT topic would be “tele/<Your-RF-Bridge-Name>/RESULT”

If you open the Tasmota console of the RF bridge and press a button on the remote (or move a sensor or whatever…)  you can see the MQTT payload as a JSON message.

Else you can subscribe to the MQTT channel using a client and see the payload. I use MQTT Box; a Chrome plugin (Chrome Web Store) as an easy MQTT Client.

Or you can do this in Nodered itself by subscribing to that channel with an “MQTT in node” and pushing the complete message object to a “debug node”. Here is the  received JSON object as it is.

If you look closely here apart from all the gibberish in the JSON payload, what we really need is the 6 digit hexadecimal code under “Data”:”A80758″. In this case it’s “A80758”. Each button on this remote and each 433MHz sensor would have a corresponding 6 digit hex code. Some contact sensors generate two codes for two states; one when it’s getting open, and one when it’s getting closed.

I use the above Nodered flow to get extract this code. Here it accepts the complete JSON using an MQTT in node, Converts JSON to a JavaScript object using a “parser” node and fetching the hex-code using a function/change node. To extract the hex code for “Data”; in the change node – Rules: [ Set “msg.payload” to “payload.RfReceived.Data” ]

Here’s what the debug nodes above (Raw JSON payload and the extracted hex-code) show for a button press. We have the hex code as the payload at the end of the flow.

[ You can skip the next paragraph if you don’t want to deal with the issue of having two RF Bridges listening to the same signals 😊 ]

Now…. I have two RF Bridges at home and even though it increases the range and reliability (yes it does, because sometimes I have seen some signals are picked up by only one bridge even though the two bridges are at the same distance from the sensor which generated the signal). I have used two identical flows as above for the two RF Bridges and used the “deduplicate node” to remove a duplicate signal received within 2 seconds. This would work as long as you don’t have any sensors or buttons (that has a function for a double click!) that need to push two messages – one after other – to operate.

The flow output is then fed to a switch node which will direct separate flows depending on the message it receives – different button presses, different sensor activation. Only caveat is we must find the hex codes generated by different events and make sure that “switch node” in Nodered knows what to do with those hex codes. I usually call various services in Home Assistant or publish different payloads to another MQTT topics (to trigger other automatons) based on the hex-code received. The possibilities are endless!!!

Additionally, I fetch other information also from the raw JSON payload and insert data into a database running on a Mariadb/MySQL docker container, so I can go back and see the hex-codes that the RF Bridges capture. Interestingly, I have seen from time to time that I get signals from devices that I don’t know of. Could be from the neighbors or electronic devices at home that communicate in 433MHz that I don’t know of yet.

As always thanks for your interest and thanks for reading!