Has anyone Managed to add a SONOFF RF Bridge and PIR sensor to their OH3 setup? and if so how? please

  • openHAB version:3*
    hi everyone, i am very new to OH and home automation in general, I have so far managed to get SONOFF basic switches to work for my lights, however when I have tried to be smart and add a SONOFF RF Bridge (which I have flashed with Tasmota 9.4) and PIR, I have unfortunately failed miserably and haven’t managed to get it working. my intention is to use the PIR to tell the lights to come on but so far i have fell at the first hurdle. any help and assistance would be greatly appreciated?

thanks in advance


Which PIR from Sonoff do you use?

Hi martin this is Kit I bought from amazon. i can see the sensor does talk to my bridge on the Tasmota console, unfortunately i just cant get them to work on OH3

Hi martin this is Kit I bought from amazon. i can see the sensor does talk to my bridge on the Tasmota console, unfortunately i just cant get them to work on OH3

Ok, it’s good that you see the PIR in the console of the bridge.
What messages do you get in the console when the PIR reacts?

Do you have a MQTT Server running?

Sorry for the late reply Martin, yes i have mosquitto running.
the following is what i see in the console:
19:40:11.424 MQT: tele/Tasmota_RFBridge/STATE = {“Time”:“2021-04-23T19:40:11”,“Uptime”:“0T09:55:10”,“UptimeSec”:35710,“Heap”:27,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“Wifi”:{“AP”:1,“SSId”:“VM3178242”,“BSSId”:“AC:F8:CC:0A:2B:93”,“Channel”:6,“RSSI”:86,“Signal”:-57,“LinkCount”:1,“Downtime”:“0T00:00:03”}}
19:41:02.734 MQT: tele/Tasmota_RFBridge/RESULT = {“Time”:“2021-04-23T19:41:02”,“RfReceived”:{“Sync”:12520,“Low”:440,“High”:1240,“Data”:“D84E3E”,“RfKey”:“None”}}

any help is greatly appreciated, once again many thanks

No problem

19:40:11.424 MQT: tele/Tasmota_RFBridge/STATE = {“Time”:“2021-04-23T19:40:11”,“Uptime”:“0T09:55:10”,“UptimeSec”:35710,“Heap”:27,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“Wifi”:{“AP”:1,“SSId”:“VM3178242”,“BSSId”:“AC:F8:CC:0A:2B:93”,“Channel”:6,“RSSI”:86,“Signal”:-57,“LinkCount”:1,“Downtime”:“0T00:00:03”}}

This is just the state of the bridge, a kind of heartbeat that the bridge is sending in a regular time frame.

