Thanks!!!
A brilliant solution to my HA restarts losing the state of the window/door sensors for my alarm!
Well, my battery guess was wrong. I had a bunch of dead batteries, and HA never showed them as bad. Any options?
I believe that this Sonoff RF Bridge Easy Setup with Tasmota Rules and the trigBoard - YouTube is a rather straightforward implementation that also deserves consideration. This abstraction allows you to have separate MQTT topics and values for each of the received RF codes, all managed by some rules on the RF Bridge.
The command publish2
inside the rules posts a “retained” value (“open” or “close”) to the sensor-specific custom topic. That way, even after restarting Home Assistant, it will use the previous value for each sensor that had a corresponding rule.
rule1
ON RfReceived#Data=B9A30A DO publish2 stat/rf-bridge/kitchen_door open ENDON
ON RfReceived#Data=B9A30E DO publish2 stat/rf-bridge/kitchen_door close ENDON
rule2
ON RfReceived#Data=B33FEE DO publish2 stat/placeholderexample/back_door open ENDON
ON RfReceived#Data=B33FEA DO publish2 stat/placeholderexample/back_door close ENDON
In Home Assistant configuration.yaml, you can then create binary sensors and subscribe to the sensor-specific topic that you chose in the rules above (on the RF Bridge). You can replace the topic “stat/rf-bridge/kitchen_door” with whatever you prefer, as long as you make sure that you use that same topic in both the rule on the RF bridge and the configuration.yaml!
mqtt:
binary_sensor:
- name: "Front door"
state_topic: "stat/rf-bridge/kitchen_door"
unique_id: "kitchen-door"
payload_on: "open"
payload_off: "close"
device_class: door
qos: 1
binary_sensor:
- name: "Back door"
state_topic: "stat/placeholderexample/back_door"
unique_id: "back-door"
payload_on: "open"
payload_off: "close"
device_class: door
qos: 1
Hi,
as far as I know, Tasmota doesn’t directly support user-configurable identifiers or aliases for individual connected sensors, through its web interface. The identification of individual sensors is usually based on the unique RF codes they transmit, and Tasmota doesn’t inherently provide a way to assign human-readable names or identifiers to each sensor.
So how did you manage to use the syntax stat/rf-bridge/kitchen_door
in your rule?
I have a number of 433MHz door sensors and the only way I’ve found to distinguish between them is to parse the long hexadecimal string they send as part of the JSON object. This is utterly non-human friendly and I’d very much like to know how you managed to assign human readable names to RF devices?
Would it be possible for you to update your howto to use the latest HA features?
Regards
Like what exactly?
Not sure why but this isnt working for me.
This is in my config yaml.
binary_sensor:
- platform: mqtt
name: 'Living Room Door'
state_topic: 'home/PatioDoor'
device_class: door
My automation is
alias: rfbridge_demultiplexer
description: ""
trigger:
- platform: mqtt
topic: tele/RF_Bridge/RESULT
condition: []
action:
- service: python_script.rfbridge_demux
data_template:
payload: "{{trigger.payload_json.RfReceived.Data}}"
mode: single
And this is the python script.
d = { '5A830A':['PatioDoor','ON','true'],
'5A830E':['PatioDoor','OFF','true'],
'2DEC73':['Living Room Window','ON','true'],
'2DEC79':['Living Room Window','OFF','true']
'0568D3':['Bedroom Window','ON','true'],
'0568D9':['Bedroom Window','OFF','true']
'06D933':['Downstairs Toilet Door','ON','true'],
'06D939':['Downstairs Toilet Door','OFF','true']
'05CDC3':['Fridge','ON','true'],
'05CDC9':['Fridge','OFF','true']
'55D60A':['Front Door','ON','true'],
'55D60E':['Front Door','OFF','true']
'5E600A':['Back Door','ON','true'],
'5E600E':['Back Door','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)
Ive also tried the sensor in my config yaml file like this
mqtt:
binary_sensor:
- name: "Patio Door"
state_topic: "home/PatioDoor"
device_class: door
According to the example in the documentation for MQTT Binary Sensor, it should look like this (assuming you have all your MQTT entities defined in configuration.yaml
):
mqtt:
- binary_sensor:
name: "Patio Door"
state_topic: "home/PatioDoor"
device_class: door
I had it setup like below. Ive modified the Patio Door config to use the python script, i can see the automation is triggering but nothing updates on the sensor.
mqtt:
binary_sensor:
- name: "Patio Door"
# state_topic: "tele/RF_Bridge/RESULT"
state_topic: "home/PatioDoor"
device_class: door
# value_template: '{{value_json.RfReceived.Data}}'
# payload_on: '5A830A'
# payload_off: '5A830E'
- name: "Living Room Window"
state_topic: "tele/RF_Bridge/RESULT"
value_template: '{{value_json.RfReceived.Data}}'
payload_on: '2DEC73'
payload_off: '2DEC79'
device_class: window
qos: 1
- name: "Bedroom Window"
state_topic: "tele/RF_Bridge/RESULT"
value_template: '{{value_json.RfReceived.Data}}'
payload_on: '0568D3'
payload_off: '0568D9'
device_class: opening
qos: 1
- name: "Office Window"
state_topic: "tele/RF_Bridge/RESULT"
value_template: '{{value_json.RfReceived.Data}}'
payload_on: '052463'
payload_off: '052469'
device_class: opening
qos: 1
The rest of my MQTT devices are in the UI but dont seem to be able to add that way
Use an MQTT client to confirm home/PatioDoor
receives the payload published by the python_script.
If there’s no payload published to home/PatioDoor
then it implies the python_script failed to find a match (in its dictionary) for the received code. In that case, it will publish it to the home/unknown
topic.
Yeah you;re right, nothing coming through on that topic.
Anything you could see wrong in the python script or automation?
This is the output from the RFBridge, which im seeing working fine.
19:26:05 MQT: tele/RF_Bridge/RESULT = {"RfReceived":{"Sync":14000,"Low":470,"High":1390,"Data":"5A830A","RfKey":"None"}}
19:26:10 MQT: tele/RF_Bridge/RESULT = {"RfReceived":{"Sync":14100,"Low":470,"High":1390,"Data":"5A830E","RfKey":"None"}}
I should add nothing on the home/unknown topic either.
I get this error if i try to manually run that action, not sure if that due to not having any data to parse or if there is an issue with this action.
I looked at the automation trace to see what happened with the script.
Executed: November 23, 2023 at 6:33:40 PM
Result:
params:
domain: python_script
service: rfbridge_demux
service_data:
payload: 5A830A
target: {}
running_script: true
Looks like its pulling the code which i have put in the script dictionary so i dont know why that isnt then sending out the device or error.
Fixed the issue! I had missed some commas in the script between each of the devices.
Oops, thanks for the help @123
- And maybe adding a set every Topic to OFF with a trigger “When Home Assistant Restart”
- Or even better an mqtt Auto Off value for those devices with no dual binary state so we can Finally put MQTTs to retain!?
I like this approch… Because I do not really know Python Stuff
thank you so much! was able to tweak the script a little to update some “last changed” topics too!
so now my leak sensors mimic the govee app + more - showing when things last happened, etc.
Thanks a lot for this script!
I can see the automation triggered with a motion sensor, but the mqtt binary sensor does not change its value.
Here is my demux script…
d = { '8B4F0A':['Sensore1','ON','true'],
'8B4F0E':['Sensore1','OFF','true'],
....many other sensors....
'951056':['Sensore movimento giroscale','ON','false']
}
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)
SONOFF trigger:
HASS automation:
MQTT binary sensor states:
EMQX Topic monitor:
What am I missing?
Thanks a lot
Andrea
Hello.
The payload declared in the script does not match the payload emitted by the sensor. The codes are not the same.
Codes not registered in the script are published in this topic:
‘topic’:‘home/unknown’
I don’t know why the sensor gives you the registered code preceded by a “0x”.
Thank you, maybe after an update it started to send 0x…
Anyway, I didn’t find any message in home/unknown topic.
I have tried to change sensors codes, let’s see if something changes.
So I used this topic a few years ago to get my sonoff rf bridge working. It continues to work well. Recently I received a new v2 of the bridge (a white one). I have managed to put esphome on this device and I am wondering if anyone has tips for using a similar method to get status of my sensors using esphome with a python script to publish to mqtt, similarly to what I am doing now? I am receiving data but the data is not being properly passed through the python if statement.
I currently have this python script…
# New ESPHome RF Bridge
# White Unit
# http://192.168.0.159/
# Add the sensor below then update the binary sensor yaml file here
# /home/mele/homeassistant/_mqtt/b_sensor
d = {
'E3E20A':['sensor8','ON','true'],
'E3E20E':['sensor8','OFF','true'],
'E3E206':['sensor8b','ON','false'],
'0DCF0A':['sensor9','ON','true'],
'0DCF0E':['sensor9','OFF','true'],
'0DCF06':['sensor9b','ON','false']
}
# Create p variable of entire payload received
# p = str(msg['payload'])
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':'true'}
logger.info('RF-Bridge Publishing: ' + str(service_data))
else:
service_data = {'topic':'home/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
rf_command = str(p)[0:2]
if rf_command != "00":
logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p))
hass.services.call('mqtt', 'publish', service_data, False)
This Automation…
alias: ESPHome RFBridge
description: ""
trigger:
- platform: event
event_type: esphome.rf_code_received
condition: []
action:
- data_template:
payload: "{{ trigger.event }}"
action: python_script.esphome_rfbridge
enabled: true
mode: single
And these MQTT Sensors…
#########################
# ESPHome RF Bridge White
#########################
- name: "Bedroom Window"
state_topic: 'home/sensor8'
device_class: door
unique_id: E3E20A
qos: 1
- name: "Bedroom Window Low Battery"
state_topic: 'home/sensor8b'
device_class: battery
unique_id: E3E206
qos: 1
- name: "Bathroom Window"
state_topic: 'home/sensor9'
device_class: door
unique_id: 0DCF0A
qos: 1
- name: "Bathroom Window Low Battery"
state_topic: 'home/sensor9b'
device_class: battery
unique_id: 0DCF06
qos: 1