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
- Add
python_script:
to yourconfiguration.yaml
file. - Create the following sub-directory:
config/python_scripts
- 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']
}
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?
Hello Taras,
I finally got it working. The problem was just a comma in the python scripts code which messed up everything .Thank you for all your help.
At some point you suggested the Publish off automation. When i start home assistant the sensors state is already off. Do I need to use the automation?
Thank you again
Hello Ash,
I just deleted everything and followed Taras Solution 2. It seems that the problem was a missing comma in the python script which caused a problem in the sensors .
Now it is ok
Thank you
If the state is off
at startup then the suggested automation isn’t necessary.
The esphome firmware appears to be using the homeassistant events. Are those mqtt based?
Does anybody have any experience with it?
Typically the best choice is to use the native api for direct (bi-directional) communication with home assistant when using esphome (so no mqtt broker or any configuration/“strategies” like described in this post are actually needed)
I did, you can just trigger anything interacting with ha from the esphome device directly. I use this for virtually everything (including IR and RF).
Also someone (don’t find any link right now - sorry) actually “abused” the tags in ha (with it’s nice management)
Home Assistant has a dedicated panel that allows you to manage your tags. You can add names, automate or delete them
to handle all his IR or RF payloads/data.
In esphome the easiest way to make use of it is the tag-scanned-action
# In some trigger
on_...:
# Simple
- homeassistant.tag_scanned: some-tag
Just now saw that you were referring to the Home Assistant Events. From what I know that’s not possible to use them with mqtt but only by utilizing the native api (from esphome).