Unifi shows large number of devices and will not open in HA

Hello

Still a newbie however I was able to watch a video many months back on how to add my Unifi to my HA.

In the process, I only selected the devices I needed, mobile, watch, etc. Goal was to be able to trigger automation state when the mobile was away.

I only have 77 devices on my home Unifi and a few selected noted above, not all. Now it shows 57,000 devices and it will not open. I get a window that says WAIT or EXIT PAGE. Waiting never gets it to an open state to see anything.

Question:

  1. Is there another way to get into the Unifi add-on?
  2. Is there a way I can fix this?

Any suggestions would be welcomed. Thanks

Oh wow, that was quite a lot. Start by deleting the integration. Then you need to look through Unifi, do you have a lot of offline devices listed?


It will populate your integration with all entries in Unifi, even if they don’t exist on your network currently. For example are these entries from different test servers I’ve spun up the last months, they do not exist now. Did you inherit the Unifi controller from work (large network) or something?

Hi and thanks

It was weird. I had a few thousand show up in my Unifi then after a few days it self purged back to the 4 offline. Why that happened is beyond me doing a reboot on all my Unifi devices and other devices cleared it after a day or so.

Delete the entire intergration…

I have thousands of these listed below. I cannot even click on one to delete it although that would be impossible to do if I could. Locks up HA if I select one.

Is there another way to delete an intergration if I cannot click on it directly from Devices?

:laughing:
Probably your Iphone playing you it’s tricks

A lot of different MAC addresses, they seem generated. Have you tried playing around in the options of the integration? Or does it time out? There’s an option there to exclude private (randomly generated) MAC addresses, but 57K seems so wrong.

I had the same issue (delete not displaying as an option), but after restarting my browser I could scroll down to delete. Do it from the integration page, not devices.
Thanks @boheme61

I will look into that if I can get back in there. Thx

Thanks for sharing.

So I cannot get into the Unifi intergration to even access the option to delete.

Settings >> Devices & Services >> Intergration seen below like my first post. I assume since it is so many devices I will not cache to open. I keep getting the window to WAIT or EXIT waited over 30min and still did not open. Ran so long that my MacBook Pro M5 fan begins to run. I never hear the fan on my MBP M5.

I assume so many generate Mac Addresses that imported into HA before my Unifi purged them all back to only 4 in Unifi.

This is from the Integration window

I think it would be better if you remove the integration via safe mode…

If you have devices that you control that are set to generate random mac addresses (usually touted as some kind of privacy setting on wifi), it can also cause a large number of unused clients on the network and they’ll show up in the integration.

Also, if you spin up virtual systems with networking, those may be creating random mac addresses as well and also creating a number of old clients that aren’t reused.

I believe you can try cleaning them up in UniFi Network which would in turn (I think) cause them to dissapear in the integration once reloaded.

Thank you… I am happy for any response. I did clean up Unifi and it also did self purge of those ghost clients. Seems my HA is a one way transaction and will not self clean after Unifi has… still thank you!

Thank you for this post. Just seeing this getting home late tonight. I will try this. I have never put HA in safe mode so will be good to learn and hope also that this works. I will follow up.

@fleskefjes what option name or selection to keep it from generating random mac addresses?

Yes, that is correct. Deletions in Unifi does not delete in HA.

Under “more options”:

@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