Skip to content

Instantly share code, notes, and snippets.

@jasonk
Last active May 25, 2025 20:08
Show Gist options
  • Save jasonk/cea154e5785684e184492256f2fdb21a to your computer and use it in GitHub Desktop.
Save jasonk/cea154e5785684e184492256f2fdb21a to your computer and use it in GitHub Desktop.
Home Assistant - Mass delete devices

After running rtl_433 with the MQTT Discovery add-on 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 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.
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,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment