Yes.
Home Assistant uses MQTT Discovery to automatically find and register a device.
Once you understand how MQTT Discovery works, you’ll also understand why you had so much trouble getting rid of the device. The principle is very simple. If I publish this ‘discovery’ payload:
'{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}'
to this topic:
homeassistant/binary_sensor/garden/config
then Home Assistant will automatically create a new entity (in the entity_registry) called binary_sensor.garden
and consider it to be a motion detector. It’s that simple.
Here’s the part that can make it very hard to get rid of the new entity. You follow all the normal procedures to delete an entity yet it always gets ‘re-discovered’. Why? Because when its ‘discovery’ payload was published, it was published as a retained message. That’s the part where you guessed correctly that, somehow, mosquitto was storing it. That’s the very definition of a ‘retained message’, namely it’s a message (payload) that is retained (stored) by the MQTT broker (mosquitto).
The big ‘nuclear option’ is to re-install mosquitto and the small ‘nuclear option’ is to delete mosquitto’s database (where messages are stored). Both options are excessive. All that’s needed is to simply delete the retained ‘discovery’ message.
Rather than advocate the use of the traditional method of purging a retained message (publish an empty retained message to the topic) simply use MQTT Explorer to do it. It provides the advantage of showing you all the topics and messages being handled by your mosquitto broker, including which ones have retained messages (and allow you to delete the retained message).
Going back to my example, if I delete the retained message I had originally published to this topic:
homeassistant/binary_sensor/garden/config
then Home Assistant will no longer “re-discover” binary_sensor.garden
. In fact, if I remember correctly, it will also automatically remove the existing binary_sensor.garden
.
EDIT
If you don’t want to install a third-party MQTT client like MQTT Explorer (but I do recommend it), you can purge a retained message from within Home Assistant using the mqtt.publish
service (thank you to @francisp for the suggestion).