Sonoff RF Bridge for controlling ventilation - how to send commands via MQTT?

Dear all,

Thanks to this tutorial I managed to set up the Sonoff RF bridge.

Unfortunately, now I’m struggling with getting my remote control for ventilation to work.

I figured out that Data: 079150 is standby message.
At 21:45:58 I’ve pressed the on/off button on the remote Data: 079158 - thus at 21:45:59 the ventilation has started.

At 21:47:20 I’ve pressed the on/off button again - Data: 079158 … and the ventilation gets back to standby mode Data: 079150.

21:45:44 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:44","RfReceived":{"Sync":9680,"Low":400,"High":1020,"Data":"079150","RfKey":"None"}}
21:45:47 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:47","RfReceived":{"Sync":9690,"Low":400,"High":1020,"Data":"079150","RfKey":"None"}}
21:45:50 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:50","RfReceived":{"Sync":9700,"Low":400,"High":1010,"Data":"079150","RfKey":"None"}}
21:45:52 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:52","RfReceived":{"Sync":9680,"Low":400,"High":1010,"Data":"079150","RfKey":"None"}}
21:45:55 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:55","RfReceived":{"Sync":9680,"Low":400,"High":1010,"Data":"079150","RfKey":"None"}}
21:45:58 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:58","RfReceived":{"Sync":9280,"Low":350,"High":910,"Data":"079158","RfKey":"None"}}
21:45:59 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:45:59","RfReceived":{"Sync":9710,"Low":390,"High":1020,"Data":"07915A","RfKey":"None"}}
21:46:02 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:46:02","RfReceived":{"Sync":9690,"Low":400,"High":1010,"Data":"07915A","RfKey":"None"}}
21:46:05 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:46:05","RfReceived":{"Sync":9690,"Low":390,"High":1020,"Data":"07915A","RfKey":"None"}}
21:46:07 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:46:07","RfReceived":{"Sync":9710,"Low":400,"High":1010,"Data":"07915A","RfKey":"None"}}

...

21:47:20 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:47:20","RfReceived":{"Sync":9350,"Low":330,"High":920,"Data":"079158","RfKey":"None"}}
21:47:21 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:47:21","RfReceived":{"Sync":9670,"Low":400,"High":1010,"Data":"079150","RfKey":"None"}}
21:47:24 MQT: tasmota/sonoffrfbridge/tele/RESULT = {"Time":"2020-04-07T21:47:24","RfReceived":{"Sync":9690,"Low":400,"High":1020,"Data":"079150","RfKey":"None"}}

I would really appreciate if someone could help me how to write a simple rule in order to switch the ventilation on and of.

Here is one way to write a rule for your RF codes:

val String filename = "rf_bridge.rules"

rule "Sonoff RF Bridge received update"
when
    Item GF_Sonoff_RF_Received_Data received update
then
    var String item = "unknown"
    var String message = "Sonoff RF Bridge received update for {}: "

    switch (triggeringItem.state) {
        case "079150" : {
            item = "Ventilation standby"

            if (Ventilation_Mode_Contact_Item.state == OPEN) {
                Ventilation_Mode_Contact_Item.sendCommand(CLOSED)
            }
        }
        case "079158": {
            item = "Ventilation ON/OFF"

            if (Ventilation_Power_Switch_Item.state == ON) {
                Ventilation_Power_Switch_Item.sendCommand(OFF)
            }
            else {
                Ventilation_Power_Switch_Item.sendCommand(ON)
            }
        }
        case "07915A": {
            item = "Ventilation something else. Spotted this extra RF Data code in your console logs. Maybe it means exiting standby mode and entering running mode? Who knows right now. You'll figure it out though. This is just a long and pointless log message to polute your OpenHAB logs."

            // Do something else, like this:
            if (BigRedDoNotPressButton.state == OFF) {
                BigRedDoNotPressButton.sendCommand(ON)
                // Oh nooooooooooooooooooooooooooooooooooooo!
            }
        }
        default: { 
            message = "No rule exists for code: "
        }
    }
    logInfo(filename, message + triggeringItem.state, item)
end

Create that rule and then follow your OpenHAB logs (found at userdata/logs/openhab.log) to ensure that the rule is firing.

1 Like

Many thanks for the code above.

I’ve implemented it into oH and it logs the data.

My ventilation system blows in the air for about 70 sec and then switches to blow out air for another 70 sec. The codes for that are 07915A / 07915B.

According to the log file, there are some other codes for which I don’t know the meaning.

2020-04-08 21:57:36.820 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Ventilation standby: 079150

2020-04-08 21:57:49.107 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Ventilation standby: 079150

2020-04-08 21:57:59.896 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Ventilation ON/OFF: 079158

2020-04-08 21:59:11.395 [INFO ] [marthome.model.script.rfbridge.rules] - No rule exists for code: 07905B

2020-04-08 22:00:25.106 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air in: 07915B

2020-04-08 22:00:33.332 [INFO ] [marthome.model.script.rfbridge.rules] - No rule exists for code: 079153

