Sonoff RF Bridge. Strategies for receiving data

What version of HA is this for ? I tried strategy 1, but get already an error :

Configuration invalid
Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/configuration.yaml”, line 39, column 4

Home Assistant 0.95.4

The indentation on line 39 is incorrect. Add two more leading spaces so {% is vertically aligned with the other ones on lines 41 and 43.

Thanks. I will try it

Update, a couple of months and the python method is still working awesome.
My only problem is where I have a PIR and a door sensor in the same short hallway. They often combine their signals in the eyes of the rfBridge and I get a random interpretation of aa rfcode. Not much I can do about that. It just shows an an unknown code …

Do you mean that when your PIR and door sensor send a signal, it results in a random code generated by RF Brisge that is not recognised by the automations mentioned above?

Can some one give me some help trying to figure out how to convert the Option 2 automation to Node-Red. I have it running now, I am just starting to setup node red and I can’t figure out how to set this up.

- alias: 'rfbridge_demultiplexer'
  - platform: mqtt
    topic: tele/RF_Bridge/RESULT
  - service: python_script.rfbridge_demux
      payload: '{{trigger.payload_json.RfReceived.Data}}'

This is what I have for the flow but it doesn’t work.

[{"id":"6205a03f.c5367","type":"tab","label":"RE Bridge","disabled":false,"info":""},{"id":"f9f5f3f8.9ffef","type":"mqtt in","z":"6205a03f.c5367","name":"","topic":"RF_Bridge/tele/RESULT","qos":"2","datatype":"auto","broker":"f559e722.2fb4e8","x":380,"y":360,"wires":[["22f89b66.723024"]]},{"id":"22f89b66.723024","type":"api-call-service","z":"6205a03f.c5367","name":"","server":"d277d7e0.b4f288","version":1,"service_domain":"python_script","service":"rfbridge_demux","entityId":"","data":"'{{trigger.payload_json.RfReceived.Data}}'","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":360,"wires":[[]]},{"id":"f559e722.2fb4e8","type":"mqtt-broker","z":"","name":"HA","broker":"","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"d277d7e0.b4f288","type":"server","z":"","name":"Home Assistant"}]

If you’ve created a Node-Red flow, you may as well incorporate the python_script’s functionality into the flow. A single function node can replace the python_script. The only challenge is converting the script’s python code to the node’s Javascript.

After a little bit of experimentation, I’ve created a Node-Red function node that duplicates the functionality of the rfbridge_demultiplexer python_script.

The entire flow consists of four nodes:

From left to right:

  1. RF Bridge is an mqtt in node subscribed to tele/RF_Bridge/RESULT.
  2. json node converts the payload from a string to an object.
  3. Demultiplexer is a function node.
  4. Publish is an mqtt out node.

The function node contains the following code:

var d = { 'A1A':['sensor1','ON','true'],

var p = msg.payload.RfReceived.Data;

if (p in d) {
  msg.topic = "home/" + d[p][0];
  msg.payload = d[p][1];
  msg.retain = d[p][2];
  msg.qos = 0;
else {
  msg.topic = "home/unknown";
  msg.payload = p;
  msg.retain = "false";
  msg.qos = 0;

return msg;

Obviously you will need to customize the function’s dictionary for your specific needs (and possibly the subscribed topic for the RF Bridge node).

Here's the flow's listing.
        "id": "8998e275.d91a38",
        "type": "mqtt in",
        "z": "303845de.585f7a",
        "name": "RF Bridge",
        "topic": "tele/RF_Bridge/RESULT",
        "qos": "0",
        "broker": "a621bb5.8358248",
        "x": 100,
        "y": 120,
        "wires": [
        "id": "dfff2e32.4d5d38",
        "type": "function",
        "z": "303845de.585f7a",
        "name": "Demultiplexer",
        "func": "var d = { 'A1A':['sensor1','ON','true'],\n      'A2A':['sensor1','OFF','true'],\n      'B1B':['sensor2','ON','false'],\n      'C1C':['sensor3','ON','false']\n    };\n\nvar p = msg.payload.RfReceived.Data;\n\nif (p in d) {\n  msg.topic = \"home/\" + d[p][0];\n  msg.payload = d[p][1];\n  msg.retain = d[p][2];\n  msg.qos = 0;\n}\nelse {\n  msg.topic = \"home/unknown\";\n  msg.payload = p;\n  msg.retain = \"false\";\n  msg.qos = 0;\n}\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 460,
        "y": 120,
        "wires": [
        "id": "1716aba3.0e9de4",
        "type": "mqtt out",
        "z": "303845de.585f7a",
        "name": "Publish",
        "topic": "",
        "qos": "",
        "retain": "",
        "broker": "a621bb5.8358248",
        "x": 660,
        "y": 120,
        "wires": []
        "id": "f97adc78.2a1af8",
        "type": "json",
        "z": "303845de.585f7a",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 270,
        "y": 120,
        "wires": [
        "id": "a621bb5.8358248",
        "type": "mqtt-broker",
        "z": "",
        "name": "YOUR_MQTT_BROKER",
        "broker": "YOUR_MQTT_BROKER",
        "port": "1883",
        "clientid": "YOUR_CLIENT_ID",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": ""

Thx! Mark and read.

WOW. Thank you very much. I was hoping for a hint to point me in the right direction not a full blown solution.
Now to import and figure how it works. Thanks So much.

Hi, I’m using Hassbian and trying to use the option 2 using demux. The script is triggered correctly but I couldn’t see the mqtt published at the end:‘mqtt’, ‘publish’, service_data, False)

I’m trying to monitor using mosquitto_sub with the topic specified in the python_script but it doesn’t seem to be published. Anything that I should check?


How are you confirming the script is triggered?

I have inside the script which show the service_data content and this is shown in the log. Is there anything special need to be done to publish through mqtt? The mqtt from RF bridge is triggered according to the log and calling the script.

Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.components.automation] Executing RFbridge Demultiplexer
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.helpers.script] Script RFbridge Demultiplexer: Running script
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.helpers.script] Script RFbridge Demultiplexer: Executing step call service
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (SyncWorker_6) [homeassistant.components.python_script] Executing {'payload': '0EF4E4'}
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (SyncWorker_6) [] Recv: {'topic': 'rfbridge/KeyFobB', 'payload': 'ON', 'qos': 0, 'retain': 'false'}

I’m trying to monitor using mosquito_sub with topic = rfbridge/*.

I believe it should be rfbridge/#

From HiveMQ’s MQTT Essentials:

Like the Thinking
but I did mine Differancely

I have this sensor

  - platform: mqtt
    name: "Last RF"
    state_topic: "tele/RF_Bridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    expire_after: 1
    qos: 1

which get reset after 1 sec
with a number of these around the house

I find out its rf code then write the 1 automation to turn on/off toggle something

- id: His side Lamp
  alias: His side Lamp
  initial_state: 'on'
  - entity_id: sensor.last_rf
    platform: state
    to: '137854'
  condition: []
  - data:
      entity_id: light.his_side
    service: light.toggle
1 Like

Silly me, thanks for pointing it out. Yes, indeed, it does get triggered. Now to finish up my automation :slight_smile: Thanks again.

Hi @123 I’ve been using your rfbridge_demux for a while now and it works perfectly with the Sonoff PIR sensors I have around :slight_smile:
But recently I got one of those Digoo RF 433 remotes and I’ve been trying to get it to trigger a binary sensor (not sure if the right call) but by some reason I see it on the log and on the mosquitto mqtt but it does nothing on the HA side… wondering if it could be my eyes misisng out something?

This is my rfbridge_demux:

d = { '123456':['remotesos','ON','false'] # remote SOS option

p = 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])}
        logger.warning('<rfbridge_demux> Received RF command: {}'.format(p))
        service_data = {'topic':'home/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
        logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p))'mqtt', 'publish', service_data, False)

This is what I see on the mqtt side:

tele/sonoff-rf001/RESULT {"RfReceived":{"Sync":12430,"Low":420,"High":1210,"Data":"123456","RfKey":"None"}}
home/remotesos ON

This is my binary_sensor:

- platform: mqtt
  name: 'SOS'
  state_topic: '/home/remotesos'
  off_delay: 15
  device_class: safety

I’ve tried changing the device_classes but no joy at all :frowning:

ps: the ‘123456’ is a fake code just for the sake of the post, the real one has the real 433 code.

Any ideas?

Thanks for the help.

The python_script will publish to this topic:


However, your binary_sensor’s state_topic is set to:


Remove the leading slash from the binary_sensor’s state_topic.

1 Like

:roll_eyes: #facepalm

OMG how did I not see that :confused:

Thank you very much

Thank you! This is the solution I’ve been looking for to make my configuration a whole lot more manageable.

I’m very averse to the verbose nature of Yaml and find in general, HASS’s configuration to be it’s biggest downside - this kind of approach completely changes my feelings about the platform, thank you! :slight_smile:

1 Like