How to Deleting unused Devices and Entities in Home Assistant(.storage)

 

 

Entities and devices are stored in configuration files in /config/.storage/ (core.device_registry and core.entity_registry respectively). 

Below is the process to entirely remove a device and/or entity in Home Assistant.

1. Backup

Make sure you have a backup or snapshot of HASS from before you make these changes.

You can backup the entire machine it’s running on, snapshot the VM (if it’s on a VM), or take a snapshot in HASS’s backups section in the settings.

 

for example(.storage directory)

/data/homeassistant/.storage

 

2. Shutdown Home Assistant 

In general it’s not a good idea to modify these core files while HASS is running. Since they aren’t supposed to be user-modifiable, HASS doesn’t expect them to be changed by anything other than itself and therefore may not handle it nicely if they are changed while it’s running.

Info
If you’re running HassOS this may not be possible. I’m not familiar with the ins and outs of HassOS, having never used it myself. You could try editing these files while HASS is running and then restart it, but I can’t guarantee that will work.

3. Modify the files 

There are many ways to access HASS’s config while it’s not running, but the easiest way will be SSH in most cases.

  1. SSH to your HASS machine and move to your config directory.
    If you’re running HASS in Docker, that will probably be /usr/share/hassio/homeassistant/.
  2. Move to the .storage directory and edit the following files with your choice of text editor.
    • core.device_registry
    • core.entity_registry
    • core.config_entries
  3. In each file, search for references to the name of the device or entity you want to remove.
  4. Delete the entire section for that object.
  5. Repeat steps 3 and 4 for each device or object you wish to remove from HASS.

Make sure you keep the syntax correct!

for example

They are listed in Settings>Devices>Entities, but the icon is of a lined-through pencil, indicating read-only.

del code in .storage/core.entity_registry

{
        "aliases": [],
        "area_id": null,
        "capabilities": null,
        "config_entry_id": "cf46024ed9667e123443ae23c24deca4",
        "device_class": null,
        "device_id": "71fe2520f7c9a2d6fbc4d87d522f405e",
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "sensor.212a01_cloud_285062_voltage",
        "hidden_by": null,
        "icon": null,
        "id": "314a50ca7dd08cbfa67345b83dc392d8",
        "has_entity_name": false,
        "name": "米家智能插座2 蓝牙网关版2 by xiaomi miot raw Power cons voltage",
        "options": {
          "conversation": {
            "should_expose": false
          }
        },
        "original_device_class": "voltage",
        "original_icon": null,
        "original_name": "米家智能插座2 蓝牙网关版2 Power cons voltage",
        "platform": "xiaomi_miot_raw",
        "supported_features": 0,
        "translation_key": null,
        "unique_id": "212a01-cloud-285062-power_cons_voltage",
        "previous_unique_id": null,
        "unit_of_measurement": null
      },

This is of the utmost importance. If you get this wrong, it will break.

If you’re unsure, paste the entire file into JSONLint, which will validate JSON syntax for you.

4. Start Home Assistant 

With all luck, HASS will start back up without a care in the world, just the way it shut down but without those pesky devices/entities you didn’t want!

Once it’s started, you should check the logs to ensure it’s not found any new problems in your configuration.

If something’s gone wrong and it doesn’t start up or starts up with a lot of errors, I suggest restoring from the backup or snapshot you took earlier and trying again.

detail:https://blog.matterxiaomi.com/boards/topic/13399/where-is-current-configuration-stored-while-home-assistant-helpers-created-in-the-gui-storage-direct/page/2#31996

I always welcome feedback on my posts, please contact me if you have any. I’m also happy to answer any related questions if I know the answer.

 

 

useful links

https://blog.tiga.tech/posts/deleting-devices-and-entities-in-home-assistant

Comments


Comments are closed