Sonoff RF Bridge. Strategies for receiving data

@123 Thanks fresh brain and have noted a typo in my rfbridge_demultiplexer.py where I copied and pasted the last line of the dictionary to add further commands. This of course missed the trailing comma and then stopped the script.

All is working well now. Thank you for your time, effort and patience.

Iā€™m getting the following warnings

Log Details (WARNING)
Sun Dec 29 2019 21:38:28 GMT+0200 (Israel Standard Time)
No matching payload found for entity: doorbell with state topic: tele/sonoff_MSSR1/RESULT. Payload: , with value template Template("{% if value_json.RfReceived.Data == '8C81D2' %}
  {{'ON'}}
{% endif %}")

my PIR sensors are configured as the following:

############################################################
#
# PIR Sensors
#
############################################################
  - platform: mqtt
    name: Seans room motion sensor
    state_topic: "tele/sonoff_MSSR1/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == 'EC1A5E' %}
        {{'ON'}}
      {% endif %}
    off_delay: 5
    device_class: motion
    qos: 1
  - platform: mqtt
    name: Lounge motion sensor
    state_topic: "tele/sonoff_MSSR1/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == 'EB868E' %}
        {{'ON'}}
      {% endif %}
    off_delay: 5
    device_class: motion
    qos: 1

Help sorting thru this will be highly appreciated

First of all : you show an error message about your doorbell, but you show the configuration of your pir sensors.

Second : if you use strategy 1, make sure there is always a valid template.

Not :

  - platform: mqtt
    name: Lounge motion sensor
    state_topic: "tele/sonoff_MSSR1/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == 'EB868E' %}
        {{'ON'}}
      {% endif %}
    off_delay: 5
    device_class: motion
    qos: 1

But :

- platform: mqtt
    name: Lounge motion sensor
    state_topic: "tele/sonoff_MSSR1/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == 'EB868E' %}
        {{'ON'}}
      {%else}
       {{states('binary_sensor.lounge_motion_sensor') | upper}}
      {% endif %}
    off_delay: 5
    device_class: motion
    qos: 1

Thank you @francisp, seemed to have cleaned the log warnings.

For the benefit of the orders the correct code suggested above is missing a '%" at the {%else}.

As a general rule of thumb, can someone comment on how many sensors typically start to degrade performance?

Sorry for the typo.

Thank you.

Thanks for sharing. I modified the demux approach a bit to work with node-red and my particular setup:


(Iā€™m using a Python function node instead of JavaScript)

codes = {
    'bridge1_codes' : {
        'xxxxxx':['backdoor','ON'],
        'xxxxxx':['backdoor','OFF']
    },
    'bridge2_codes' : {
        'xxxxxx':['garagedoor','OFF'],
        'xxxxxx':['garagedoor','ON']
    }
}
try:
    tmp = msg['topic'].split('/')[1]
    d = codes['{}_codes'.format(tmp)]
except:
    d = None
if d is not None:
    try:
        data = msg['payload']['RfReceived']['Data']
    except:
        data = None
    msg = {}
    msg['payload'] = None
    if data is not None:
        if data in d.keys():
            msg['topic'] = 'hass/{}/status'.format(d[data][0])
            msg['payload'] = d[data][1]
    if msg['payload'] is not None:
        return msg

I have multiple rf bridges in my house with 6 door/window sensors, Some single buttons and remotes for my alarm. I used to run tasmota but last week I have converted all the bridges to esphome. It is MUCH faster than tasmota. Also the range seems to be a lot better. No mqtt traffic anymore but straight into home assistant via the native esphome api. My log was also flooded with payload warnings but that problem is also fixed now.

Can someone explain how thatā€™s possible? Is the receiverā€™s gain adjustable?

Probably indicative of configuration problems requiring correction. It wasnā€™t running optimally so any performance comparisons with esphome are rendered moot.

Well, in general esphome is known for its performance and faster than Tasmota.
My configuration was correct, these logs are warnings, no errors. It was working rock solid for months, but simply not as fast as esphome. I can recommend it to everyone. Not only for the rf bridges but also for other devices. As far as the gain settings, Iā€™m not sure you can. You can set the tolerance and use filters. This can help a lot in enhancing the stability of the signal/range

I too have just dipped my toe in with ESPHome and the RF Bridge. The response is definitely quicker. Iā€™ve not made any attempt, as yet, to test range though.

Wether the response time is because itā€™s not going through the MQTT server I canā€™t determine.

As mentioned in my previous posts, Iā€™m using 5 RF Bridges and for me the demux option works great as any of them can pick up the signal from my sensors and I only get one message into home assistant. My reliability has increased as a result.

What Iā€™d like to try next is using 5 ESPHome RF Bridges in the same way but my python skills arenā€™t yet up to that.

Following the successful test of the ESPHome version, Iā€™ll buy another 4 RF bridges and see if I can run them side by side to see what the real differences are.

And if anyone can help me work up a demux for them itā€™d be a great help.

As each sensor is defined on the RF Bridge itā€™ll certainly eliminate rogue codes that I, and others, have been experiencing.

1 Like

i think the response is quicker because the data is going straight into Home Assistant via the native ESPHome API and indeed, not via MQTT.
Before i did the conversion to ESPHome i needed 4 bridges in total, now i need 3, because there are no misfires anymore.
If you want to expand your range via multiple bridges, you could simply try to end your automation with a automation.turn_off a delay of a couple of seconds, and then a automation.turn_on. If you do so, the first message will trigger the automation and turns it off immediately so the other ā€œtriggersā€ will not result in multiple automation runs. With Tasmota i was not aware of the demux option, so i simply subscribed all my bridges to the same topic, and used the automations as described above. Worked like a charm!

Excellent. Iā€™ll give that a try.

If you make hardware mods and switch to ESPhome can you still switch back to tasmota? Or do the hardware mods not allow this?

I donā€™t think you can. You can switch to openmqttgateway after the mod. I use my rf bridges with openmqttgateway.

How exactly did you do that? I can see nothing about Sonoff RF Bridge on the ESPHome website.
Iā€™m using my RF Bridge with OMG and wonder if there are any benefits of switching to ESPHome (have some Wemos D1 mini with ESPHome as remote sensors and hoping to convert my Sonoff Basic to ESPHome, too).

Have a watch of this. It tells you pretty much all you need to know.

1 Like

I am trying this python script but fail to provide the needed JSON to Python Dict transformation. In my setup the ā€œpayloadā€ is always transfered as string to the python script:
My automation:

- id: 'rf_demux'
  alias: demux result
  description: 'decode the RF Bridfe /result messages'
  trigger:
  - platform: mqtt
    topic: sonoff/stat/RESULT
  action:
  - service: python_script.demux_result
    data_template:
      payload: '{{ trigger.payload_json }}'

Because m is a string in the python script any operation with dictionaries fails:

m= data.get('payload')

for k in m.keys():
  logger.info("Received keys = %s", k)

All parameter values are passed as strings. Normally the solution would be to convert the string using pythonā€™s json.loads but that is unavailable in python_script. To make it available, you would need to import json but python_script does not allow importing modules.

Someone else encountered the same hurdle and there was no solution to convert the string to a dict:

Thanks for this negative answer which at least saves me hours of useless effortsā€¦ actually I would have tried exactly that. :frowning_face:
With Python scripts its even worse: you cannot do simple slicing like a[:4]. It appears to be a naked installation without even the basic modules. I am surprised as one argument for me to try HomeAssisstant was the underlying Python framework.