2020-04-08 22:00:57.974 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air in: 07915B

2020-04-08 22:01:10.560 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air in: 07915B

2020-04-08 22:02:06.686 [INFO ] [marthome.model.script.rfbridge.rules] - No rule exists for code: 07815A

2020-04-08 22:02:09.190 [INFO ] [marthome.model.script.rfbridge.rules] - No rule exists for code: 03C8AD

2020-04-08 22:02:17.740 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air out: 07915A

2020-04-08 22:02:31.335 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air out: 07915A

2020-04-08 22:02:35.240 [INFO ] [marthome.model.script.rfbridge.rules] - Sonoff RF Bridge received update for Air out: 07915A

2020-04-08 22:02:37.990 [INFO ] [marthome.model.script.rfbridge.rules] - No rule exists for code: 07905A

Currently, I can monitor all data on the Tasmota console, MQTT.fx, OH log and OH sitemap. It also switches the Ventilation_Power_Switch_Item.

What still doesn’t work is switching ventilation on/off via OH sitemap with Ventilation_Power_Switch_Item. Could you please help me again?

Today I’ve paired the on/off remote control’s on/off button to RF bridge key 1 by using the command RfKey1 2 in tasmota console.

19:36:19 CMD: RfKey1 2
19:36:19 MQT: tasmota/sonoffrfbridge/stat/RESULT = {"RfKey1":"Start learning"}
19:36:22 MQT: tasmota/sonoffrfbridge/stat/RESULT = {"RfKey1":"Learned"}

With this I’m able to switch the ventilation on/off by clicking button 1 in Tasmota GUI.

MQT: tasmota/sonoffrfbridge/stat/RESULT = {"RfKey1":"Learned sent"}

But OH logs always the following error

[ab.binding.mqtt.generic.ChannelState] - Command 'Learned sent' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.Learned sent
[t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey16' in '{"RfKey1":"Learned sent"}'

This is my Thing configuration:

 	Thing topic sonoffrf "Sonoff RF Bridge" @ "MQTT" {
        Type string : Sonoffrf_reachable     "Sonoff RF Bridge: Reachable"            [ stateTopic="tasmota/sonoffrfbridge/tele/LWT" ]
        Type string : Sonoffrf_recieveddata  "Sonoff RF Bridge: Received Data"        [ stateTopic="tasmota/sonoffrfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : Sonoffrf_recievedsync  "Sonoff RF Bridge: Received Sync"        [ stateTopic="tasmota/sonoffrfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : Sonoffrf_recievedlow   "Sonoff RF Bridge: Received Low"         [ stateTopic="tasmota/sonoffrfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : Sonoffrf_recievedhigh  "Sonoff RF Bridge: Received High"        [ stateTopic="tasmota/sonoffrfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : Sonoffrf_recievedrfkey "Sonoff RF Bridge: Received RfKey"       [ stateTopic="tasmota/sonoffrfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : Sonoffrf_button1       "Sonoff RF Bridge: Button 1"             [ stateTopic="tasmota/sonoffrfbridge/stat/RESULT", commandTopic="tasmota/sonoffrfbridge/cmd/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        //
        Type switch : Sonoffrf_button16      "Sonoff RF Bridge: Button 16"            [ stateTopic="tasmota/sonoffrfbridge/stat/RESULT", commandTopic="tasmota/sonoffrfbridge/cmd/RFKEY16", transformationPattern="JSONPATH:$.RfKey16" ]
        Type number : Sonoffrf_rssi          "Sonoff RF Bridge: WiFi Signal Strength" [ stateTopic="tasmota/sonoffrfbridge/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }	

So I would like to get rid of this error (but don’t know how) - AND … the next step would be to switch the ventilation via OH sitemap by using RfKey

You’ve linked that topic to a Switch, but the payload isn’t ON or OFF so it doesn’t fit.
This is what transformations are about.
You’re already using the JSONPATH transform to pick out your value, you could chain a second MAP transform to convert it to ON/OFF

I’m a bit lost.

Changed the Channel from

Type switch : Sonoffrf_button1       "Sonoff RF Bridge: Button 1"             [ stateTopic="tasmota/sonoffrfbridge/stat/RESULT", commandTopic="tasmota/sonoffrfbridge/cmd/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]

to

Type switch : Sonoffrf_button1       "Sonoff RF Bridge: Button 1"             [ stateTopic="tasmota/sonoffrfbridge/stat/RESULT", commandTopic="tasmota/sonoffrfbridge/cmd/RFKEY1", transformationPattern="JSONPATH:$.RfKey1",on="ON",off="OFF" ]

but with no effect.

Yep.
Not what I suggested to do.
Lots of posts here where JSONPATH and the on=/off= “instant transform” just don’t seem to work together. I have seen no-one make it work.
I suspect it does things in the wrong order, which would be crucial, and is beyond your control.

So you have to “roll your own” on/off transform with a MAP and chain it to the JSONPATH transform so they happen in the right order.

Ok, thanks. I’ll try it.

In the meantime I’ve managed to switch the ventilation via HTTP request.