How can I remove autodiscovery MQTT devices?

Tags: #<Tag:0x00007f73ace8d790>

I’ve been playing with MQTT Autodiscovery and in the process I’ve got a bunch of mal-configured devices. Here’s a screenshot!

image

One of the devices is correct, the others are duff. How can I remove them?

I know that if I find out the correct MQTT autodiscovery topic and publish an empty message on it the devices go away - but some of them still come back when HASS restarts! Why is this?

Bit of a pita, but I’ve un/reinstalled mosquito add-on while running hassio.

because you didn’t send it a retain flag

I’ve just been thorugh this. From the CLI for your MQTT server you can use the -r -n flag for each of the topics that were created.

mosquitto_pub -h 127.0.0.1 -p 1883 -u ‘mq_usr’ -P ‘mq_pwd’ -t “homeassistant/sensor/gr-lt99-uptime/config” -r -n

4 Likes

I had this is esphomelib, then I discovered you could use it to clean up the entries it had made, as long as you hadn’t changed the name of the device or name of the item in the config.

Whenever this happens to my with Tasmota, I turn discovery off on the devices SetOption19 Off then I remove the MQTT integration, disable the broker and restart home assistant. Then add integration again and enable the broker and discovery.

I don’t really understand how a device gets multiple entity_id’s the second usually with a _2 suffix… I updated firmware yesterday and it did it on one switch.

1 Like

How can I remove autodiscovery MQTT devices?

have your mqtt yaml set like this:

mqtt:
  discovery: false

works great :slight_smile:

1 Like

Yes ! I get _2 and then have to either roll back my system (snap shots) or totally change the names.

my fix is a little less drastic.

Agreed, I’ll give it a try tonight, as I’m planning on replacing my Bruh digital leds with either esphomelib, or the one from The hook ups channel, as mqtt_json is getting deprecated.

It already is. Just change

platform: mqtt_json

to

platform: mqtt
schema: json

It is but how do you identify that topic? it looks nothing like anything I have in my broker.

I found that my .storage/core.restore_state file contains a bunk of junk MQTT data. However it’s remarkably sticky - deleting it and then restarting doesn’t seem to work. I guess it saves iton exit or something.

Any idea what this is?

That was a topic I had created during my mqtt discovery experiment.

to list topics:

mosquitto_sub -h 127.0.0.1 -p 1883 -u ‘mq_usr’ -P ‘mq_pwd’ -v -d -R -t ‘#’
You can pipe this through grep if there is a keyword you are looking for.

2 Likes

As long as thte mqtt server still has those topics, they will reappear in HA. So clean up the mqtt server and HA will clean itself up.

Just had a same problem that I just tried autodiscovery and it spamed all my data with prekonfigured sensors. I had to disable the autodiscovery in config
mqtt:
discovery: false
And remove whole MQTT in the section Integrations. Then run tool MQTT Explorer and just remove whole topic containing those sensors (by default homeassistant).
No need to reinstall Mosquito and lost other retained maeesages.

One extra sensor is spam? With useful status information? You could just disable that sensor in the integration if it offends you so much. That’s what I did with the binary_sensor it just started creating.

Well the issue is that Zigbee temperature sensors I use have few other values than just temparature. It has also pressure, link quality, baterry voltage, battery percentage. And imagine all these get added also for sensors I had as I have not been using autodiscovery before. So once I enabled autodiscovery i immediatelly had like 50 aditional sensors in my charts (have 10+devices). Chars become unreadable, what a mess. But long story short, it’s great feature for beginners, but I personaly find it risky as it seem that those data are kept in MQTT only as persistant topic wihtout a way how to back it up. Once you hassio running Mosquito crashes and dies, you loose all that, but if you have configured the hard way in the config a backing it up time to time, you can restore anytime. Or am I missing some good way how to backup the autodiscovery sensors?

you can install MQTT-Explorer (http://mqtt-explorer.com/)
Login to your MQTT broker.
Then you choose the items that you want to remove and push the Del button on your keyboard or click on the waste-basket symbol (for the last method you have to move the cursor horizontally from the selected item to the right and then go up to the waste-basket symbol)