@fleskefjes @VietNgoc
Thank you both. Safe Mode just locked up on my. Then I took it to my ChatGPT. It showed me how to removed the Unifi intergration via SSH via my MacBook terminal. All was new to me so happy it gave me all the commands to copy paste.
After running some commands it gave me, It first wanted to know the Unifi specific ID. Based on that ran commands against that:
173888 entity_registry
142.2M size
115878 device_registry
It had me stop ha core stop, then I ran this it gave me:
python3 - <<‘PY’
import json
import os
import shutil
TARGET = “01KG6M9294VH0FSVZXBH8WFM63”
BASE = “/config/.storage”
paths = {
“config”: f"{BASE}/core.config_entries",
“entity”: f"{BASE}/core.entity_registry",
“device”: f"{BASE}/core.device_registry",
}
Load files
with open(paths[“config”], encoding=“utf-8”) as f:
config = json.load(f)
with open(paths[“entity”], encoding=“utf-8”) as f:
entity = json.load(f)
with open(paths[“device”], encoding=“utf-8”) as f:
device = json.load(f)
Count before
config_before = len(config[“data”][“entries”])
entities_before = len(entity[“data”][“entities”])
deleted_entities_before = len(entity[“data”][“deleted_entities”])
devices_before = len(device[“data”][“devices”])
deleted_devices_before = len(device[“data”][“deleted_devices”])
Remove exact UniFi config entry
config[“data”][“entries”] = [
x for x in config[“data”][“entries”]
if x.get(“entry_id”) != TARGET
]
Remove UniFi entity records
entity[“data”][“entities”] = [
x for x in entity[“data”][“entities”]
if x.get(“config_entry_id”) != TARGET
]
entity[“data”][“deleted_entities”] = [
x for x in entity[“data”][“deleted_entities”]
if x.get(“config_entry_id”) != TARGET
]
Remove UniFi device records
device[“data”][“devices”] = [
x for x in device[“data”][“devices”]
if x.get(“config_entry_id”) != TARGET
]
device[“data”][“deleted_devices”] = [
x for x in device[“data”][“deleted_devices”]
if x.get(“config_entry_id”) != TARGET
]
Calculate removals
removed_config = config_before - len(config[“data”][“entries”])
removed_entities = entities_before - len(entity[“data”][“entities”])
removed_deleted_entities = (
deleted_entities_before - len(entity[“data”][“deleted_entities”])
)
removed_devices = devices_before - len(device[“data”][“devices”])
removed_deleted_devices = (
deleted_devices_before - len(device[“data”][“deleted_devices”])
)
print(“Removing:”)
print(" Config entries :“, removed_config)
print(” Live entities :“, removed_entities)
print(” Deleted entities :“, removed_deleted_entities)
print(” Live devices :“, removed_devices)
print(” Deleted devices :", removed_deleted_devices)
Safety checks based on what we already verified
if removed_config != 1:
raise RuntimeError(
f"SAFETY STOP: Expected 1 config entry, found {removed_config}"
)
if removed_entities != 173733:
raise RuntimeError(
f"SAFETY STOP: Expected 173733 live entities, found {removed_entities}"
)
if removed_deleted_entities != 155:
raise RuntimeError(
f"SAFETY STOP: Expected 155 deleted entities, found {removed_deleted_entities}"
)
if removed_devices != 57916:
raise RuntimeError(
f"SAFETY STOP: Expected 57916 live devices, found {removed_devices}"
)
if removed_deleted_devices != 46:
raise RuntimeError(
f"SAFETY STOP: Expected 46 deleted devices, found {removed_deleted_devices}"
)
Write to temporary files first
outputs = [
(paths[“config”], config),
(paths[“entity”], entity),
(paths[“device”], device),
]
for path, data in outputs:
temp = path + “.cleanup”
with open(temp, “w”, encoding=“utf-8”) as f:
json.dump(
data,
f,
ensure_ascii=False,
separators=(“,”, “:”)
)
Confirm temporary files parse before replacing originals
for path, _ in outputs:
temp = path + “.cleanup”
with open(temp, encoding=“utf-8”) as f:
json.load(f)
Replace originals
for path, _ in outputs:
os.replace(path + “.cleanup”, path)
print()
print(“SUCCESS: UniFi registry records removed.”)
print(“Original files remain backed up in:”)
print(“/config/registry_backup_final”)
PY
In the end it removed:
Removing:
Config entries : 1
Live entities : 173733
Deleted entities : 155
Live devices : 57916
Deleted devices : 46
Device_registry 132.0k
core.entity_registry 1.5M
It asked me a lot of question before ChatGPT took this direction. It did want to modify the do the commands or manual options to search for entries Chat decided to go this route.
The size of your registry (173k entities / 115k devices), glad it is deleted.
I need to readd it so do as you posted to ignore random Mac Addresses