UniFi Network integration - official thread

must confess I had the section of devices set to 3 weeks in my Unifi Client devices view, and when I set it to All (meaning no time selection) a few of the returning devices were listed.

However… it made me find several others, even older, that were once registered, but now long gone, so I manually deleted them from the Unifi interface with the Remove button

Even after having done so, and restarted the HA instance (effectively also reloading the integration) they all still were there…

Next I tried to (re-)enable those devices in the HA Integration entities interface, and waited the 30 secs, hoping this would force them to be reregistered of sorts, and when not available, mark them as truly deletable… still nothing,

another HA restart now made a lot of difference, because now, those were showing the red icons

indicating we can delete them from the HA system at last.

Just updated UDMP to new EA version of UnifiOS 4.0.3 and now the integration is unable to start. (same with Unifi Protect BTW).

Only thing in the HA log is “Unable to complete setup”. It does show my local user set up for this integration last login as expected.

Have double checked the account setup and even recreated to see if that would help, but no luck.

Probably shouldn’t have jumped so quickly to the EA version, but I suppose someone has to be the guinea pig.

Anyone else?

1 Like

Are you running a local user or a cloud user?

What error message are you seeing? Enable debug logging for extra information. As I’m not running EA it’s gonna be some time before I can try it myself

Yes, it is a local user.
This is what is in the logs. I will set up debug logging and see if I can get more information.

2024-04-29 11:41:22.602 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: {('unifi', 'd22fc47f1027dda5e30b158cdc2b78ee'): 1542328.627579097}
2024-04-29 11:42:22.852 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: {('unifi', 'd22fc47f1027dda5e30b158cdc2b78ee'): 1542328.627579097}
2024-04-29 11:43:23.094 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: {('unifi', 'd22fc47f1027dda5e30b158cdc2b78ee'): 1542328.627579097}
2024-04-29 11:43:27.978 WARNING (MainThread) [homeassistant.components.unifi] Exception on update maximum recursion depth exceeded
2024-04-29 11:43:27.980 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/rest/user received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/stat/device received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/rest/dpiapp received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/rest/dpigroup received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/rest/portforward received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/self/sites received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/stat/sysinfo received 401 Unauthorized
2024-04-29 11:43:27.981 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://10.0.0.1:443/proxy/network/api/s/default/rest/wlanconf received 401 Unauthorized
2024-04-29 11:43:27.982 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Default for unifi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifi/__init__.py", line 47, in async_setup_entry
    await hub.initialize()
  File "/usr/src/homeassistant/homeassistant/components/unifi/hub/hub.py", line 84, in initialize
    self.is_admin = self.api.sites[self.config.entry.unique_id].role == "admin"
                    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiounifi/interfaces/api_handlers.py", line 167, in __getitem__
    return self._items[obj_id]
           ~~~~~~~~~~~^^^^^^^^
KeyError: '6161e05bc3ecef069349f369'

There is a lot of stuff in the logs so not sure what would be helpful. Exacerbated by having Unifi Protect integration with similar issues. Below is a snippet of logs that look relevant. This block is repeated until it reaches login attempt limit. Password was in the clear, so took that out. Several IDs and tokens I took out as well, don’t know if they are sensitive, but erring on the side of caution.

Please let me know if there is anything specific you need.

Thanks

