I have several entities withouta unique_id that I created when making some tests but that I cannot delete from the UI, there is no delete button.
When adding a unique_id during creation (via MQTT discovery), I have a better control of it though the UI, but still not possible to delete it - the delete button is grayed out
The only solution I found for this was to modify the home-assistant_v2.db with SQLite DB Browser, which you can download and install for free. I am running home assistant in a docker instance on a Ubuntu server. The database file is found in the home assistant config folder.
*** Messing with the database is probably the best way to completely screw up your entire install if something goes wrong - so make a backup first. ***
Stop home assistant and make a backup of the database first. Then while home assistant is stopped, you can access the database with the SQLite DB Browser. For me, my orphan entities were caused by creating MQTT sensors in my configuration.yaml. I found these entities referenced in the “states” table of the database. I simply deleted every record I found which referenced the orphaned entities. Once I restarted home assistant, I checked the entities and found the orphan entities were all gone.
I had previously tried restarting home assistant to see if they would disappear, that did not work. I used grep to find any instances of the orphaned entities in the .storage folder. I removed every instance I found in that folder to only see them created by home assistant again. The only file left with references to the entities I wanted to remove was the database file. I found these things so annoying I was willing to risk a complete re-install and re-build if something went wrong in the database modifications. But hey, if it did go that wrong, a clean install would also fix the issue.
If what is in home-assistant_v2.db is causing the entities to show up, most likely you simply need to wait until the recorder history is purged from the database to get rid of it. 10 days is the default setting for that. Then the last values from the old sensor are deleted automatically.
I have also have an entity, created from HACS, that I cannot remove. Interestingly the entity is not displayed when I goto settings > devices > entities but is offered as an entity when adding to lovelace. The entity has not been used for many months. I ran recorder purge for it. Still there.
How can I remove it and isn’t this an inconsistency in the database? Is there possibly a service to check this and clean it?
This did not work for me however. Any suggestions?
FYI: I run HA on top a deconz system. Deleting the troublesome entities from deconz, reloading (from deconz), deconz:deleting orphans and recorder:purging still leaves the ghost entities
I have a lot of (maybe 30000?) sensor ble entities without unique id and with not (anymore) existing mac adresses. Recorder Purge entities does not delete them. I would be glad if anyone had an idea …
Many Thanks, Michael
Just tried to watch the Database (home-assistant_v2.db) with SQlite DB Browser. Can’t find the unused entries in “state” folder, but they are all listed under “event_data”. Can I delete them from there and might it help?