Sonoff RF Bridge. Strategies for receiving data

Check and see if one byte differs from another of your 433Mhz sensors/switches. I find that occasionally I will get what seems like interference on my RF bridge. I will get spurious packets that differ in only one byte of my configured sensors, when I should have received the correct value. This lasts a while then stops, I am yet to work out the interference source.

Interestingā€¦

I have just started logging all my 433 signals so that I can try and work out when my sensors send a low battery signal and I have been noticing a lot of signals that look the same as I am expecting but varying by one byte. And not always the same byte so I am none the wiser as to if any are actual low battery signals.

But you are saying they might just be interference?

This is exactly what I see.

I doubt itā€™s interference from a 433 Mhz device though. I live remotely so itā€™s definitely not coming from another property and Iā€™m aware (hopefully) of all of my devices.

Hmmmā€¦ Iā€™ve seen also ā€œinterference-corrupted codesā€ on my RF bridge. Usually, just single byte (but not always last one) was ā€œcorruptedā€. Are you seeing completely random codes or they can be partially-matched with some known codes?

Also, some RF sensors (like door/window sensors, or wireless thermostats) emit additional RF codes, when ā€œbattery is nearly drainedā€. I guess in such case the prefix of RF signal should match the other (known) codesā€¦ just last byte would differā€¦ Maybe this is an issue?

Correct. It could be that as the codes are so similar though the battery codes from my devices end in F and thatā€™s not what Iā€™m seeing.

Whatā€™s also odd is how itā€™s not consistent. For the last 4 days Iā€™ve had no issues. I had assumed that it may be a faulty device so took it out of service, only to find another one exhibiting this behaviour.

Inconclusively, Iā€™ve noticed it to be worse in the sun and less problematic when itā€™s cold.

Hmmm, The battery capacity changes with temperature. So, maybe the RF signal strength varies depending on conditions.
https://www.thoughtco.com/why-batteries-discharge-quickly-cold-weather-607889

Thatā€™s certainly a possibility.

I have assumed that the devices just send out a ā€˜low batteryā€™ code once it drops to a pre determined level. Is it possible that it also sends out intermediate battery level codes too maybe, and that is what I am seeing?

The Chinese documents are a little scant on detail.

I seem to be getting random byte changes. It always appears to be just one byte but so far I have not seen a pattern with which byte is different.

I am now saving all ā€˜unknownā€™ RF codes to a file so I can have a good look when I have a lot of them.

Understatement!

Are you doing that automatically? Care to share?

When I receive an unknown code I publish it to a separate MQTT topic. Then I have an automation that writes them to a file.

#===========
#=== Notify
#===========
notify:
  - platform: file
    name: log_unknown_rf_codes
    filename: my-log_unknown_rf_codes.log


#================
#=== Automations
#================
automation:

  #===============================
  #=== Deal with unknown RF Codes
  #===============================
  - alias: Access Monitoring Unknown RF Codes
    trigger:
      - platform: mqtt
        topic: 433/Unknown_RF_Code

    condition:
      - condition: template
        value_template: >
          {% set known_codes = 'DC970A, DC970E, BLAH-BLAH' %}
          {{ trigger.payload[0:6] not in known_codes }}

      - service: notify.log_unknown_rf_codes
        data_template:
          message: >
            {{ as_timestamp(now()) | timestamp_custom('%d %b, %X') }} - {{ trigger.payload }}
1 Like

You can modify rfbridge_demux.py and have it take care of logging unknown codes to a file.

Replace the last few line of the python_script with the following:

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:
    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)

It publishes known codes to your preferred MQTT topic (433/<code>) and unknown codes are logged to the notify component you created (notify.log_unknown_rf_codes).

1 Like

Yes, but I still havenā€™t changed to use the python script. Itā€™s on my todo list!

As a favour :wink: can you show me the python to add so that I can write to the log only if an input_boolean is on?

This is the big drawback to using python scripts written by others. They are a lot harder to modify if you donā€™t have a good knowledge of python!

Whenever you get around to using the python_script, then Iā€™ll help you to modify it.

1 Like

Could I have some help with this please? I am working with Strategy 2.

My rfbridge_demux.py is this;

d = { '1A1092':['Mum needs help','ON','false'],
      '989301':['doorbell','ON','false'],
      '2D8B11':['Water leak','ON','false'],
      '125B0A':['Front door','ON','true']
      '125B0E':['Front door','OFF','true']
      'B91D0A':['Back door','ON','true']
      'B91D0E':['Back door','OFF','true']
      '1DE00A':['Study single door','ON','true']
      '1DE00E':['Study single door','OFF','true']
      'E801FE':['kitchen motion','ON','false']
      '3834B9':['My room door','ON','false']
      'EA1E99':['Brewery door','ON','false']
      'CC8DA2':['My Study light toggle','ON','true']
    }

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])}
  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)

My automation is this:

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

and my adjusted binary sensor is this:

    - platform: mqtt
      name: "Door bell"
      state_topic: 'home/doorbell'
      off_delay: 00:00:05
      device_class: motion

The old binary sensor config is this:

    - platform: mqtt
      name: "Door bell"
      state_topic: "bridge1/tele/RESULT"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: "989301"
      payload_off: "989301off"
      device_class: Motion
      qos: 1

Iā€™m starting with the door bell but if I subscribe to the topic home/doorbell there is no data received to the topic. I can see the payload arrive in the original topic as;

{
    "Time": "2019-12-29T20:06:51",
    "RfReceived": {
        "Sync": 9020,
        "Low": 290,
        "High": 880,
        "Data": "989301",
        "RfKey": "None"
    }
}

I have no log entries but none the lest - I expect it to be something simple as it so often is!
But for the life of me I cannot see it.

Oh and ā€˜A Happy New Year to Allā€™.

edit1: As a side note I am focusing on the doorbell as a tester. Do it simple and the rest will follow approach.

Hereā€™s what I currently have in my rfbridge_demux.py:

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)

Do I just need to change it to this, or are any other changes needed?

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])}
    hass.services.call('mqtt', 'publish', service_data, False)
  else:
    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)

Will it create the log file or do I need to create an empty one first?

Adding an input_boolean to activate/deactivate would be a welcome addition.

Based on a quick review, the python_script, automation, and binary_sensor all appear to be correct.

If payloads are published to bridge1/tele/RESULT but none are published to home/doorbell then it may be due to:

  1. The python script is not being executed because you may have overlooked to include python_script: in your configuration file (and then restarted Home Assistant).
  2. The automation is not turned on (check its state in Developer Tools > States).

Check the system logā€™s details for any messages related to the execution of the automation and python_script.

According to the File Sensorā€™s documentation, it will create the file if it doesnā€™t exist.

If you work with Klogg then Iā€™m sure the two of you will develop a means to do that. Hereā€™s something to get you both going:

x = hass.states.get('input_boolean.whatever')
if x is not None and x.state == "on":
  <do something>
2 Likes

Definitely set `python_script:ā€™ in the configuration file.
And;
The automation.rfbridge_demultiplexer is set to on.

not sure how to set the debug for this but any advice is appreciated.

Developer Tools > Logs then click Load Full Home Assistant Log.

Each time a payload is published to bridge1/tele/RESULT it should trigger automation.rfbridge_demultiplexer (and this will appear in the log) which then calls python_script.rfbridge_demux which, I believe, should also appear in the log.

If the log doesnā€™t report any of this activity ā€¦ something isnā€™t what it seems to be here.

I think then

I will investigate in the UK morning as its late here now. Thank you for your support.