Sonoff RF Bridge. Strategies for receiving data

I’ve been pondering this too. I am not confident things will work as we would like in this case and furthermore I don’t believe HA is responsive enough for it to even need to be (all that) close to ‘the exact same time’.

But I agree with @123, that has nothing to do with these solutions.

I don’t really see a way to handle this situation that is anything other than complex.

Hi!

Nice tutorial, it had help me a lot.

But how can I use the secrets.yaml file contents within the second strategy?

Thanks.

What in the second strategy do you wish to store in secrets.yaml?

I need to store some hidden and personal RF codes, as sharing my config would reveal some of the security RF keys.

Thanks.

The second strategy stores the RF codes in a python_script. As a consequence, you can’t use the convention supported by configuration.yaml where you can simply write !secret rf_code_1 and it will be automatically retrieved from secrets.yaml.

You would have to create additional python code to retrieve all your RF codes stored in a separate file that you don’t share with others.

You can’t use the words ‘secure’ and ‘secret’ when describing RF 433MHz. All codes are transmitted unencrypted and it only takes someone with another RF Bridge to detect them all. However, I do understand your request. For example, if you wanted to backup the python_script to GitHub, it would reveal all of your RF codes. Unfortunately, this is a current limitation of how the python_script is currently implemented (but can be enhanced by you to meet your requirements).

1 Like

Excellent implementation using the python script - got it up and running in no time! I was using rules in Tasmota on the RF Bridge, but this is much easier to add additional devices (once set up).

Thanks!

It feels so good to have a clean log. This solution should be implemented in the official docs.

1 Like

Thank you for such a great solution to have a clean log.
I just tried setting up the Demultiplexer method but i can’t seem to get it to work and i was wondering if you could point out to what i’m doing wrong.

Here’s the payload produced by the RF bridge

Here are some of my sensor configurations
- platform: mqtt
name: “Garage Door”
state_topic: ‘home/Garage Door’
device_class: garage_door
qos: 1
-platform: mqtt
name: “Crawl Space Door”
state_topic: ‘home/Crawl Space Door’
device_class: door
qos: 1

This is the error i get in HA log
image

Thanks in advance for your help!

Please post the contents of your python_script.

This is the Python script

d = { '2B470A':['Front Door','ON','true'],
  '2B470E':['Front Door','OFF','true'],
  '2B520A':['Basement Door','ON','false'],
  '2B520E':['Basement Door','OFF','false'],
  '2C630A':['Kitchen Door','ON','false'],
  '2C630E':['Kitchen Door','OFF','false'],
  '2C8B0A':['Garage Side Door','ON','false'],
  '2C8B0E':['Garage Side Door','OFF','false'],
  '2EC50A':['Guest Room Left Window','ON','false'],
  '2EC50E':['Guest Room Left Window','OFF','false'],
  '2D610A':['Guest Room Middle Window','ON','false'],
  '2D610E':['Guest Room Middle Window','OFF','false'],
  '2C6D0A':['Guest Room Right Window','ON','false'],
  '2C6D0E':['Guest Room Right Window','OFF','false'],
  '2FA00A':['Living Room Left Window','ON','false'],
  '2FA00E':['Living Room Left Window','OFF','false'],
  '2B870A':['Living Room Right Window','ON','false'],
  '2B870E':['Living Room Right Window','OFF','false'],
  '2F850A':['Guest Bedroom Window','ON','false'],
  '2F850E':['Guest Bedroom Window','OFF','false'],
  'D58911':['Basement Flood Sensor','ON','false'],
  '34270A':['Garage Door','ON','false'],
  '34270E':['Garage Door','OFF','false'],
  '31370A':['Crawl Space Door','ON','false'],
  '31370E':['Crawl Space Door','OFF','false'],
  '30120A':['Mail Box','ON','false'],
  '30120E':['Mail Box','OFF','false']
}
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§, ‘qos’:0, ‘retain’:‘false’}
logger.warning(’<rfbridge_demux> Received unknown RF command: {}’.format§)
hass.services.call(‘mqtt’, ‘publish’, service_data, False)

Why do you have this character § here?
Received unknown RF command: {}'.format§)

this must have been when i pasted the code on here. Here’s a screen shot instead.

1 Like

Show me a screenshot of your rfbridge_demultiplexer.

It should look like this:

- 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}}'

The clue may be in the Log Warning message. The error message shows the literal template {{trigger.payload_json.RfReceived.Data}} as opposed to the result produced by the template.


EDIT
Here’s the result of the python_script receiving an unknown payload:

Thu May 16 2019 12:04:14 GMT-0400 (Eastern Daylight Time)

<rfbridge_demux> Received unknown RF command: 351FD1

Notice how the error message reports the unknown payload 351FD1 as opposed to the literal template {{trigger.payload_json.RfReceived.Data}}.

here’s a screen shot of my automation

image

Given all the information you have provided, all of the code appears to be correct. Nevertheless the <rf_demux> error message is displaying the literal template as opposed to the template’s result.

I can’t duplicate the error you are seeing. Can you provide a copy of the JSON data that causes this error?

Of course, do you mean the JSON data from my Rfbridge?

Yes, it should be similar to this example:

{"RfReceived":{"Sync":7740,"Low":250,"High":720,"Data":"051FD1","RfKey":"None"}}

I’m sorry it was in my first post.
Here it is

Both 2B520A and 2B520E are listed in the python_script’s dictionary (named d) and represent the ON and OFF states of Basement Door.

That means the python_script should have found those codes in its dictionary.
It only prints an error message if it fails to find the code in its dictionary.

if p in d.keys():
  service_data = ... etc ...
else:
  service_data = ... etc ...
  logger.warning('<rfbridge_demux> ... etc ...

Based on the everything you’ve provided, there’s no logical explanation for how the script can fail to find the code in its dictionary and then proceed to generate an error message that replaces the received code with the actual template.

I have no idea what kind of conditions can lead to this unusual result. As a consequence, I don’t know how to reproduce your result.

Out of curiosity, which version of Home Assistant are you using?

I reviewed the information you provided more closely and found the error … and it’s so simple.

There’s a mistake in your rfbridge_demultiplexer. Use data_template: not data:

It was never passing the RF code to the python_script. It was passing the literal template to it.

1 Like