Sonoff RF Bridge. Strategies for receiving data

Mine are all black and have been in and working without attention for about 3 years.

Very occasionally, when adding a new device, I will look at the console and notice the odd code being received but it just gets ignored by the demux.

They are all running Tasmota 10.1.0.

The referenced “MQTT Button” seems to be a virtual button, intended for dashboard / UI. I cannot believe the button definitions in this howto are incorrect. I just need to know where to put the button code (if in configurqation.yaml - config error) and, how to specify them correctly. It baffles me how many people report success and yet, literally following this HowTo fails for me.

Removing the Button_X definitions gets me this:

2022-11-23 12:45:00.506 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on tele/sonoff-rfbridge-1/RESULT: b'{"Time":"2022-11-23T18:45:00","RfReceived":{"Sync":10400,"Low":340,"High":1030,"Data":"XXF161","RfKey":"None"}}'
2022-11-23 12:45:00.517 INFO (MainThread) [homeassistant.components.automation.rfbridge_demultiplexer] rfbridge_demultiplexer: Running automation actions
2022-11-23 12:45:00.518 INFO (MainThread) [homeassistant.components.automation.rfbridge_demultiplexer] rfbridge_demultiplexer: Executing step call service
2022-11-23 12:45:00.552 INFO (SyncWorker_2) [homeassistant.components.python_script] Executing rfbridge_demux.py: {'payload': 'XXF161'}
2022-11-23 12:45:00.553 INFO (SyncWorker_2) [homeassistant.components.python_script.rfbridge_demux.py] <rfbridge_demux> Received RF command: XXF161
2022-11-23 12:45:00.572 DEBUG (MainThread) [homeassistant.components.mqtt.client] Transmitting message on home/button_a: 'ON', mid: 52

So, at least I have home/button_x messages to use to control stuff. Clearly “more learning” required.

If by “How to” you mean the first post in this topic then you are mistaken.

The first post in this topic contains no information about configuring MQTT Buttons. The examples that it provides are for binary_sensors and they are not part of the rfbridge_demultiplexer automation; you have misinterpreted it.

Here’s an annotated screenshot of the information in the first post.

Yep; It is proper config of the binary sensor buttons that was baffling me: Where to put the button code? I think I need it for the “off_delay”, otherwise, once triggered, state will remain on from mqtt broker perspective (I think).

Looked into this further. It was MQTT Binary Sensor - Home Assistant that was required to “fix” this howto for buttons. As I suspected, HA evolution changed the required syntax (see link). Proper entries (in configuration.yaml) are:

# Pendant buttons via sonoff RF bridge
mqtt:
  binary_sensor:
    - name: 'Button_A'
      state_topic: 'home/button_a'
      off_delay: 1
    - name: 'Button_B'
      state_topic: 'home/button_b'
      off_delay: 1
    - name: 'Button_C'
      state_topic: 'home/button_c'
      off_delay: 1
    - name: 'Button_D'
      state_topic: 'home/button_d'
      off_delay: 1

Developer Tools / States now show buttons:

Not a big issue: until button pushed, state remains “unknown” - from startup. I have seen a few ways to address this.

Perhaps update this HowTo (buttons) to reflect current HA code?

There’s no such thing as “binary sensor buttons” in Home Assistant. Button and Binary Sensor are two completely different integrations:

  1. Binary Sensor
  2. Button

This is a “howto” about receiving multiplexed data, like the kind transmitted by a Sonoff RF Bridge (but not limited to it) . The examples contain the configuration of MQTT Binary Sensors (not buttons) as they were done when this topic was created 3.5 years ago.

A lot has changed in Home Assistant since then. Most recently, the configuration of MQTT-based entities, like sensor, binary_sensor, button, light, etc, are consolidated under an mqtt key. It’s left to the user to stay on top of changes. After all, the focus of this topic isn’t about configuring MQTT Binary Sensors, it’s about demultiplexing multiplexed data.

Even if I had updated the examples, with the latest style of MQTT Binary Sensor configuration, it would not have prevented the error you initially encountered because that was due to you misreading the instructions and mistakenly combining the rfbridge_demultiplexer automation with the binary_sensor configuration.

