I am using door rf sensor with sonoff rf bridge tasmota by creating a binary sensor for on/off by receiving on and off signal from sensor.
Recently hassos updated so that after system restart the door sensor value becomes unknow instead of on or off like in previous version. Is there any way for the system to remember the last value before restarting the system?
This is an example binary sensor code.
The only way that I can think to reliably do it is to create an input_boolean that stores the current state via an automation and that will survive restarts.
Can you set the retained flag on the published mqtt messages (i.e. from the rf bridge tasmota)?
That way home assistant will subscribe to the topic and receive the last known state from the broker after a restart.
how to config it
No idea, I don’t use Tasmota. Try searching the Tasmota documentation and these forums.
See this topic, use strategy 2:
Works very well.
Am I writing this code right?
d = { ‘123456’:[‘sensor1’,‘ON’,‘true’],
'234567':['sensor1','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)
I think indentation is off :
d = { ‘123456’:[‘sensor1’,‘ON’,‘true’],
'234567':['sensor1','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)
Thank you very much, if in this case I use node red, will the effect be the same as using python?
according to the following steps
Thank you, now the system works perfectly.
Good to know