6 Routines to Delete/Rename/Move Devices & Entities and their corresponding registry entries, data, and metadata

If I want to delete multiple devices or entities, I would typically look through core.device_registry and core.entity_registry, respectively to find either the full names or the ids of the desired devices or entities, using either grep or if you want to parse the json code in a more sophisticated manner, use jq

If you have a lot of devices and want to automate, then use a bash for loop to iterate through the desired list of devices or entities, calling the relevant delete routine and flags on each iteration.

My code is written in the spirit of Linux – it is a routine that does what it needs to do – no more, no less. If you want to add on more specific functionality then you chain it through other standard Linux and bash commands to get your desired result.

BE CAREFUL - and test your bash command before proceeding.

If this doesn’t make sense, then I suggest you not try it because I fear you might lack the knowledge and experience to do this low-level and potentially destructive editing of HA registries and databases.

While I have added various tests and backups to make this code as safe as possible, fundamentally it can mess up your system if you don’t know what you are doing… so buyer beware…

You scripts seem to be exactly what I need, but I wonder if something has changed in HA. I logged in with PuTTY and tried your first script, using the command

bash delete_devices_entities.bash -e sensor.kathy_s_left_shade_battery_charge_state_1_2

It seemed to run successfully, with two key result lines being:

   DELETED 1 entries from 'states_meta' table
   DELETED 42 entries from 'states' table

Unfortunately, after running ha core start the entity appeared in the interface again. I ran the script a second time and those two lines became

   DELETED 1 entries from 'states_meta' table
   DELETED 1 entries from 'states' table

so it seems that while many ā€˜states’ entries were deleted, the entity was not completely removed. It still appears in the interface after this second run of the script.

Background: I am running on HA Yellow with the latest software including Core 2026.2.0 , supervisor 2026.01.1 and Operating system 17.0. These are entities from a Matter device, specifically a SmartWings levitate blind. The extra entities appeared months ago when I had to repeat the installation after some problems.

Any idea on what I may be doing wrong?

The entity is probably part of a device (which you haven’t deleted) so when you restart core, it automatically re-discovers the entity. If you want to also delete the associated device, use the -A flag. Additionally, if it was loaded as part of an integration, that integration may still be discovering the device/entity and reinstalling them. Depending on the integration, you may want to turn off auto-discovery and/or more generally uninstall the integration if you are no longer using it.

After deleting devices and entities – especially ones that are parts of custom integrations – I typically do a manual check for any residual ā€˜crud’ before restarting ha core. In particular, I run a grep -ir' on the name of the entity and associated device in /homeassistant/.storage` to see if any special residual entries left that go beyond the scope of the general deletions of my program. If any found, I then manually look through the associated settings/register file and decide whether and how to delete it manually with my text editor (being careful to preserve JSON formatting). Sometimes, you also may need to grep on the device and entity ids.

Thanks. I’ll try some grepping and other checks.

I can’t delete the device or integration because I’m using it. The most troublesome one is a SmartWings window shade which has eight battery entities, with two working and 6 unavailable. I didn’t expect even two since there is only one charge port, but maybe there are two batteries internally.

This duplication is repeated for charge state, identify, and more. I can hide them in most places, but it just seems wrong to have all this junk.

Thanks for your help. If the next round of checks I’ll just try to ignore these and hope that Home Assistant develops a native way to handle this some day.

For latest versions see: