Clean deletion of entities?

Hello,

Is there a way to delete/drop entities in a clean way. I did a few test with MQTT sensors and now I would like to remove those dummy sensors I have on home page. I know deleting the homeassistant db will do the trick, but I think this on the hard side. Hiding them is also not a satisfactory manner to me.

if it’s MQTT and you had set you your topics to be retained, even deleting the HA DB won’t do the trick as the message will still be on your MQTT Broker.
Instead you need to delete the retained message.
The standard MQTT mechanism to clean up retained messages is sending a retained message with an empty payload to a topic. This will remove the retained message

Hello,

Thank you for the info. Should I restart HA after publishing the empty payload?

I’m not sure to be honest, you may still have values saved into HA so maybe yes you should?

All you need to do is remove the mqtt sensors you defined in your configuration.yaml and then restart Home Assistant. Not necessary to publish a null payload to clear a retained message (because even if you do, unless you remove the sensor from configuration.yaml, it will still show up but with an empty value).

Also, deleting the database won’t delete the entities, it will only delete the history for all of your devices.

Yes unless @e_jp has enabled discovery: true for MQTT and hasn’t manually saved/added the MQTT entities…
In which case he’d need to delete the topics he no longer wants…

That’s the trick, sensors are not defined because of MQTT auto discovery. (I’m testing esphomeyaml features)

Ahh I see. In that case the only way to remove the sensors is to publish a null retained payload to the discovery config topic that your device publishes its discovery payload to, then restart Home Assistant. No need to delete the HA database.

1 Like

Hello again and thank you all!
With your good advises, I was able to remove the unwanted sensors.

1 Like

can you share the steeps to do that i have some dummy sensors too that i want to remove

I’m pretty sure you can do it several ways (including from HA or node-RED) but in my case I used MQTT.fx client (http://mqttfx.org/) to publish an empty payload in the config topic:

  • connect to your MQTT broker
  • in the subscribe section, hit “scan” in topics collector
  • find the topic you want, right-click and copy it
  • in the publish section, paste the link, leave payload empty and hit publish
    that should be it.
1 Like

node-red to do this for MQTT server 192.168.100

[{"id":"e7a9896a.fa9a18","type":"mqtt in","z":"21dc59a8.d43566","name":"","topic":"#","qos":"2","datatype":"auto","broker":"dbb6c1e9.b6c53","x":150,"y":480,"wires":[["ab0daaa8.084ca"]]},{"id":"ab0daaa8.084ca","type":"change","z":"21dc59a8.d43566","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":480,"wires":[["5f2c47b6.b8d52"]]},{"id":"5f2c47b6.b8d52","type":"mqtt out","z":"21dc59a8.d43566","name":"","topic":"","qos":"","retain":"","broker":"dbb6c1e9.b6c53","x":590,"y":500,"wires":[]},{"id":"dbb6c1e9.b6c53","type":"mqtt-broker","z":"","broker":"192.168.0.100","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]