Deleting an old Entity is driving me crazy

HA: 0.95.4
ESPHOME: 1.13.6

I have seen numerous discussions on how to delete an entity from HA, but whatever i try it keeps coming back and drives me crazy. It started after I installed an ESP32_camera (called camera.tuin) that worked well. Then I re-flashed the ESP32 device for some testing with face recognition SW and after that I re-flashed it again with the first ESP32_camera SW again. The same device appears as camera_tuin_2 with the same fixed IP as before, and the ‘old’ camera_tuin device is still visible in developertools->states. I have deleted all entities that refer to this one (folowing the numerous discussions), but it still keeps coming back. I even removed the esphome integration and resinstalled it, but it keeps coming back.

Anyone can shed some light into this behaviour? It drives me nuts.

Regards, Harry

Make a backup of your config or create a snapshot. Move it off your HA server somewhere safe.

Delete the entity from the configuration / entities menu.

Delete the integration from configuration / integration.

Delete or move the corresponding esphome files from config/esphome.

Use the command line to stop home assistant.

Use SSH (terminal or winscp) to back up your config/.storage files. Somewhere safe, preferably off your HA server.

Comb the files in config/.storage for reference to your device and delete the entries - being extremely careful not to disrupt the file structure.

Likely culprits are the core.*, files.

Restart home assistant from the command line. If it refuses to start or things go tits-up stop home asssistant and restore your config/.storage directory from the files you saved and restart. Worst case use the restore snapshot / backup.

These files are not supposed to be user editable but sometimes it’s the only way.

I feel your frustration. This is an absolute PITA and it should not be this difficult to remove a device. The .storage mode leave a great deal to be desired.

@tom_I, I have already checked all core.* files (first thing to check) and in the passed stopping HA, remove the entries and start HA again resolved this issue. I agree, this is really frustrating, i have spent already several hours to find the culprit, but no luck yet. A month ago i switched from domoticz (used it since 2013) to HA. Because domoticz uses a Sqlite database, you simply select the device, delete it and all references of the device are removed. I really hope the developers take a look at this, because I really like HA compared to domoticz

I don’t know if you configured ESPHome to use MQTT for this device, so I may be heading down the wrong path here, but is there a possibility that MQTT Discovery is responsible for this behavior?

If the device’s discovery topics were published as retained messages, that means they are stored on the MQTT Broker. Even if the device is no longer physically present and you’ve deleted every instance of the entity in config files, entity registry, .core files, etc the moment Home Assistant detects the device’s retained discovery topics it will create the entity. So despite your best efforts to eliminate it, it always seems to magically re-appear … and all because its discovery topics (containing retained messages) are still on the broker.

If you did not configure ESPHome to use MQTT then this nice little theory doesn’t apply to you. :man_shrugging:

1 Like

@123 Taras, you might have a point here, i have been ‘playing’ with MQTT also, will have a look at the retained messages for this ‘old’ device. Thanks for the info.

The default discovery prefix for MQTT Discovery is homeassistant/ so when your MQTT client connects to the broker and subscribes to the homeassistant/# topic, look for anything referring to a camera. It should not contain any topics for the camera that you are no longer using. If you do find them there, then you’ve discovered the source of your problem. The retained messages in those topics must be purged. If you’re using MQTT Explorer, it makes this task very easy.

1 Like

@123 hank you so much, fixed it

1 Like

Glad to hear it and thanks for marking my post with 'Solution`. It makes it easier for others to find it.

FWIW, I encountered this situation last in April (posted in another forum). It involved thermostats and after exhausting all other possibilities (config file, entity registry, etc) I concluded there must be only one other mechanism to make them re-appear and that’s through MQTT Discovery. I checked the custom component’s source code and confirmed it was posting retained messages to its discovery topics. The user purged them and that stopped the unused thermostats from being re-discovered.

You’re answer is a life saver to a search of many hours…
Thank you!

1 Like

This seems to be related to the issue I’m having but I haven’t had much luck with the specified suggestions/fixes

I have an entity I can’t seem to get rid of called: sensor.auto_close (name: Auto Close)


  • Try to remove from entities but get: “Entities can only be removed when the integration is no longer providing the entities” even after restarting Home Assistant
  • Per @tom_l suggestion I removed all references to it in the config/.storage folder files (it only existed in core.entity_registry) but every time I restarted HAAS, it “magically” appeared/was re-entered into my core.entity_registry file
  • Per @123 Taras - It sounds like something like this could happen if ESPHome is configured to use MQTT - but that doesn’t seem to be the case as I’ve explicitly set mqtt to discovery: False (I never had it to true) - see here and here. I also installed MQTT Explorer as @123 suggested in the posted solution and confirmed Auto Close (sensor.auto_close) isn’t there

Could it be you have retained MQTT messages?

I was eventually about to remove it by removing a different sensor template I had configured improperly. After uploading I was able to simply remove sensor.auto_close from the entities