Integrating RF devices with sonoff rf bridge on Tasmota Firmware

Hello Home assistant enthousiast.

I have bought a sonofRF and flashed the tasmota firmware.

I also have an Sonof PIR, Keyfob and Doorsensor working on RF.

When i activate the detectors above I get the following logging in the tasmota console.

Sonoff PIR

19:12:40 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:12470,“Low”:420,“High”:1220,“Data”:“D2C71E”,“RfKey”:“None”}}
19:13:22 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:12380,“Low”:420,“High”:1220,“Data”:“D2C71E”,“RfKey”:“None”}}

Keyfob

ButtonA

19:18:01 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11080,“Low”:350,“High”:1080,“Data”:“BC7DE4”,“RfKey”:“None”}}
19:18:04 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11090,“Low”:350,“High”:1080,“Data”:“BC7DE4”,“RfKey”:“None”}}

ButtonB

19:18:36 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11130,“Low”:360,“High”:1060,“Data”:“BC7DE1”,“RfKey”:“None”}}
19:18:44 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11130,“Low”:360,“High”:1070,“Data”:“BC7DE1”,“RfKey”:“None”}}

ButtonC

19:19:25 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11090,“Low”:350,“High”:1080,“Data”:“BC7DE8”,“RfKey”:“None”}}
19:19:34 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11090,“Low”:350,“High”:1080,“Data”:“BC7DE8”,“RfKey”:“None”}}

ButtonD

19:20:03 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11130,“Low”:360,“High”:1070,“Data”:“BC7DE2”,“RfKey”:“None”}}
19:20:05 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:11120,“Low”:360,“High”:1070,“Data”:“BC7DE2”,“RfKey”:“None”}}

PIR

19:21:08 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:14190,“Low”:510,“High”:1470,“Data”:“946A21”,“RfKey”:“None”}}
19:21:23 MQT: tele/sonoffrf/RESULT = {“RfReceived”:{“Sync”:13820,“Low”:490,“High”:1430,“Data”:“946A21”,“RfKey”:“None”}}

I see that Sync,Low,High feedback differs but that the Data is consistent per detector.

Can anyone point me in the right direction to integrating these sensors in Home assistant ?

I am trying to build a basic alarm system with these.

3 Likes

Hi Im using the OpenMQTTGateway so not sure, but try this for your pir for instance:

binary_sensor:

  • platform: mqtt
    name: “pir5_hall”
    state_topic: “tele/sonoffrf/Data”
    payload_on: “946A21”
    device_class: motion

I would also like to know this.

The “data” is a nested JSON value

  • platform: mqtt
    name: “pir wherever”
    payload_on: “946A21”
    payload_off: “940923”
    sensor_class: motion
    state_topic: “tele/sonoffrf/RESULT”
    value_template: ‘{{ value_json.RfReceived.Data }}’

The payload_off is a random string that can be used to “reset” the sensor after its triggered. Its not sent to the PIR

bukurat, your code snip helped me get the first RfKey working in HA as a binary sensor. Currently the sensor shows up as a badge in hassio. A good start…
What it doesn’t do is reset to off at all. The RfKey TX can only send one code so it can never send ‘off’ or 0.
Can you suggest a fix for this without creating automations to do it ?

binary_sensor:
  - platform: mqtt
    name: "Test RF bridge rfkey 1"
    payload_on: "1"
    payload_off: "0"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
1 Like

I think you cannot do that without automation.I recently had a chat with a guy in a similar situation, here is his message
- action:

  • service: switch.toggle
    entity_id: switch.test_switch
    alias: AutoMQTTRF433_PIR_toggle
    condition:
  • condition: template
    value_template: ‘{{ trigger.payload_json.RfReceived.Data == “D34E0E” }}’
    id: '15132855315478’
    trigger:
  • platform: mqtt
    topic: ‘tele/RF433/RESULT’

Still struggling to get the test_switch off after x sec delay.

I suggested him to read this OR switch to Espurna - I have a working example, and it’s much neater :wink:

