Unable to connect to UniFi controller 5.10.25 using HA 0.95.x

I am having issues with connecting HA to my UniFi controller after I upgraded it to 5.10.25 (running on a CloudKey, but not sure that is significant to this issue).

I am able to login to the UniFi interface successfully. I have double/triple/quadruple checked the details in my HA config files and they are correct. HA reports “Failed to connect” in the log. Presence detection is showing all devices as away, even though they listed as connected in the UniFi interface.

019-07-01 23:08:21 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi controller at [IPAddressRedacted]
2019-07-01 23:08:21 ERROR (MainThread) [homeassistant.components.unifi.device_tracker] Failed to connect to Unifi: 
2019-07-01 23:08:21 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy

No other changes other than upgrade from 5.10.23, running Hassio 0.95.4 on a Raspberry Pi 3B+.

I was using the UniFi device tracker, but tried converting over to use the UniFi Controller integration, and I got nothing whatsoever in the logs, but presence detection still reporting all devices as away.

I have just now downgraded UniFi back to 5.10.23 (technically it was a fresh install and then restoration from backup, heart in mouth whilst doing it), reverted to using the UniFi device tracker, restarted HA to allow the UniFi component to reconnect, and it all came good again.

The integration still does does not work. No entries in the log file that I could discern - the same results as under 5.10.25 - all devices marked as away.

I only have the one CloudKey, and do a lot of automations with presence, so can’t really play around with it all that much before annoying wife and kids (they are easily annoyed :wink:)

I am just relieved it is now back up and running.

The integration is only for controlling poe devices right now. It is decoupled from the device tracker atm. I’m working on combining them

@Robban Thanks for the clarification.

What you have stated is not immediately obvious from the documentation.

Currently this implementation only exposes POE control for networked devices. Device tracker implementation is not using the same code base

I assume that is meant to make it clear, but it didn’t for me on first reading.But at least I now know why the integration was not working as I expected - my unrealistic expectations.

Now only the “Failed to connect” issue on 5.10.25 is left. If anyone else is running UniFi and is able to see if the problem can be reproduced it would be good. It is easy enough to downgrade afterwards if you have SSH access and a valid backup. I followed the accepted solution in the following link and adjusted the command to reinstall for the version I need.

https://community.ui.com/questions/Unifi-Cloudkey-UCK-Cannot-downgrade-from-5-9-29-to-5-7-23/a5cedfbf-b31d-435d-8582-ef724b299353

I restarted my home assistant multiple times yesterday and it reconnected fine to 5.10.25 so it is weird that you got that behavior. :frowning:

FWIW: I’m also on 5.10.25 (Cloudkey) and device_tracker is working fine for me too.

OK. Thanks for getting back to @Robban and @jparthum. I might have to give it another try, but might leave it a few days. At one stage there I thought I may have bricked my CloudKey, so just want to sit on this for a bit until I feel a little more adventurous.

2 Likes

… and got a connection error on a restart this morning! Ahhh! Seems to be an intermittent problem. HA 0.95 introduced a change to the way the Unif compoent works. Refer https://github.com/home-assistant/home-assistant/pull/24149

There is a comment down below by use @patrik about a possible issue with dependencies. I don’t know enough about how these work, but could this be causing the issue?

I did upgrade to HA 0.95 on Saturday, and noticed the problems on Sunday, so it could be possible that I just missed it when checking things out. I did have to change a few things due to breaking changes when I went to 0.95, so might try to downgrade and change everything back.

1 Like

https://github.com/home-assistant/home-assistant/issues/24895

Presuming that is the culprit here.

OK, so downgraded from 0.95.4 to 0.94.3 and it is now working flawlessly. I have restarted HA about 10 times and have not been able to reproduce the issue. I would summize from this that is highly likely caused by the changes introduced in 0.95 release.

I had an issue connecting to my Unifi Controller on a CK 2 (running 5.10.25) after upgrading HA to 0.95.4 from 0.94.4 on Saturday.
The issue also prevented me logging into my unifi controller (repeated “session expired” message from unifi.ubnt.com) until I stopped HA.
However after rebooting my HA host the problem resolved itself.

It may be worth noting that I use a dedicated HA user account on the controller with read-only admin access.

The issue seem to happen on restart of hass. Stopping and starting passes the configuration validation.

OK, so upgrade to 0.95 - take II.

I upgraded to 0.95.4. It successfully connected to UniFi controller post the upgrade. I then made a change to fix a Synology DSM breaking change (changed entity_namespace to name), and on the subsequent HA restart, it failed to connect.

2019-07-03 21:08:18 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi controller at 192.168.0.4
2019-07-03 21:08:18 ERROR (MainThread) [homeassistant.components.unifi.device_tracker] Failed to connect to Unifi: 
2019-07-03 21:08:18 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy

I then SSH’ed in and did a hassio ha stop and then a hassio host reboot. After that, it successfully reconnected. I restarted again, and it failed, same error as above. It also displayed a persistent notification in the UI.

07%20pm

Another restart through the GUI and it connected successfully. Quite a few subsequent restarts have all connected successfully.

@Robban - I am hoping that this is helping with investigations and troubleshooting - I believe that you are a code owner of the component. It just appears to be a little hit and miss whether it connects or not for some reason.

… and the saga continues.

Updated UniFi to 5.10.25 again. Unable to connect to UniFi… at all … even after a HA stop and a host restart.

Downgraded back to HA 0.94.4 and it is operating flawless. Only change that was required to revert was changing the Synology DSM sensor to use entity_namespace config variable instead name variable.

At this point, I think I just need to show patience with 0.95.x until such a point as it become a bit more stable.

Would you mind trying out using the unifi integration? Right now it runs separate from device tracker but Im working on combining them to one solution. If the integration works then at least it should be smooth sailing forward. Else its a bigger issue and I need to delve into it.

Sure. Happy to give it a go if you can let me know how. I presume that there is some changes to implement a new UniFi integration???

FYI, I have just copyied the 0.94.4 synologydsm source into a custom component, and upgraded to the latest version of HA. So I will be running HA 0.95.4, but with a 0.94.4 synologydsm component. It seems to be working fine so far.

I know this is a bit of a kludge, but I hate getting too far behind the latest release and then having to deal with multiple iterations of breaking changes. This way, I can keep on upgrading to the latest release, but keep the synologydsm component from 0.94.x which works well.

I understand precisely.

Just head on over to configuration -> integrations and hit + and select UniFi

You need to make sure that the user has admin privileges for the integration. This will change to support read only when I merge device tracker into the integration

OK. I have configured the integration successfully.

And none of the previous issues are appearing?

Seems to be behaving itself. Running HA 0.95.4, it has successfully survived 3 HA restarts so far. I will keep a close eye on it and do some regular reboots over the next couple of days and report back.

I am really interested to know why having the integration configured would make a difference.

It is probably due to how hass loads platforms or handles dependencies