Erase Old MQTT or Unwanted Sensors
How to use it To use this:
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. 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. Open your browser's JavaScript console and paste in the code below. It will delete all the devices in that garbage area.
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,
);
Gist Source: https://gist.github.com/jasonk/cea154e5785684e184492256f2fdb21a