Yeah, there are many similar questions about resetting RF binary sensors all over Github and ha forums. I’m surprised only the RFXtrx binary sensor component seems to have foreseen this need and done it.

Actually I just came away from Espurna because while the GUI was real great, it’s not stable on the ESP. Many people are having issues with random ESP resets or related stuff. I did. It took a week before my Sonoff bridge shat itself at 2AM with false triggers into HA from the resets… Then it would do same hours or days later after power reboots etc. So far the same hardware is running fine on Tasmota (but not yet a week).

Like others I’ve been considering chucking out the whole RF bridge idea because of this binary sensor configuration stuff, and buying a Xiaomi hub and a batch of their Zigbee door, window and PIR sensors instead. Personally I’d rather find a neat solution to use the lower cost 433Mhz stuff, but I’m struggling to find time to keep pressing on learning more and more detail and not fitting up the house with the hardware.

Thanks for help BTW, if you do find a way to get the magic reset happening above please let us know.

I’m happy with my one so far, just a bit strange to see both RF bridge and SONOFF SV becoming unavailable and immediately coming back many times a day, randomly. Haven’t had time to check whether it affects functionality of my system.

Not sure you will have effortless setup there. But I understand your point about finding time for all this stuff.

Well, I can’t really help with Tasmota when I have Espurna.
They have a good wiki here.
I would have played with some MQTT-specific commands to see what you can get from it.

The pir only sends something when there is movement. Think of it as a pulse. If the movement continues it sends more pulses at a rate determined by the pir sensor. If it sent a continuous transmission for the duration of the movement it could stop other sensor signals being received. The RF bridge just converts these transmissions to JSON objects and packages them for transmission via MQTT. You don’t reset the pir as it doesn’t need resetting.
In a hard wired alarm panel the panel firmware would see the first voltage as movement detected and do whatever it’s been programmed to do. When the voltage returns to its normal state the panel may do nothing as the movement has been already noted, or it may note the duration for a log.

What you do with them in HA is up to you. I note the first one and reset the HA component to wait and see if there are any more pulses from that sensor.

“What you do with them in HA is up to you. I note the first one and reset the HA component to wait and see if there are any more pulses from that sensor.”

So, what do you do code wise to note the first MQTT result and then reset the binary sensor entity in HA, specifically for a RF PIR lets say, can you post the code snips for us to see exactly how you coded it ?

Thanks for your help.

I’ll post the snippet to tomorrow, it’s nearly midnight here and the development computer is off. The iPad isn’t the best tool to use.

This is what I am currently using. I have a Sonoff RF bridge that packs whatever it receives into a JSON object and sends it via MQTT. This is my binary_sensor

- platform: mqtt
  name: Hall Motion
  payload_on: "D3276E"
  payload_off: "D3276Eoff"
  sensor_class: motion
  state_topic: "sonoffbr/tele/RESULT"
  value_template: '{{ value_json.RfReceived.Data }}'

The payload_off is a made up value used to reset the sensor in the automation following. I’m not all that happy with this method, but as yet I haven’t found another way to change the state of the binary sensor.

#turn off hall motion sensor after 5 sec
- alias: Turn off hall motion
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.hall_motion
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: "sonoffbr/tele/RESULT"
      payload: "D3276Eoff"
      retain: "true"
3 Likes

is your RF bridge flashed with Tasmota?

I suspect it must be, like mine is now.

OK, I’ve taken your code snips and successfully used them tonight to create six automatically resetting binary sensors from the six RF devices !
So thank you very much bukurat for taking the time to give me a complete enough set of information based on my probably not very clear questions (at times).

I needed to change some small details to match my own environment, but that was not hard. My MQTT topics were slightly different to yours, and slightly different order also. I also decided to get the RF bridge (Tasmota FW based) to learn the six devices and use the ‘RfKey’ number payload instead of the ‘data’ payload. I think mainly so I can change an RF sensor and only need to relearn it in the RF bridge, the config and automation yaml will remain unchanged that way.

My new configuration.yaml code addition that’s working. Payload_on is the value sent from Sonoff bridge, payload_off is just an arbitrary (but meaningful to me) string, just like you explained with your random codes for that. Seems the RF bridge cares not if it’s Hex or ASCII.

