The binary sensor state will be updated only after a new message is published on
payload_off . If these messages are published with the
retain flag set, the binary sensor will receive an instant state update after subscription and Home Assistant will display the correct state on startup. Otherwise, the initial state displayed in Home Assistant will be
Is this definitely true? Mine seem to take on a locked or closed state on reboot (locked if a lock and closed if a door etc)
Yes, it’s true.
What you’re observing is the fact the binary_sensor defaults to
off. For example, given this definition:
- platform: mqtt
name: 'Bathroom Door'
it appears like this in the UI:
It indicates ‘Closed’ which corresponds to state =
off. Yet the topic
home/sensor1 doesn’t even exist on my MQTT broker, let alone have a value.
Some would argue that defaulting to
off in the absence of any received data is misleading. The solution would be to define an availability topic. In the absence of data, the binary_sensor’s state will be
If I add this line to the previous definition:
the UI will display this: