At first glance, it looks OK. I wouldn’t normally set the entity’s state_topic
to something so similar to its discovery topic but I think it should be OK.
Just for fun, try this script.
create_entities:
sequence:
- service: mqtt.publish
data:
topic: homeassistant/binary_sensor/bathroom_door/config
payload: >
{
"name":"Bathroom Door",
"state_topic":"home/sensor1",
"device_class":"door"
}
Alternately, just go to Developer Tools > Services, select mqtt.publish, then set the options:
topic: homeassistant/binary_sensor/bathroom_door/config
name: Bathroom Door
state_topic: home/sensor1
device_class: door
and click CALL SERVICE.
Normally you would include retain: true
so that the discovery topic and its payload are stored on the broker. This ensures that when you restart Home Assistant, the entity will be re-created (otherwise it won’t). For testing purposes, it’s not necessary (you probably don’t want this entity to persist beyond the next restart).