Sonoff RF Bridge. Strategies for receiving data

with what?

Latest Tasmota.

Important bit it is :wink:

Finally, I found time to change to use this and so far so good.
Except, I get an error every time I receive an unknown code if my logging boolean is turned on…

ERROR

Error executing script: '__import__'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 196, in execute
    exec(compiled.code, restricted_globals)
  File "rfbridge_demux.py", line 58, in <module>
KeyError: '__import__'

Line 58 is:

service_data = {'message':'{} - {}'.format(datetime.datetime.now().strftime("%d %b, %X"), p)}

PYTHON SCRIPT

if p is not None:
  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])}
    hass.services.call('mqtt', 'publish', service_data, False)
  else:
    x = hass.states.get('input_boolean.log_unknown_rf_codes')
    if x is not None and x.state == "on":
      # logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p))
      service_data = {'message':'{} - {}'.format(datetime.datetime.now().strftime("%d %b, %X"), p)}
      hass.services.call('notify', 'log_unknown_rf_codes', service_data, False)

Never mind, I changed it to publish the unknown code and then have an automation act on that.
That way I can easily also create a persistent notification too.

Well, I say never mind but it would be interesting to know why it didn’t work…

I believe strftime() is unavailable in python_script.

See this thread post:

Tomato-tomahto but I prefer checking for the existence of a key rather than falling to an exception for handling the “unknowns”. I dunno but that could be why node red doesn’t like it…

If I have 2 rf bridge how must mod the config?
the first : tele/sonoff_rf/RESULT
second: tele/sonoff_rf2/RESULT

You need to have an automation like this (I have 5 rf bridges):

- alias: 'rfbridge_demultiplexer'
  trigger:
  - platform: mqtt
    topic: tele/Garage_RF_Bridge/RESULT
  - platform: mqtt
    topic: tele/RF_bridge_west/RESULT
  - platform: mqtt
    topic: tele/RF_bridge_east/RESULT
  - platform: mqtt
    topic: tele/RF_bridge_stable/RESULT
  - platform: mqtt
    topic: tele/RF_bridge_1st_floor/RESULT
  action:
  - service: python_script.rfbridge_demux
    data_template:
      payload: '{{trigger.payload_json.RfReceived.Data}}'

Perfect, thank you!

edit: now received a lot of message like this: <rfbridge_demux> Received unknown RF command: 347343

That means exactly what it says, it received an unknown RF command: it received 347343 and couldn’t find it in the dictionary you defined.

Sorry to hijack this thread but I am considering purchasing a Sonoff RF Bridge and I am curious if this is still a recommended option for things like motion sensors and door / window switches.

No need to be sorry, just start a new topic. This one is dedicated to strategies for receiving multiplexed data, like from a Sonoff RF bridge (but applicable to any device that multiplexes data via one MQTT topic). If you want to discuss the pros and cons of the actual device, a new topic is preferable.

1 Like

Great. Excellent solution. Thanks

Hi, I tested your config and works well, thanks you
I don´t know how implement this with more than one sonoff rf bridge

Thanks!

To use more than one bridge you give them all the same topic in mqtt config.
The closest one will pick up the signal without duplication problems.
I have 3 set up like this with this solution since it was released and works well.

Hmm, I have 3 bridges as well but I have separate topics for each. I was concerned that the buttons I have located throughout the property would be detected as two pushes if I configured them your way. As most of them toggle something I expected that this would translate as on then off as two or more MQTT messages were received. Does that not happen?

I only use the bridge for sensors. and in my case it’s not a problem at all.
I suggest you try it.

You would think I would have more time to play with HA, stuck at home, but it just means 12 hr work days. Thanks for the suggestion, will try on the weekend.

My two bridges have different topics, but they use the same demux-script.