How to remove an integrated ESP device?

I have a whole bunch of ESPhome devices that use mqtt discovery in HA (not the new api).

One of these devices is faulty and I want to replace it with one of the other less important devices.

What is the best way to remove just these two devices from the HA integration so I can then reprogram one of them to replace the other?

Sending blank mqtt discovery messages for the device?
Stopping HA and editing the .storage files?
Or some other method?

Using the “Clean MQTT” script ESPHome provides. In dashboard, see overflow menu.

2 Likes

Unfortunately due to operator error that will not be possible (I’ve since deleted the ESPHome config files for the devices as they were not needed).

I’ve tried stopping the home assisistant server and deleting relevant sections of the core.device_registry and core.entity_registry but as soon as I start HA again the entries reappear.

If tried sending blank retained config mqtt messages to the broker.

My config is a mess. I have test sensors that dont exist and a sensor that does exist but wont connect. I get these warning in the HA log:

homeassistant.exceptions.HomeAssistantError: Entity id already exists: sensor.dining_room_humidity. Platform mqtt does not generate unique IDs 2019-01-19 20:20:03 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved

And these errors in the mqtt log:

1547888619: New client connected from 10.1.1.100 as 0930d2e1-6e3d-4cdc-bf41-redacted (c1, k60, u'mqtt_user').
1547888628: Socket error on client dining_dht2-bcdredacted, disconnecting.

This whole mess could have been easily avoided if we had an easy way to delete devices from integrations rather than the integration as a whole.

I’m now seriously considering having to delete the whole integration, my .storage files and reinstalling the mqtt broker.

It’s a massive mess.

This is madness.

  1. Stop HA server from the configuration / general page
  2. delete all reference to the duplicate sensors from core.device_registry and core.entity_registry
  3. send retained blank config messages to the mqtt broker for the duplicate entities
  4. stop the host system via ssh
  5. physical power cycle

The ba$%&rd entities are back in the .storage files! (but not the mqtt broker).

I have done this twice but the .storage entries keep re-appearing.

What the heck am I doing wrong?

Delete the MQTT integration and Broker and restart.
Edit the dud entities from the /.storage file.
Restart HA
Verify /.storage file has them no more again.
Add MQTT broker and integration and restart HA again.

1 Like

I’m 99.9% certain I’ve expunged the offending entries from the mqtt broker. Inspection of the topic homeassistant/sensor/# reveals no retained duplicates/test sensor configs.

I’m procrastinating about pulling the pin on the whole integration in the (vain) hope that someone comes up with a better idea as this means I have to crawl into the back of my comms cupboard to pull the power on a number of remote ESP devices to get them to resend their config messages. Not an easy task - I have some illuminated rocket launch cover switches for this but haven’t wired them up yet. Guess I should just drink a cup of concrete and HTFU.

I’ve made a snapshot, copied it off and am going in…

  • Delete the MQTT integration and Broker and restart. DONE
  • Edit the dud entities from the /.storage file. DONE
  • Restart HA DONE
  • Verify /.storage file has them no more again. (gone, YAY!) DONE
  • Add MQTT broker and integration and restart HA again. Reinstall failed twice. Third time lucky

Power cycled the easy to get to ESP devices and… I have no ESP mqtt integrations or sonoff devices (not auto discovered) :frowning:

Restart again.

And we’re back and fully operational without the test duplicates!

My remote battery powered ESPs that are asleep are missing though. Head torch on and going for a walk in the garden to wake them up. I may be some time…

Thanks David.

12 out of 12 That’s a pass. Mailbox refused to respond though. Found the reed switch magnet had fallen off. Will sort it in daylight.

Lesson learned: Do not reuse ESP modules for testing.

1 Like

Those zombies can be an absolute nightmare to kill!

1 Like

Not for much longer :crossed_fingers: :slight_smile:

1 Like

Yep! Good PR soon.

Thank you for this. I had to do one more thing: before adding the broker back to HA I had to remove the retained messages on the broker. To do that I took the easy route and deleted mosquitto.db

1 Like

Thank you, the same process worked for the esphome platform which was producing similar messages.

@tom_l I wonder if you would mind updating this post for anyone looking for a solution, as the solution has changed.

image

This will delete the single integration (not the entire esphome integration).

1 Like

That is only applicable if using the API.

I don’t get it. Deleting the MQTT integration and broker, restarting, editing the entities from .storage, restarting, verifying that the .storage file hasn’t re-added the entities and then re-adding the MQTT broker and integration then restarting HA again is your preferred solution??

No it isn’t. I am now using the API for all but a couple of my ESP devices. These devices use deep sleep which does not work well with the API.

Guess I still don’t get it.

I was just saying that in order to save time for the next person with my question, that you update the solution. I don’t get why you’re opposed to that, but whatever.

Because your solution does not apply to this use case. The original question was about mqtt, not the ESPHome API:

And if using MQTT, deleting the integration still deletes all mqtt devices and clearing retained messages in the broker is still required.

And now I understand. Thank you.

1 Like