I assume that you have the Sonoff RF Bridge 433MHz flashed with Tasmota firmware and initially configured to handle MQTT. Optional requirement would be configuring pre-defined RFKeyX’s. Full tutorial is written i previous post. this guideline covers OpenHAB configuration only.
I went through OpenHAB community forum to get the best approach in configuring Sonoff RF Bridge. There are different solutions and configs. I tried to get the best and put them together here. Solution is quite simplified as I do not use any rules yet. They will be required when you use virtual buttons or devices that send data and we have to act upon that.
Generally there are 2 approaches how to control remote devices like wireless switch using Sonoff RF Bridge.
- You capture signal and configure RFKeyX in Sonoff RF Bridge. Then configure OpenHAB to send MQTT requests to switch RFKey1, RFKey2…RfKey16
- You do not need configure RFKey at all. You use full 433MHz code that is captured by Sonoff RF Bridge and re-use it directly in MQTT requests. Bridge works as WiFi-to-433MHz gateway.
In both cases receiving MQTT messages and binding them to the Items is the same. To be more specific I mean getting input from devices which only send data one-way (PIR, weather station, temperature sensor, reed switch etc.)
I focus only on OpenHAB2 and MQTT plugin v2.x.
Scenario 1 – Separate RfKeyX
Let’s say that you were able to learn codes to Sonoff RF Bridge. There are 16 codes that can be programmed. In order to execute any of them we have to pass command RfKeyX
where X
is the value from 1-16. If key has code learned then it is executed.
MQTT act fast as RfKeyX has already saved in Sonoff RF Bridge Flash
You have to learn code in Sonoff RF Bridge first
.things
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// Common part: MQTT server definition, Sonoff RF Bridge state control Bridge mqtt:broker:localbroker [ host="192.168.1.254", secure=false, clientID="OpenHABv2" ] { Thing mqtt:topic:sonoffbridge { Channels: Type string : reachable "Reachable" [ stateTopic="tele/sonoff-bridge/LWT" ] Type string : recieveddata "Received Data" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"] Type string : recievedsync "Received Sync" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"] Type string : recievedlow "Received Low" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"] Type string : recievedhigh "Received High" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"] Type string : recievedrfkey "Received RfKey" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"] Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/sonoff-bridge/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"] // Custom already programmed 16 buttons: Type switch : button1 "Button 1" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RfKey1", on="6", transformationPattern="JSONPATH:$.RfKey1" ] Type switch : button2 "Button 2" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RfKey2", on="6", transformationPattern="JSONPATH:$.RfKey2" ] Type switch : button3 "Button 3" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RFKEY3", transformationPattern="JSONPATH:$.RfKey3" ] Type switch : button4 "Button 4" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RFKEY4", transformationPattern="JSONPATH:$.RfKey4" ] Type switch : button5 "Button 5" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RFKEY5", transformationPattern="JSONPATH:$.RfKey5" ] Type switch : button6 "Button 6" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/RFKEY6", transformationPattern="JSONPATH:$.RfKey6" ] } } |
.items
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Group GF_Sonoff_RF "RF Bridge" <sonoff_rf> (Sonoff_RF) String GF_Sonoff_RF_Reachable "Reachable: [%s]" <contactable> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:reachable" } String GF_Sonoff_RF_Received_Data "Received Data: [%s]" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:recieveddata" } String GF_Sonoff_RF_Received_Sync "Received Sync: [%s]" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:recievedsync" } String GF_Sonoff_RF_Received_Low "Received Low: [%s]" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:recievedlow" } String GF_Sonoff_RF_Received_High "Received High: [%s]" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:recievedhigh" } String GF_Sonoff_RF_Received_RfKey "Received RfKey: [%s]" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:recievedrfkey" } Number GF_Sonoff_RF_RSSI "WiFi Signal Strength [%d %%]" <wifi> (GF_Sonoff_RF) { channel="mqtt:topic:sonofbridge:rssi" } // Single buttons mapped Switch GF_Sonoff_RF_Button_1 "Button 1" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:button1", autoupdate="false"} Switch GF_Sonoff_RF_Button_2 "Button 2" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:button2", autoupdate="false"} Switch GF_Sonoff_RF_Button_3 "Button 3" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:button3", autoupdate="false"} Switch GF_Sonoff_RF_Button_4 "Button 4" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:button4", autoupdate="false"} |
.sitemaps
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Group item=GF_Sonoff_RF { Text item=GF_Sonoff_RF_Reachable label="Status [%s]" Text item=GF_Sonoff_RF_Received_Data label="Data [%s]" Text item=GF_Sonoff_RF_Received_Sync label="Sync [%s]" Text item=GF_Sonoff_RF_Received_Low label="Low [%s]" Text item=GF_Sonoff_RF_Received_High label="High [%s]" Text item=GF_Sonoff_RF_Received_RfKey label="RfKey [%s]" Text item=GF_Sonoff_RF_RSSI label="WiFi Signal Strength [%d %%]" Switch item=GF_Sonoff_RF_Button_1 label="RfKey1" mappings=[ON="Key 1"] Switch item=GF_Sonoff_RF_Button_2 label="RfKey2" mappings=[ON="Key 2"] Switch item=GF_Sonoff_RF_Button_3 label="RfKey3" mappings=[ON="Key 3"] Switch item=GF_Sonoff_RF_Button_4 label="RfKey4" mappings=[ON="Key 4"] } |
Scenario 2 – RfKeyX mapped to the button
In previous scenario in Sitemap file we have to use 2 separate buttons to handle one wireless switch. RfKey1 sent separate signal to ON and RfKey2 sent separate signal to OFF. If you use remote switch only in Rules then it doesn’t matter but if you want to have more human readable interface it is better to use traditional 1 switch button to handle 1 socket/relay.
I changed thing definition, separate for ON and OFF action. I use also different MQTT command: Backlog
MQTT act fast as RfKeyX has already saved in Sonoff RF Bridge Flash
You have to learn code in Sonoff RF Bridge first
In example below I skip common parts for Sonoff Bridge states, just focus on relevant changes.
.things
1 2 3 4 5 6 7 8 9 10 11 |
// Common part: MQTT server definition, Sonoff Bridge state control Bridge mqtt:broker:localbroker [ host="192.168.1.254", secure=false, clientID="OpenHABv2" ] { ... // Programmed 6 sample buttons in 3 user friendly button switch: Type switch : switchrfA "Switch rf A" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfKey1", off="RfKey2"] Type switch : switchrfB "Switch rf B" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfKey3", off="RfKey4"] Type switch : switchrfC "Switch rf C" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfKey5", off="RfKey6"] } } |
.items
1 2 3 4 |
// Default Switch buttons mapped to RfKeyX Switch GF_Sonoff_RF_Button_1 "Button 1" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfA", autoupdate="false"} Switch GF_Sonoff_RF_Button_2 "Button 2" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfB", autoupdate="false"} Switch GF_Sonoff_RF_Button_3 "Button 3" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfC", autoupdate="false"} |
.sitemaps
1 2 3 4 5 |
Group item=GF_Sonoff_RF { Switch item=GF_Sonoff_RF_Button_1 Switch item=GF_Sonoff_RF_Button_2 Switch item=GF_Sonoff_RF_Button_3 } |
Scenario 3 – Sonoff Bridge as a Gateway
Sonoff Bridge may act as MQTT<WIFI>433MHz Gateway. We may manually define what 433MHz message should look like and send over the air. At the beginning it is good to learn codes and then view and re-use them in custom MQTT queries. To show details of learned code assigned to RFKey1 you may type in console:
RfKey1 6
MQTT act fast as RfKeyX has already saved in Sonoff RF Bridge Flash
You have to learn code in Sonoff RF Bridge first
.things
1 2 3 4 5 6 7 8 9 10 11 |
// Common part: MQTT server definition, Sonoff Bridge state control Bridge mqtt:broker:localbroker [ host="192.168.1.254", secure=false, clientID="OpenHABv2" ] { ... // Programmed 6 sample buttons in 3 user frienldy: Type switch : switchrfA "Switch rf A" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfSync 9840; RfLow 340; RfHigh 960; RfCode #400551", off="RfSync 9840; RfLow 350; RfHigh 960; RfCode #400554"] Type switch : switchrfB "Switch rf B" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfSync 9860; RfLow 340; RfHigh 960; RfCode #401151", off="RfSync 9870; RfLow 350; RfHigh 970; RfCode #401154"] Type switch : switchrfC "Switch rf C" [ stateTopic="stat/sonoff-bridge/RESULT", commandTopic="cmnd/sonoff-bridge/Backlog", on="RfSync 9850; RfLow 340; RfHigh 960; RfCode #401451", off="RfSync 9890; RfLow 320; RfHigh 980; RfCode #401454"] } } |
.items
1 2 3 4 |
// Default Switch buttons mapped to customized mqtt queries Switch GF_Sonoff_RF_Button_1 "Button 1" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfA", autoupdate="false"} Switch GF_Sonoff_RF_Button_2 "Button 2" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfB", autoupdate="false"} Switch GF_Sonoff_RF_Button_3 "Button 3" <none> (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:switchrfC", autoupdate="false"} |
.sitemaps
1 2 3 4 5 |
Group item=GF_Sonoff_RF { Switch item=GF_Sonoff_RF_Button_1 Switch item=GF_Sonoff_RF_Button_2 Switch item=GF_Sonoff_RF_Button_3 } |
MQTT Debug
Sometimes we need to check what is happening inside Sonoff RF Bridge. For MQTT testing it is good to install Chrome plugin MQTTLens. Add broker and may either subscribe to topics or publish MQTT messages.
In other end, on the server side in order to get live logs you have to subscribe to all topics “#”. In case of mosquitto you may run the following:
1 2 3 4 5 6 7 |
iot@sabayon ~ $ /usr/local/bin/mosquitto_sub -v -h 192.168.1.234 -p 1883 -t '#' tele/bridge/LWT Online ESP_Easy/status/LWT Connected cmnd/bridge/Backlog RfSync 9840; RfLow 340; RfHigh 960; RfCode #400551 stat/bridge/RESULT {"RfSync":9840} stat/bridge/RESULT {"RfLow":340} stat/bridge/RESULT {"RfHigh":960} |
Links
https://github.com/arendst/Sonoff-Tasmota/wiki/Commands
Promo
Now Sonoff smart devices are cheaper: SONOFF -15% OFF
Cześć
Czy możesz pokazać jakie tematy masz wpisane w BridgeRF? Fajnie to widać w zakładce Information w Tasmocie. Niestety ale nie mogę ogarnąć tych tematów…
Pozdrawiam.
poniżej screen’y:
Thank you for this. Very helpful in pointing me in the right direction. I was able to trigger a Sonoff basic via a Key Fob. It took a while, but I was successful in my proof of concept to under OpenHab 2.5 and Tasmota 8.2.0. I am using the bridge as a gateway.
Thank you. Besafe!
Bob