Skip to content

Instantly share code, notes, and snippets.

@jasonk
Last active October 24, 2025 09:06
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,
);
@korpx
Copy link

korpx commented Sep 6, 2025

I had 1400+ of my neighbors RFXCOM devices cluttering my setup for years. Can't believe it's not an option to bulk delete devices in Home Assistant. This is awesome, thanks!

The script worked fine except it could not delete some 15 devices that gave me errors in the java script console;

... VM387:21 Failed to delete device cdac56ad6edf72a4ac10ff12c5f04b48: {code: 'invalid_format', message: "expected str for dictionary value @ data['config_entry_id']. Got None"}code: "invalid_format"message: "expected str for dictionary value @ data['config_entry_id']. Got None"[[Prototype]]: Object (anonymous) @ VM387:21 await in (anonymous) (anonymous) @ VM387:24 VM387:21 Failed to delete device e9023c62c0b1a46f967167d5e8689af0: {code: 'invalid_format', message: "expected str for dictionary value @ data['config_entry_id']. Got None"} (anonymous) @ VM387:21 await in (anonymous) ...

@drkpxl
Copy link

drkpxl commented Sep 15, 2025

Thank you for this, had over 3000 "bad" devices, this fixed it for me.

@imoskvin
Copy link

imoskvin commented Oct 5, 2025

Thank a lot! You made my day. iBeacon Tracker integration added over 12K devices. I searched for a way to get rid of them and finally you posted a great solution!
Based on your function I made my own to delete ALL devices by source integration.
So it will take a while, but finally I'll get what it planned :)
2025-10-05_20-41-40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment