Skip to content

Instantly share code, notes, and snippets.

@jasonk
Last active November 13, 2025 17:30
Show Gist options
  • Select an option

  • Save jasonk/cea154e5785684e184492256f2fdb21a to your computer and use it in GitHub Desktop.

Select an option

Save jasonk/cea154e5785684e184492256f2fdb21a to your computer and use it in GitHub Desktop.

Revisions

  1. jasonk revised this gist May 25, 2025. No changes.
  2. jasonk renamed this gist May 25, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. jasonk created this gist May 25, 2025.
    10 changes: 10 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    After running [rtl_433](https://github.com/pbkhrv/rtl_433-hass-addons/tree/main/rtl_433) with the [MQTT Discovery add-on](https://github.com/pbkhrv/rtl_433-hass-addons/tree/main/rtl_433_mqtt_autodiscovery) for a while, I ended up with hundreds of my neighbors devices in my Home Assistant instance. This was when I found out there was no easy way to delete them and was faced with the prospect of going to each one in the GUI, picking "delete" from a menu and the confirming it hundreds of times.

    I'm too lazy for that, so I did this instead, based on [some code from the forums](https://community.home-assistant.io/t/some-entities-not-visible-in-rfxcom-rfxtrx/353134/4) I came up with this.

    # How to use it #

    To use this:
    1. Create a new Area in your Home Assistant (I called mine "Garbage"), and change the `GARBAGE_ID` variable in the code to have the ID of your new area.
    2. In the devices list you can hit the "select" button and put checkmarks next to all the devices you want to get rid of. Then use the menu in the upper right to mass move all those devices into the "Garbage" area.
    3. Open your browser's JavaScript console and paste in the code below. It will delete all the devices in that garbage area.
    33 changes: 33 additions & 0 deletions home-assistant-delete-garbage.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    await (async (garbage_id, actually_delete=false) => {
    const hass = document.querySelector("home-assistant").hass;
    const devices = await hass.callWS({type: "config/device_registry/list"});
    for (const device of devices) {
    if (device.area_id !== garbage_id) continue;
    try {
    if (actually_delete) {
    await hass.callWS({
    type:"config/device_registry/remove_config_entry",
    device_id: device.id,
    config_entry_id: device.primary_config_entry,
    });
    }
    console.log(
    'Delete device:',
    device.name_by_user || device.name,
    device.manufacturer,
    device.model,
    );
    } catch (error) {
    console.error(`Failed to delete device ${device.id}:`, error);
    }
    }
    })(
    // Change this to the ID of your garbage area
    "eb89d996b3487d2c80204b9cc861e99a",
    // When this is `false` the code will just list the devices it would
    // have deleted, but not actually delete them. You should leave this
    // as `false` the first time, review the output, then run it again
    // with this changed to `true` when you want to actually delete the
    // devices.
    false,
    );