2024-04-29 12:40:16.273 DEBUG (MainThread) [aiounifi.interfaces.connectivity] Logged in to UniFi https://10.0.0.1:443/api/auth/login
2024-04-29 12:40:16.273 DEBUG (MainThread) [aiounifi.interfaces.connectivity] sending (to https://10.0.0.1:443/proxy/network/api/s/default/stat/sta) get, None, {}
2024-04-29 12:40:16.275 DEBUG (MainThread) [aiounifi.interfaces.connectivity] received (from https://10.0.0.1:443/proxy/network/api/s/default/stat/sta) 401 application/json <ClientResponse(https://10.0.0.1:443/proxy/network/api/s/default/stat/sta) [401 Unauthorized]>
<CIMultiDictProxy('Server': 'nginx', 'Date': 'Mon, 29 Apr 2024 17:40:16 GMT', 'Content-Type': 'application/json', 'Content-Length': '47', 'Connection': 'keep-alive', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-DNS-Prefetch-Control': 'off', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block', 'Set-Cookie': 'UOS_TOKEN=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; samesite=none; secure; httponly; partitioned')>

2024-04-29 12:40:16.275 DEBUG (MainThread) [aiounifi.interfaces.connectivity] sending (to https://10.0.0.1:443/api/auth/login) post, {'username': 'ha_network', 'password': 'XXXXXXXXX', 'remember': True}, {}
2024-04-29 12:40:16.582 DEBUG (MainThread) [aiounifi.interfaces.connectivity] received (from https://10.0.0.1:443/api/auth/login) 200 application/json <ClientResponse(https://10.0.0.1:443/api/auth/login) [200 OK]>
<CIMultiDictProxy('Server': 'nginx', 'Date': 'Mon, 29 Apr 2024 17:40:16 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Set-Cookie': 'UOS_TOKEN=XXXXXXXXXXX; path=/; expires=Mon, 29 Apr 2024 19:40:16 GMT; samesite=none; secure; httponly; partitioned', 'x-updated-csrf-token': 'XXXXXXXXX', 'x-token-expire-time': '1714419616468', 'X-Response-Time': '304ms', 'Access-Control-Allow-Credentials': 'false', 'Access-Control-Expose-Headers': 'Content-Disposition, Content-Range, Filename, Location, Range, Upload-Length, Upload-Offset, X-Connection-Type, X-Csrf-Token, X-File-Id, X-Token-Expire-Time, X-Updated-Csrf-Token', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-DNS-Prefetch-Control': 'off', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block', 'X-Csrf-Token': 'XXXXXXXXXX', 'Content-Encoding': 'gzip')>

2024-04-29 12:40:16.583 DEBUG (MainThread) [aiounifi.interfaces.connectivity] data (from https://10.0.0.1:443/api/auth/login) b'{"unique_id":"XXXXXXXXX","first_name":"ha_network","last_name":" ","alias":"","full_name":"ha_network","email":"","email_status":"UNVERIFIED","email_is_null":true,"user_email":"","phone":"","avatar_relative_path":"","avatar_rpath2":"","status":"ACTIVE","employee_number":"","create_time":1683130563,"login_time":1714409006,"extras":{},"username":"ha_network","local_account_exist":true,"password_revision":1714408661,"sso_account":"","sso_uuid":"","sso_username":"","sso_picture":"","uid_sso_id":"","uid_sso_account":"","uid_account_status":"","groups":[{"unique_id":"XXXXXXXXX","name":"UDMPRO","up_id":"XXXXXXXXXX","up_ids":["XXXXXXX","XXXXXXXXX"],"system_name":"UDMPRO / Home / UDMPRO","create_time":"2023-10-23T15:31:42-05:00"}],"roles":[{"unique_id":"XXXXXXXXXXXX","name":"Super Admin","system_role":true,"system_key":"super_administrator","level":2,"create_time":"2021-10-09T13:32:14-05:00","update_time":"2021-10-09T08:32:14-05:00","is_private":false}],"permissions":{"innerspace.management":["admin"],"network.management":["admin"],"protect.management":["admin"],"system.management.location":["admin"],"system.management.user":["admin"]},"scopes":["write:protect.viewer","write:protect.user:$","write:protect.user","write:protect.sensor","write:protect.schedule","write:protect.nvr","write:protect.light","write:protect.legacyUFV","write:protect.group","write:protect.doorlock","write:protect.deviceGroup","write:protect.chime","write:protect.camera","write:protect.bridge","view:user_timezone","view:user","view:unifi-os:user","view:systemlog","view:settings","view:role","view:permission:viewer","view:permission:admin","view:permission","view:os-menu:user","view:os-menu:system-log","view:os-menu:storage","view:os-menu:settings","view:os-menu:notify-settings","view:os-menu:map","view:os-menu:devices","view:os-menu:about","view:notification","view:location_policy","view:location_device","view:location_activity","view:location","view:identity:update","view:identity:settings","view:identity:services","view:identity:organization_info","view:holiday_timezone","view:holiday","view:group","view:door_group","view:controller:uid-agent","view:controller:talk","view:controller:protect","view:controller:olympus","view:controller:network","view:controller:led","view:controller:innerspace","view:controller:drive","view:controller:connect","view:controller:calculus","view:controller:access","view:cloud_access","view:app:users","view:app:uid-agent","view:app:settings","view:app:locations","view:access:user","view:access.visitor","view:access.systemlog","view:access.settings","view:access.schedule","view:access.policy","view:access.pin_code","view:access.open_api","view:access.nfc_card","view:access.face","view:access.device","view:access.dashboard","update:access.device","systemlog:user","systemlog:system","systemlog:network","systemlog:location","systemlog:connect","systemlog:access","send:identity:email","revoke:identity:credential","readmedia:protect.camera","readlive:protect.camera","read:protect.viewer","read:protect.user:$","read:protect.user","read:protect.sensor","read:protect.schedule","read:protect.nvr","read:protect.light","read:protect.legacyUFV","read:protect.group","read:protect.doorlock","read:protect.deviceGroup","read:protect.chime","read:protect.camera","read:protect.bridge","open:door","notify:user","notify:location","notify:access","manage:controller:talk","manage:controller:protect","manage:controller:olympus","manage:controller:network","manage:controller:led","manage:controller:innerspace","manage:controller:drive","manage:controller:connect","manage:controller:calculus","manage:controller:access","edit:user_timezone","edit:user","edit:unifi-os:user_group","edit:unifi-os:user","edit:systemlog","edit:settings","edit:role","edit:preview","edit:permission:viewer","edit:permission:admin","edit:os-settings:update_install","edit:os-settings:update_channel","edit:os-settings:support_file","edit:os-settings:ssh","edit:os-settings:send_diagnostics","edit:os-settings:restart","edit:os-settings:raid","edit:os-settings:poweroff","edit:os-settings:notify","edit:os-settings:hotspare","edit:os-settings:general","edit:os-settings:client_network","edit:os-settings:auto_update","edit:notification","edit:location_policy","edit:location_device","edit:location_activity","edit:location","edit:identity:update","edit:identity:status","edit:identity:settings","edit:identity:services","edit:identity:organization_info","edit:holiday_timezone","edit:holiday","edit:group","edit:feedback","edit:export_log","edit:door_group","edit:controller:uid-agent","edit:access:user","edit:access.visitor","edit:access.settings","edit:access.schedule","edit:access.policy","edit:access.pin_code","edit:access.open_api","edit:access.nfc_card","edit:access.face","edit:access.device","deletemedia:protect.camera","delete:protect.viewer","delete:protect.user:$","delete:protect.user","delete:protect.sensor","delete:protect.schedule","delete:protect.nvr","delete:protect.light","delete:protect.legacyUFV","delete:protect.group","delete:protect.doorlock","delete:protect.deviceGroup","delete:protect.chime","delete:protect.camera","delete:protect.bridge","delete:access.device","create:protect.viewer","create:protect.user","create:protect.sensor","create:protect.schedule","create:protect.liveview","create:protect.light","create:protect.group","create:protect.doorlock","create:protect.deviceGroup","create:protect.chime","create:protect.camera","create:protect.bridge","assign:role","assign:identity:wifi","assign:identity:vpn","assign:identity:talk","assign:identity:evstation","assign:identity:camera","adopt:access.device"],"cloud_access_granted":false,"only_local_account":false,"update_time":1683130563,"avatar":null,"nfc_token":"","nfc_display_id":"","nfc_card_type":"","nfc_card_status":"","role":"admin","roleId":"XXXXXXXXXXX":"XXXXXXXXXXX","isOwner":false,"isSuperAdmin":true,"isMember":false,"maskedEmail":"","accessMask":2014,"permissionMask":8028,"deviceToken":"XXXXXXXXXXX","ssoAuth":{}}'

Got something similar shared on github. In that case websocket connection failed. Might be some changes to websocket. Someone’s gonna need to deep into webbrowser developer and try to figure out the changes

That doesn’t sound good (you lost me at websocket ;). Saw a post on the unifi EA thread as well, so it isn’t just me.
I suppose I will look into downgrading until this gets sorted. Please let me know if there is anything I can do to help. But I am afraid my skills are a bit lacking.

1 Like

Link pls :+1:t2:

Link here https://community.ui.com/releases/UniFi-OS-Dream-Machines-4-0-3/90b24b90-8be8-4987-8d47-eb408eb07e45#comment/f8fc8a2a-cc59-4af5-bb71-5aa2296d3032

A little later in the thread poster got the unifi protect integration working. I re-authed that integration several times and it came back up.

Thinking there may be something cached that might be the issue I am in the process of completely removing the network integration and adding it back. Will report back if that has any effect.

Unfortunately no joy with the remove/replace of the network integration.

Fix for Unifi OS v4 is ready for 2024.5.1 release (Bump aiounifi to v77 by Kane610 · Pull Request #116639 · home-assistant/core · GitHub)

Thanks to Jasper Slits and Luke Collins for figuring out a fix

Hello,

sorry I missed those messages.
To recap :

  • you can only remove a device, not an entity (like device_tracker.xyz), BUT each entity is linked to a device and removing the device will remove the entities linked to it
  • you cannot remove a device if it has been active since Home Assistant startup (or Unifi integration reload), meaning the Unifi API sent an update on that device. This is to prevent untested side effects, and also because an active device would reappear next time you restart HA any way. If you try to remove an active device you will get this error in the logs: "Failed to remove device entry, rejected by integration"
  • Unifi does NOT send to Home assistant clients which are offline (at least from my testing). So those can be removed from HA, assuming they have been offline all the time since HA startup or since the last Unifi integration reload.

So to remove old clients (which appear as “offline clients” in Unifi console) you should restart HA (if it was not restarted since last time client was online) or reload the Unifi integration, and then you will be allowed to “Delete” device in HA.

Let me know if you think this does not work as expected in your case.

1 Like

thanks, I will need to check again, because I removed a lot the other day (as described in the how to above…)

I find the entities that get the numerical object_id’s or the unifi_default_ etc etc also very confusing, they can be a pain to find out to which device they belong…

most of those are always obsolete as I found out, but some of them do have a recent logon history, so I need to be careful.

something else:

these identically named entities created by the 2 integrations are a bit of a thing.

because:

so what are they… Is the flatliner effectively out of order? are they even the same sensor entity, albeit created by the 2 different integrations?

the same issue is for the memory utilization:

see what both integrations show:

when selecting the Udm Pro device in their listing. Somehow there’s a double entity for the both of them?

Not sure I am even sure we should see the UDM pro under the Unifi Protect integration in the first place…

You can open the entity and then click “Device info” to open the related device.
It’s the simplest way to make sure you remove the right device :
image

I don’t use Unifi protect so won’t be able to help there.
But it’s true that HA sometimes groups in the same device entities coming from different integrations, which can be great sometimes or quite confusing.

yes , showing the same integration twice doesnt help… but thats mostly because of network stuff, so not the real issue here, I am aware after all.

What is an issue are the 2 double entities in the listing. I cant delete either of them, as they apparently are provided by the integration. And the functional one is the one with the unset icon, the _2 .

so, I can rename the correctly named one to _dontuse, the _2 one to not using the suffix, and re-edit then icon…

then disable the _dontuse one…

really not sure what you are saying here…
I have the UDM pro, with a connected switch. My cameras are connected to that. It is promoted and sold as the most obvious and advertised box to have it like that, even includes the HDD for recording the streams.

How can you say it not the recommended way, if Unifi promote it as the recommended way?

could you please elaborate on that a bit?

I mean, those double sensors, are they now supposed to be there, or is it a fluke of the integration. Even though they are both listed under the same integration I take it it has nothing to do with me running the 2 integrations? There is after all no link to Protect, other than Integration Protect also showing the Integration Network there…

I really am confused now.

Unifi Protect showing all of my cameras as connected Ubiquiti devices, and the Udm Pro, while the Unifi Network shows all networked devices, includiung the ones by Ubiquiti, and Ubiquiti Networks.

those Ubiquiti Networks btw also list 2 UDMPro variant devices…

the top UDM-Pro is the one with all entities, the bottom one is without any entities…

lastly there’s is also this:

both without any entities. What devices are those?

Is that two integrations?

I believe those are 2 ‘services’
details:

wait, I now also see the 2 UDM pro entries have different Mac addresses,

ok thanks, just to be sure, they provide the same sensors of the hardware device they are running on. Which in my case is the same one and only Udm pro? In which case I can see the issue of the identical naming.

Or, is it uptime etc etc of the use of those integrations running on the devices.
in which case I wonder if it wouldn’t be nicer if the naming of the entities would be different.

Funny you would say that, because given the fact I have several cams, I get the notification in my Protect app on the phone, that I am nearing the max capacity, and better hardware is advised.

considering the memory utilization of 83% that might be a serious notification? Not sure ion I have encountered results of it in operating the apps or the integrations in HA for that matter, but there is quite the lag when opening the camera streams, which tbh I have always related to other stuff, compression and resolution and things like that.