Sonoff RF Bridge. Strategies for receiving data

Hello, this code will not report the current state after a restart home assistant.

Then you’re the first to experience that problem in the three years this code has been available.

Having used this for close on 3 years, other than problems of my own making, this has been rock solid.

Are you sure this isn’t an MQTT problem?

A post was split to a new topic: Report as “good” instead of “unknown”

I have around 10 binary sensors which are RF Switches. I mostly use them to turn on lights and a couple of scenes. After the change in home assistant these sensors now show unknown state and my automations do not work any more. I don’t have any idea about python and scripts. i would appreciate your help top implement strategy 2 if possible. thank you in advance

All of the instructions for implementing strategy 2 are documented in the first post. Which part is unclear to you?

Have a read of this thread. You are not alone with this problem.

the false and true options is the confusing part for me. When do you use true and when false. Please note that all my binary sensors have no off code. They are single code rf buttons. Thank yoy for replying

Refer to the link posted by ashscott.

Thank you I will look it up

I feel very stupid. I can’t make it work. I really need some help if you can.

I followed these instruction

  1. Add python_script: to your configuration.yaml file.
  2. Create the following sub-directory: config/python_scripts
  3. Restart Home Assistant.

Create a new file in config/python_scripts called rfbridge_demux.py with the following contents:

and put 4 of my sensors in this file like this

d = { '05C2D4':['blindb1','off','true'],
      '0A89A8':['blindb2','off','true'],
      '0A89A1':['blindb3','off','true'],
      '0A89A4':['blindb4','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)

Then I created the bnary sensors as following

    - platform: mqtt
      name: 'Blind Button 1'
      state_topic: 'home/blindb1'
      device_class: door

    - platform: mqtt
      name: 'Blind Button 2'
      state_topic: 'home/blindb2'
      off_delay: 2
      device_class: door

    - platform: mqtt
      name: 'Blind Button 3'
      state_topic: 'home/blindb3'
      off_delay: 2
      device_class: door
      
    - platform: mqtt
      name: 'Blind Button 4'
      state_topic: 'home/blindb4'
      off_delay: 2
      device_class: door

And finally created the automation

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

I need all sensors to show state ‘off’ on home assistant start

Can you spot any mistake?

Thank you in advance

Newer version of HA does not check the state of a toggle sensor (sensor that sends only 1 signal code) and at boot it will be status “unknown”. Move the switch and signal is sent and the status is known. Lets say on.
So at boot of HA send desired status as I explained in the other thread ashscott also mentioned: Report as “good” instead of “unknown” for MQTT binary sensor
Set off_delay for the sensor so that the new ‘on’ signal is a change for the sensor.

Hope this helps.

Yes, it appears that you didn’t apply the advice suggested in ashscott’s link.

The challenge you are facing is not exclusive to the information presented in this topic (it’s affects all MQTT Binary Sensor entities, regardless if you use strategy 1, strategy 2, or neither strategy). That’s why you were referred to review the other topic.

However, if you don’t want read the other topic, I suggest you add the following automation. The moment off_delay sets a binary_sensor’s state to off, it will trigger the automation and publish OFF to the binary_sensor’s MQTT topic (as a retained message). On startup, Home Assistant will receive this value therefore the binary_sensor will not be unknown.

  alias: Publish off
  mode: queued
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.blind_button_1
        - binary_sensor.blind_button_2
        - binary_sensor.blind_button_3
        - binary_sensor.blind_button_4
      to: 'off'
  action:
    - service: mqtt.publish
      data:
        topic: 'home/blindb{{ trigger.to_state.object_id[-1:] }}'
        payload: 'OFF'
        retain: true

In addition, I don’t think this is correct:

d = { '05C2D4':['blindb1','off','true'],
      '0A89A8':['blindb2','off','true'],
      '0A89A1':['blindb3','off','true'],
      '0A89A4':['blindb4','off','true']
    }

When the RF code is received, it represents when the binary_sensor is on and not when it’s off. Change it to this:

d = { '05C2D4':['blindb1','on','true'],
      '0A89A8':['blindb2','on','true'],
      '0A89A1':['blindb3','on','true'],
      '0A89A4':['blindb4','on','true']
    }
1 Like

Good morning, Thank you very much. I will review the suggested link again. Maybe I didn’t understand the reason of suggestion. Sorry for that

thank you for the reply.

Unfortunately I can’t get it working. I deleted everything and followd instructions very carefully (for strategy 2). when I press the button on my remote RF Bridge receives the code but all my binary sensors remain to unknown in the developer States , and do not change to anything else. Any help is appreciated.

Please post all relevant code you have. Creation of sensors, python script, automations, scripts.
Maybe I can help.

My advice is to frist make it work for 1 sensor and then add more by copy and small changes.

Is what you are using now the same as what you posted earlier?

If it’s not, indicate what is different.

Hello, thank you for offering to help.

I finally managed to get the sensors to work.

Thank you again

And what was the solution?