binary_sensor:
  - platform: mqtt
    name: "RF bridge key 1"
    payload_on: "1"
    payload_off: "key1_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
  - platform: mqtt
    name: "RF bridge key 2"
    payload_on: "2"
    payload_off: "key2_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
  - platform: mqtt
    name: "RF bridge key 3"
    payload_on: "3"
    payload_off: "key3_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
  - platform: mqtt
    name: "RF bridge key 4"
    payload_on: "4"
    payload_off: "key4_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
  - platform: mqtt
    name: "RF bridge key 5"
    payload_on: "5"
    payload_off: "key5_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'
  - platform: mqtt
    name: "RF bridge key 6"
    payload_on: "6"
    payload_off: "key6_off"
    device_class: opening
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'

and the reset automations

- alias: Reset RF bridge RfKey1
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_1
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key1_off
      retain: 'true'
- alias: Reset RF bridge RfKey2
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_2
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key2_off
      retain: 'true'
- alias: Reset RF bridge RfKey3
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_3
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key3_off
      retain: 'true'
- alias: Reset RF bridge RfKey4
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_4
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key4_off
      retain: 'true'
- alias: Reset RF bridge RfKey5
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_5
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key5_off
      retain: 'true'
- alias: Reset RF bridge RfKey6
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.rf_bridge_key_6
    to: 'on'
    for:
      seconds: 5
  action:
    service: mqtt.publish
    data:
      topic: tele/sonoff_bridge/RESULT
      payload: key6_off
      retain: 'true'  
7 Likes

I’m glad it helped you. The bridge doesn’t do anything with the data apart from checking to see if its a command for it to do something. If its not, it just passes it to the RF side to transmit. The various devices listening on the same frequency only react if they hear their own address. PIRs and window sensors just send a “something happened near me” message to the world at large, the bridge hears it and, if it recognises it as something it has learnt

21/03/2018, 14:25:15node: ed292e4.396525
sonoffbr/tele/RESULT : msg.payload : string[75]
"{"RfReceived":{"Sync":6210,"Low":240,"High":580,"Data":"00000F","RfKey":1}}"

orif it can make sense of it, packages it in a JSON object and sends it to the MQTT broker as telemetry

21/03/2018, 14:27:50node: ed292e4.396525
sonoffbr/tele/RESULT : msg.payload : string[82]
"{"RfReceived":{"Sync":12540,"Low":420,"High":1210,"Data":"D3276E","RfKey":"None"}}"

Yes, this all Tasmota

I use node-red to watch the MQTT topics to see what is being sent by the bridge.

Cool. I’ve been using MQTT Snooper on an Android tablet.
I also tested commands back to the RF Bridge using that app, then I’ve used the tested command in an mqtt.publish service call from a time based automation. It locks my car at night if I’ve forgotten…

PS. Ultimately I hope the HA dev’s add a reset variable to the Binary Sensor Component, as it would be much easier for newbies to use.

Just when I thought I’d got an acceptable work around for integrating these 433Mhz RF binary sensors, I get this flood of log errors after any sensor fires now, after I updated HASS a couple of nights ago… FIH.
This was from tripping rfkey1 door sensor after clearing the log first.

No matching payload found for entity: RF bridge key 2 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
No matching payload found for entity: RF bridge key 6 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
No matching payload found for entity: RF bridge key 4 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
No matching payload found for entity: RF bridge key 5 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
No matching payload found for entity: RF bridge key 3 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
Error parsing value: ‘value_json’ is undefined (value: key1_off, template: {{ value_json.RfReceived.RfKey }})
8:59 PM helpers/template.py (ERROR)
No matching payload found for entity: RF bridge key 2 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
No matching payload found for entity: RF bridge key 6 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
No matching payload found for entity: RF bridge key 4 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
No matching payload found for entity: RF bridge key 5 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)
No matching payload found for entity: RF bridge key 3 with state_topic: tele/sonoff_bridge/RESULT
8:59 PM components/binary_sensor/mqtt.py (WARNING)