-
Setting up the python_script integration is easier than configuring a binary_sensor (just add
python_script:
toconfiguration.yaml
and done). -
Creating a sub-directory is a basic computer skill and an insignificant step.
On the subject of restarting Home Assistant, there is a way to create MQTT Sensors and Binary_Sensors (and other entities) without restarting and that’s to use MQTT Discovery. To enable it, just add discovery: true
to MQTT’s configuration.
For example, to create this binary_sensor via MQTT Discovery:
- platform: mqtt
name: 'Bathroom Door'
state_topic: 'home/sensor1'
device_class: door
you can use an MQTT client, like MQTT Explorer, to publish this payload (as a retained message):
{"name": "Bathroom Door",
"state_topic": "home/sensor1",
"device_class": "door"}
to this topic:
homeassistant/binary_sensor/bathroom_door/config
Home Assistant will immediately create the binary_sensor and it will be visible in Developer Tools > States as well as Configuration > Entities (all without having to restart Home Assistant).
NOTE: If you add the unique_id
option (with some unique value), then the binary_sensor can also be edited in Configuration > Entities and will be listed in MQTT Integrations.
{"name": "Bathroom Door",
"state_topic": "home/sensor1",
"device_class": "door",
"unique_id": "abc123xyz"}
Ideally, you would be able to publish this using Developer Tools > MQTT > Publish. However, it currently doesn’t offer the ability to publish the payload as a retained message (which is important for preserving the discovery topic).