How to remove entities without a unique_id? Where are they?

Has anyone figured out how to assign a unique ID so they can be managed in the UI?

1 Like

@WoJWoJ - Were you ever able to find an answer to this?

Unfortunately not.

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. :slight_smile:

4 Likes

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.

If not want to wait, from developer-tools/service and “Recorder: Purge Entities” I was able clear my orphan entity.

31 Likes

This worked for me… thanks again.

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?

Thanks Bogey.

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 :confused:

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?

Damn I have exactly the same problems! Any solution for it. With Recorder: Purge Entities it doesnt work.

PS:
Clear the browser cache works!

3 Likes

Hi ,

Yes it helped , log out/log in removed the ones.

Thanks

3 Likes

After purging the entity, log out/log in will make it go away.

Thanks guys.

2 Likes

The question still remains; “How do you purge an entry that does not appear in the list of entities or when typed out?”

For me I went to “Developer Tools”, “Statistics” tab, then clicked “Fix Issue” on all the entities without unique ID’s.

3 Likes

Thanks a lot,
I just had to clear the cache

1 Like

For me, the devices were not in the known_devices.yaml…

I had removed them from the configuration.yaml, and the entities persisted.
Restarting HA in the interface didn’t work… UNTIL I ran “reboot” from the terminal.

After that they were gone.

1 Like

Thanks- that’s a tool that I didn’t know about.
But my orphan device is not on that list.

I had the same issue after creating an entity with the REST api. I was able to remove this by posting a DELETE event:

curl -X DELETE -H "Authorization: Bearer $TOKEN" https://your-homeassistant.example.com/api/states/sensor.example

More about the REST api in the docs, although this delete action is not mentioned there: REST API | Home Assistant Developer Docs

10 Likes