As of the time of this posting there is not an easy way that I have found to delete devices from Home Assistant. Checking on-line it seems like the only way is to edit a core.device_registry file in a hidden folder. Yuck.
Well, OK, if I have to do that I want to make it as simple as possible. So here are the steps that I use:
First of all I have a couple of add-ons installed. The first is the simple file editor. I had been using the Visual Studio editor, but it started to cause issues with my installation so I started using this one.
Also I use the Terminal add on.
Step 1 – use the Integrations page to find the devices I want to remove. I disable them using the “edit” icon at the top of the page for the device. This is the icon you would use to rename the device. Below the name is a disable feature:
I click on the slider to disable the device.
After disabling all the devices I want to remove I open the Terminal. I change directory (cd) to the .storage folder. I then make a backup of the core.device_registry file. Then I copy the core.device_registry file up one folder so that the File editor can find it easily.
cd ~/config/.storage
cp core.device_registry core.device_registry.bak
cp core.device_registry ..
I now open the File Editor.
In the file editor I go to the folder view (which on my system defaults to the config folder). There I find the copied core.device_registry file.
I click on it and open it. I then go to the File Editor settings and change the edit mode to JSON. It defaults to YAML mode.
All of this just takes a few minutes. I am now ready to remove the items that I have disabled. I click on the search icon and search for “disabled_by”: “user”
I find each one and then move up to the start of the entry. Below shows the first line of the entry at line number 2766.
Since I am in json mode the line number has an expansion arrow on it. I click on the arrow to collapse the entry, and then I select the collapsed entry and delete it.
After deleting the block I am left with a blank line which I also delete, and then use the find feature to go to the next entry.
When all have been deleted I save the file and open the terminal again. I copy the modified file back to the .storage folder. Note that I am still in the .storage folder in the Terminal.
cp ../config.device_registry .
All that is left to do is to go to the Developer Tools YAML tab and check the configuration. If the tests passes you can then restart Home Assistant.
I find this the safest way for me. By disabling devices I make sure that I am finding and deleting the devices I want. By using the json mode and the expand/collapse feature I make sure I am not accidentally deleting too much.
Hi,
Thanks for this very interesting post.
I encountered a problem with obsolete devices and entities in HA and cannot delete them from the UI.
I want to try your solution, but I’m still wondering what you did with the entities?
Every device probably also had some entities….?
Were you able to then delete them via the UI or how did you go about it?
In another community post I read that there are additional files for devices and entities, which should be edited….. (core.device_registry, core.entity_registry, core.config_entries, core.restore_state)
Any experience with this?
Many thanks