Sonoff RF Bridge. Strategies for receiving data

WOW. Thank you very much. I was hoping for a hint to point me in the right direction not a full blown solution.
Now to import and figure how it works. Thanks So much.

Hi, I’m using Hassbian and trying to use the option 2 using demux. The script is triggered correctly but I couldn’t see the mqtt published at the end:

hass.services.call(‘mqtt’, ‘publish’, service_data, False)

I’m trying to monitor using mosquitto_sub with the topic specified in the python_script but it doesn’t seem to be published. Anything that I should check?

Thanks.

How are you confirming the script is triggered?

I have logger.info inside the script which show the service_data content and this is shown in the log. Is there anything special need to be done to publish through mqtt? The mqtt from RF bridge is triggered according to the log and calling the script.

Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.components.automation] Executing RFbridge Demultiplexer
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.helpers.script] Script RFbridge Demultiplexer: Running script
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (MainThread) [homeassistant.helpers.script] Script RFbridge Demultiplexer: Executing step call service
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (SyncWorker_6) [homeassistant.components.python_script] Executing rfbridge_demux.py: {'payload': '0EF4E4'}
Aug 24 07:56:45 hassbian hass[524]: 2019-08-24 07:56:45 INFO (SyncWorker_6) [homeassistant.components.python_script.rfbridge_demux.py] Recv: {'topic': 'rfbridge/KeyFobB', 'payload': 'ON', 'qos': 0, 'retain': 'false'}

I’m trying to monitor using mosquito_sub with topic = rfbridge/*.

I believe it should be rfbridge/#

From HiveMQ’s MQTT Essentials:

Like the Thinking
but I did mine Differancely

I have this sensor

  - platform: mqtt
    name: "Last RF"
    state_topic: "tele/RF_Bridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    expire_after: 1
    qos: 1

which get reset after 1 sec
with a number of these around the house
https://www.ebay.com/itm/1-2-3-Way-433MHz-RF-Wireless-Remote-Control-Transmitter-Smart-Switch-Wall-Panel/233179974574?_trkparms=ispr%3D1&hash=item364a9c0bae:m:mtkiF2aBeQd_YyVlrU0RynA&enc=AQAEAAACIBPxNw%2BVj6nta7CKEs3N0qWWjcWnNpC%2FbZ3jaTp5bM1Q7syJjNtOk%2BnKndN638FQqVhVaa%2FnFN3qC%2BN0Ah9LAb94BpJumTnlygcbsiDyvvW03NX7fz6gD8qa%2B%2FGdJhfdMi%2Fi3a%2FZsK6VKeLuuKEme%2FuNqHui8Nq2KsycFnbIUbFjvRsiLaPEXn%2FJGFbiRg3jBQPVjACdSvaFVXF330xwa80TS3DmSdB3zYWKQPjHR0FXFEZFZheyoz%2BZwffVUMuJ03ISxvL7AGuKcYYklK98SVUQeREssUUsBLoCknNEaawDhij6IoCzHWn1wJorA46HNu%2Fsi%2B2GRkxELBUjWZabc7rDKDBNQwxvjBPmHtPu4Ie2sMl1XMHVQFReaZNTCfN2wOJtJDBGBzk8YtQEWv%2FRDn6jJLtgELSoBG%2FX4UnmKjMABlus3m%2B3QTpKRLbwKFUuQhK%2B0OK69WBaNihFYE5L27efk8p4DcbU9dP9eDmTRprhs5YkNaXWVR8gBWA2z1buaVbVLHY82J9f3xB6x%2BYRoN%2BwiOXmaGuAYPWaHY7atrZAK8unn22bK6p%2FtjfTXF%2FMxao54PEkDn%2FxQj3alDWyBkhlJZBr0gCvuBmjdwoNRZ4DwDX9i4HC4uXXv7nsGkQiRfNhMcr9LCVFk0keluH5KSn110P64pdU8k7bQEX0zqua5qgB96zlcRyG5K%2B1%2BRL6JYqv4JFIaHAmAP7kChePwqA%3D&checksum=233179974574baaa6bd6677c47b39ab17a6db05857ba

I find out its rf code then write the 1 automation to turn on/off toggle something

- id: His side Lamp
  alias: His side Lamp
  initial_state: 'on'
  trigger:
  - entity_id: sensor.last_rf
    platform: state
    to: '137854'
  condition: []
  action:
  - data:
      entity_id: light.his_side
    service: light.toggle
1 Like

Silly me, thanks for pointing it out. Yes, indeed, it does get triggered. Now to finish up my automation :slight_smile: Thanks again.

Hi @123 I’ve been using your rfbridge_demux for a while now and it works perfectly with the Sonoff PIR sensors I have around :slight_smile:
But recently I got one of those Digoo RF 433 remotes and I’ve been trying to get it to trigger a binary sensor (not sure if the right call) but by some reason I see it on the log and on the mosquitto mqtt but it does nothing on the HA side… wondering if it could be my eyes misisng out something?

This is my rfbridge_demux:

d = { '123456':['remotesos','ON','false'] # remote SOS option
    }

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])}
        logger.warning('<rfbridge_demux> Received RF command: {}'.format(p))
    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)

This is what I see on the mqtt side:

tele/sonoff-rf001/RESULT {"RfReceived":{"Sync":12430,"Low":420,"High":1210,"Data":"123456","RfKey":"None"}}
home/remotesos ON

This is my binary_sensor:

- platform: mqtt
  name: 'SOS'
  state_topic: '/home/remotesos'
  off_delay: 15
  device_class: safety

I’ve tried changing the device_classes but no joy at all :frowning:

ps: the ‘123456’ is a fake code just for the sake of the post, the real one has the real 433 code.

Any ideas?

Thanks for the help.

The python_script will publish to this topic:

home/remotesos

However, your binary_sensor’s state_topic is set to:

/home/remotesos

Remove the leading slash from the binary_sensor’s state_topic.

1 Like

:roll_eyes: #facepalm

OMG how did I not see that :confused:

Thank you very much

Thank you! This is the solution I’ve been looking for to make my configuration a whole lot more manageable.

I’m very averse to the verbose nature of Yaml and find in general, HASS’s configuration to be it’s biggest downside - this kind of approach completely changes my feelings about the platform, thank you! :slight_smile:

1 Like

Hi All

Trying to go convert to strategy 2 but getting this error in my HA log:

Error while executing automation automation.rfbridge_demultiplexer. Service not found for call_service at pos 1: Unable to find service python_script/rfbridge_demux

My first time configuring python scripts on the system so started from step one.

Anything specific I should look for?

Did you put python_script: in your configuration.yaml?

Thanks so much, @francisp. That was indeed my issue.

Thought I’d show my independent implementation of the ‘de-multiplexer’ completely using HA’s templates. I am able to take advantage of the fact that my door sensors all have their open/close code differ by only the last character (‘A’ for open, ‘E’ for close):

I like this.
One question though; what made you decide to raise an rf_signal_received event and then trigger a second automation based on it, rather than just have it all as one automation?

I have RF devices other than door sensors, and I like having the RF signals abstracted from the MQTT messages, when I write other RF-based automations. You could totally do it the way you’re suggesting. It’s just preference.

1 Like

Is there anything I can improve in my original post to make it less likely that others make the same mistake?

This is what it currently states:

To make this work, you have to configure Home Assistant to use the python_script component.

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

Can I suggest:

Add python_script: to your configuration.yaml file

Your suggestion is already present in the existing text (third paragraph in the second section). It’s the first one of three steps.

Or are you suggesting only the first step should be shown and the other two removed??