@Taras Thanks for your help. Don’t get me wrong, I was not criticizing. Demux is excellent. The net is full of obsolete, confusing info. I think making this HowTo current / complete is a good thing and, if / when I get around to implementing MQTT button (as opposed to binary sensor), will post code here.

Enhancement to Strategy 2

I have made a small change to allow the identification of codes that are a close match to known existing ones. Most cheap Chinese sensors aren’t documented and I never know if I have correctly identified the code for the battery warnings.

So here is my version that checks for the code having the same first or last 5 characters as an existing one.

p = str(data.get('payload'))
service_data = ''

if p in d.keys():
  service_data = {'topic':'433/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
else:
  for string in d:
    if string[:5] == p[:5] or string[-5:] == p[-5:]:
      matching_p = string
      service_data = {'topic':'433/Close_Match_Code', 'payload':'{}'.format(d[string][0]) + ' - ' + p, 'qos':0, 'retain':'false'}
      break
  if service_data == '':
    service_data = {'topic':'433/Unknown_RF_Code', 'payload':p, 'qos':0, 'retain':'false'}
hass.services.call('mqtt', 'publish', service_data, False)

I am no Python programmer so by all means, please make this code ‘nicer’.

I adapted this a bit. I was annoyed that on HA reboot the sensors say “Unknown”. I use an off_delay for my sensors (no explicit “off” RF signal). Fortunately my sensors continuously send updates (Govee Water Sensors) if they’re wet, so I was able to make some assumptions setting an initial state.

Thanks!!!
A brilliant solution to my HA restarts losing the state of the window/door sensors for my alarm!

Well, my battery guess was wrong. I had a bunch of dead batteries, and HA never showed them as bad. Any options?

I believe that this Sonoff RF Bridge Easy Setup with Tasmota Rules and the trigBoard - YouTube is a rather straightforward implementation that also deserves consideration. This abstraction allows you to have separate MQTT topics and values for each of the received RF codes, all managed by some rules on the RF Bridge.

The command publish2 inside the rules posts a “retained” value (“open” or “close”) to the sensor-specific custom topic. That way, even after restarting Home Assistant, it will use the previous value for each sensor that had a corresponding rule.

rule1 
ON RfReceived#Data=B9A30A DO publish2 stat/rf-bridge/kitchen_door open ENDON 
ON RfReceived#Data=B9A30E DO publish2 stat/rf-bridge/kitchen_door close ENDON

rule2 
ON RfReceived#Data=B33FEE DO publish2 stat/placeholderexample/back_door open ENDON 
ON RfReceived#Data=B33FEA DO publish2 stat/placeholderexample/back_door close ENDON

In Home Assistant configuration.yaml, you can then create binary sensors and subscribe to the sensor-specific topic that you chose in the rules above (on the RF Bridge). You can replace the topic “stat/rf-bridge/kitchen_door” with whatever you prefer, as long as you make sure that you use that same topic in both the rule on the RF bridge and the configuration.yaml!

mqtt:
  binary_sensor:
    - name: "Front door"
      state_topic: "stat/rf-bridge/kitchen_door"
      unique_id: "kitchen-door"
      payload_on: "open"
      payload_off: "close"
      device_class: door
      qos: 1
  binary_sensor:
    - name: "Back door"
      state_topic: "stat/placeholderexample/back_door"
      unique_id: "back-door"
      payload_on: "open"
      payload_off: "close"
      device_class: door
      qos: 1

Hi,
as far as I know, Tasmota doesn’t directly support user-configurable identifiers or aliases for individual connected sensors, through its web interface. The identification of individual sensors is usually based on the unique RF codes they transmit, and Tasmota doesn’t inherently provide a way to assign human-readable names or identifiers to each sensor.
So how did you manage to use the syntax stat/rf-bridge/kitchen_door in your rule?
I have a number of 433MHz door sensors and the only way I’ve found to distinguish between them is to parse the long hexadecimal string they send as part of the JSON object. This is utterly non-human friendly and I’d very much like to know how you managed to assign human readable names to RF devices?

Would it be possible for you to update your howto to use the latest HA features?

Regards

Like what exactly?

Not sure why but this isnt working for me.

This is in my config yaml.

binary_sensor:
    - platform: mqtt
      name: 'Living Room Door'
      state_topic: 'home/PatioDoor'
      device_class: door

My automation is

alias: rfbridge_demultiplexer
description: ""
trigger:
  - platform: mqtt
    topic: tele/RF_Bridge/RESULT
condition: []
action:
  - service: python_script.rfbridge_demux
    data_template:
      payload: "{{trigger.payload_json.RfReceived.Data}}"
mode: single

And this is the python script.

d = { '5A830A':['PatioDoor','ON','true'],
      '5A830E':['PatioDoor','OFF','true'],
      '2DEC73':['Living Room Window','ON','true'],
      '2DEC79':['Living Room Window','OFF','true']
      '0568D3':['Bedroom Window','ON','true'],
      '0568D9':['Bedroom Window','OFF','true']
      '06D933':['Downstairs Toilet Door','ON','true'],
      '06D939':['Downstairs Toilet Door','OFF','true']
      '05CDC3':['Fridge','ON','true'],
      '05CDC9':['Fridge','OFF','true']
      '55D60A':['Front Door','ON','true'],
      '55D60E':['Front Door','OFF','true']
      '5E600A':['Back Door','ON','true'],
      '5E600E':['Back Door','OFF','true']
    }

p = str(data.get('payload'))

if p is not None:
  if p in d.keys():
    service_data = {'topic':'home/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
  else:
    service_data = {'topic':'home/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
    logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p))
  hass.services.call('mqtt', 'publish', service_data, False)


Ive also tried the sensor in my config yaml file like this

mqtt:
  binary_sensor:
    - name: "Patio Door"
      state_topic: "home/PatioDoor"
      device_class: door

According to the example in the documentation for MQTT Binary Sensor, it should look like this (assuming you have all your MQTT entities defined in configuration.yaml):

mqtt:
  - binary_sensor:
      name: "Patio Door"
      state_topic: "home/PatioDoor"
      device_class: door

I had it setup like below. Ive modified the Patio Door config to use the python script, i can see the automation is triggering but nothing updates on the sensor.

mqtt:
  binary_sensor:
    - name: "Patio Door"
#      state_topic: "tele/RF_Bridge/RESULT"
      state_topic: "home/PatioDoor"
      device_class: door
#      value_template: '{{value_json.RfReceived.Data}}'
#      payload_on: '5A830A'
#      payload_off: '5A830E'
    - name: "Living Room Window"
      state_topic: "tele/RF_Bridge/RESULT"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: '2DEC73'
      payload_off: '2DEC79'
      device_class: window
      qos: 1
    - name: "Bedroom Window"
      state_topic: "tele/RF_Bridge/RESULT"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: '0568D3'
      payload_off: '0568D9'
      device_class: opening
      qos: 1
    - name: "Office Window"
      state_topic: "tele/RF_Bridge/RESULT"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: '052463'
      payload_off: '052469'
      device_class: opening
      qos: 1

The rest of my MQTT devices are in the UI but dont seem to be able to add that way

Use an MQTT client to confirm home/PatioDoor receives the payload published by the python_script.

If there’s no payload published to home/PatioDoor then it implies the python_script failed to find a match (in its dictionary) for the received code. In that case, it will publish it to the home/unknown topic.

Yeah you;re right, nothing coming through on that topic.

Anything you could see wrong in the python script or automation?

This is the output from the RFBridge, which im seeing working fine.

19:26:05 MQT: tele/RF_Bridge/RESULT = {"RfReceived":{"Sync":14000,"Low":470,"High":1390,"Data":"5A830A","RfKey":"None"}}
19:26:10 MQT: tele/RF_Bridge/RESULT = {"RfReceived":{"Sync":14100,"Low":470,"High":1390,"Data":"5A830E","RfKey":"None"}}

I should add nothing on the home/unknown topic either.