I have just set up some door and window sensors but every time I restart HA they revert to ‘Closed’. I understand that this is expected behaviour i.e. their state is not saved in the same way as input_booleans for example.
Is there a way around this other than the horrible kludge of saving the binary sensor state into an input boolean every time it changes?
Why would they be changing to Closed if the door/window isn’t closed? If the sensor hasn’t updated yet, it should be ‘unknown’ after restart, not ‘Closed’. Maybe you could share your sensor code.
Interesting. Well, I don’t use MQTT (you should probably use that tag when creating a topic that involves MQTT), and I haven’t looked at the code, but I would think that the binary_sensor’s state would be ‘unknown’ until it receives the first message from the broker. Are you sure the state is ‘off’, or is it just not ‘on’?
Well, all I can say is that when HA restarts my binary_sensors which have a type of ‘door’ or ‘window’ all show as ‘Closed’ irrespective of their state at that time.
Now that this seems to be ‘surprising’ behaviour I will create a new thread with the MQTT tag.
Thanks for your input.
On the original point, even when sensors show as ‘Unavailable’ do you have a way that you reset them to their original state at system start which doesn’t involve a ‘kludge’?