I have configured a door sensor for a wine cellar… and the door is usually open. Problem is: every time HA reboots or something like that, its state is shown as closed - where it is actually open, as it has not changed its state.
Any suggestion on how to solve this, besides actually closing the cellar door? I only close it when I leave town - that’s why.
What door sensor? If it is a mqtt door sensor, make sure it publishes it state with the retain flag set, so the state gets preserved across HA restarts.
Thanks Francis. I tried using strategy 1, and it shows no error messages, but the same thing happens: as soon as I reboot HA, it again shows the sensor as closed, whereas it has been left open.
d = {
'2291358':['frontdoor','ON','true'],
'2291351':['frontdoor','OFF','true']
}
p = data.get('payload')
if p is not None:
if p in d.keys():
service_data = {'topic':'sensor/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
else:
service_data = {'topic':'sensor/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
hass.services.call('mqtt', 'publish', service_data, False)
The third parameter of d is true, so the retain flag is set and the state of the door is preserved across HA restarts.