19:41:02.734 MQT: tele/Tasmota_RFBridge/RESULT = {“Time”:“2021-04-23T19:41:02”,

This is the important part for decoding the PIR signal.
Sync, Low and High will be different, but always in a range that is nearby these values.
The Data part will always be the same, normally. That’s how you can identify the PIR.

Before I continue I need to know, if the PIR is sending a second signal after a while, when the area is clear again.
Means: if you activate the PIR and then nothing happens for x seconds, will the PIR send a second signal or not?

There are PIR’s that send just a signal when a motion is recognized and there are PIR’s that send a second signal when no motion was recognized after a certain time, when the area is ‘clear’.
If that is the case, then the data for sending ‘clear’ could be different.

Hi Martin apologies for such a late reply, i have checked and the pir i have only sends the one signal,

once again thank you so much for your help so far

Ok, that makes it more complex.
I assume you already configured a MQTT Thing in openhab. If not, you have to do so.
Here you can add a channel now, normally you choose an open/close contact here.
But the PIR sends only the “open” signal, so you need some more scripting and maybe some helper items.

Ok, let’s choose the open/close contact, then write this into the MQTT state topic:


This subscribes the channel to this MQTT topic.

Into the Custom On/Open Value write the Data part of the json:


Into the Incoming Value Transformations type this:


Now link the channel to an item of your choice (normally you choose create new one)

Now every time the PIR reacts to a motion the item gets the state open.

But it will stay open in your case because there is no second signal for “close”.
That means you will have to write a rule which sets up a timer to close the item after a while.
But if in this time the PIR is activated again you have to watch first, if there is already a timer running…
That’s what I mean with complex, you have to think about a logic algorythm that controls all eventualities that could happen.

The expire function could take of that, including “restarts” of timing.

An alternative approach would be to not have an Item at all, and configure the MQTT Thing channel to produce trigger events, but that is probably best left for use of confident rule authors.

Yes, a trigger would be good solution, too.
But I really have trouble with restarting or rescheduling the timer because the variable that stores the timer is gone after the rule was executed, so there is no way to test if there is already a timer running.

I simulated that and it’s no problem to switch a light when the trigger was activated and turn it off after x seconds or minutes. But then always the first activation will turn off the lights and when there still someone is in the room, the lights would turn off and on again, when the trigger is activated again.

rule "Testrule for MQTT Trigger"
    Channel "mqtt:topic:fb697192:mqtt_trigger_test" triggered "D84E3E"

    if (Sonoff_MiniR2_02_Switch.state == OFF) {


        timerTriggertest = createTimer(now.plusSeconds(30)) [|

                timerTriggertest = null

It could be a solution to set a timestamp in a helper item everytime the trigger was activated.
Then in the existing timer the last timestamp could be checked and the timer can be rescheduled if the timestamp is in a certain range, e.g. 30 secs in the past.

If the item solution is used instead of the trigger solution it’s easier to use a timestamp with just linking a second item in the channel to the timestamp when updated.

You seem to have missed the many examples of using timers with a so-called ‘global’ variable in files based DSL rules.

I read those, my mistake was that I forgot to declare my timer as a timer, I just wrote

var timerTriggertest = null

instead of

var Timer timerTriggertest = null

Now it works…

Thx for the advice, learned again some more

1 Like

Thankyou very much both, now to try and see if i can get mine to work

You’re welcome, let me show you what I have done to get this working, maybe not the most elegant way to solve this, but it works.

  • In my MQTT Thing I created a trigger named “mqtt_trigger_test” with MQTT Topic

and Incoming Value Transformation (advanced Settings)

  • I created an item type string (no thing, just the item) “triggerMQTTTest”. In this item I will store a timestamp when “mqtt_trigger_test” is triggered (later in rules)

  • I created a rule

var Timer timerTriggertest = null

rule "Testrule for MQTT Trigger"
    Channel "mqtt:topic:fb697192:mqtt_trigger_test" triggered "D84E3E"


    if (Sonoff_MiniR2_02_Switch.state == OFF) {


        timerTriggertest = createTimer(now.plusSeconds(30)) [|

                if ((triggerMQTTTest.state).toString.compareTo(now.minusSeconds(20).toString) > 0) {

                else {



This rule works this way:

  • Everytime the trigger event happens the item “triggerMQTTTest” will get an Update with the timestamp of the trigger event
  • The rule should just do s.th. when the lights are off, so you can switch them manual, too
  • If the lights are off, switch them on and start a timer (in my case 30 secs)
  • When the timer function is activated after 30 secs my rule first checks if there was a new trigger event after the initial trigger event. I do that with comparing the current time with the timestamp of the last trigger event. If it is less than 20 secs there was a trigger event at least 10 secs after the initial trigger event and I reschedule the timer to 30 secs more
  • If there was no more trigger event after the last timer update then the lights are switched off again.

Set your own times for 30 secs and 20 secs and it should work.

I had a few of those PIR but as you know they only send one state. I went with the HUE motion sensor by Phillips as it also has temperature and LUX in it.
The sonoff rf-bridge has the Tasmota firmware on it.

The way I do it is I have a rule (no text files) in the GUI.

I then don’t use the timer logic anymore and just use the expire in the metadata of the item and set the time to turn off there.

I use a lot of 433mhz devices and the logic is in the JavaScript in the THEN part of the screenshot. (This has all the remote controls RF codes in it)

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
// var rfinput = itemRegistry.getItem('RFBridgekitchen_Receiveddata').getState();
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");
var Duration = Java.type("java.time.Duration");
var TOPIC = null;
var PAYLOAD = null;

var rfinput = itemRegistry.getItem('RFBridgekitchen_Receiveddata').getState().toString();

switch(rfinput) {
  case '53D80A':
    var TOPIC = "jedwood/raw/frontdoor-sensor";
var PAYLOAD = "ON";
  logger.info('Front door opened');
//B button lounge curtain don't need to toggle this. Just send ON.
  case 'BC5098':
     events.sendCommand('Curtainlounge_Curtainlounge', 'ON');
       logger.info('Curtain lounge ON');

//If not blank then send the command
if (TOPIC) {
result = Exec.executeCommandLine(Duration.ofSeconds(5), "/usr/bin/mosquitto_pub","\-h","","\-t","" + TOPIC,"\-m","" + PAYLOAD);
//logger.info('The script ran the command '  + TOPIC);

I set the TOPIC and the PAYLOAD if I want to send via MQTT and if the TOPIC is NOT blank then it uses MQTT. I have that at the end of all the case statements.

The expire looks like this:

The rf bridge looks like this:


I have door sensors, doorbell, PIR and multiple 433mhz remote controls laying around the house that all use the RF-bridge. I can control divices by using remote control, web browser, the physical switch of the device or on the phone.

The above might work for you. I use it all the time and it works fine.