home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.39k stars 30.65k forks source link

Unifi integration shows device_tracker status for wi-fi devices incorrectly #104576

Closed Spirituss closed 5 months ago

Spirituss commented 11 months ago

The problem

Wi-fi esp device added as "tracked" in Unifi integration. It is permanently online, Unifi controller web site shows it as online device, but HA integration shows "offline" all the time. The same situation is for many devices.

Снимок экрана 2023-11-27 в 10 03 18

What version of Home Assistant Core has the issue?

core-2023.11.3

What was the last working version of Home Assistant Core?

Unknown

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Unifi

Link to integration documentation on our website

https://www.home-assistant.io/integrations/unifi/

Diagnostics information

I find HA devices in Unifi API info ($ip/api/s/default/stat/device/) and see the following client attributes, which have correct (updated) values, while HA shows "not home" all the time:

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 11 months ago

Hey there @kane610, mind taking a look at this issue as it has been labeled with an integration (unifi) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `unifi` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign unifi` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


unifi documentation unifi source (message by IssueLinks)

Kane610 commented 11 months ago

Please share a debug log

Spirituss commented 11 months ago

Please share a debug log

Here config_entry-unifi-redacted.json.txt

Kane610 commented 11 months ago

What version of unifi are you running

Spirituss commented 11 months ago

What version of unifi are you running

HA official Add-on, the last available version: UniFi Network Application Current version: 3.0.0

Kane610 commented 11 months ago

That's the addon version not the software version

Spirituss commented 11 months ago

That's the addon version not the software version

Network 8.0.7

Kane610 commented 11 months ago

Can you enable debug logging for the integration and share the logs?

a-r-j-a-n commented 10 months ago

Having the same issue.

HA Core 2023.12.2 Unifi Network Network 8.0.24

States in Unifi Network do show correct.

[Solved for me] Edit: The logs showed my user couldnt login anymore. Maybe because of new Unifi OS password length requirements. Changed the password to a longer (12+) length and updated the integration. Now it works again.

Kane610 commented 10 months ago

Having the same issue.

HA Core 2023.12.2 Unifi Network Network 8.0.24

States in Unifi Network do show correct.

[Solved for me] Edit: The logs showed my user couldnt login anymore. Maybe because of new Unifi OS password length requirements. Changed the password to a longer (12+) length and updated the integration. Now it works again.

Do you have the log output still? Would be nice to improve how to communicate things like that

arsaboo commented 10 months ago

I don't think it's the password. I'm facing the same issue and I have a long password. Also, the integration connects on HA start and when I click reload on the integration.

This is all I see in the logs:

Error connecting to the UniFi Network at 192.168.2.1:

Kane610 commented 10 months ago

Error connecting to the UniFi Network at 192.168.2.1:

Try restarting UniFi

arsaboo commented 10 months ago

The devices keep going offline. There is something wrong with this integration. I am not sure if Unifi AP is the answer (since I have 3 APs).

pascal-de-ladurantaye commented 10 months ago

I also experience a client device tracker that keeps reverting to away 5 minutes after reloading the integration which is the only way to properly get the real state that I've found. Maybe I should create an automation that reloads the integration every 2 minutes to keep a stable device tracking solution? I'm mostly joking but only mostly

pascal-de-ladurantaye commented 10 months ago

I might have some time for debugging over the Holiday break. Hopefully I'll find something

Schwebebahn commented 10 months ago

same problem here. I have changed the password, removed and added the Dream Router again, but it did not help.

pascal-de-ladurantaye commented 10 months ago

After setting up a development environment to debug the issue in dev mode, I noticed that I wasn't able to reproduce it. The only difference was the integration setup. In my Dev environment, my user wasn't setup in advanced mode which resulted a simplified setup flow for the Unifi Network integration. Armed with this knowledge, I removed the integration in my prod environment, restarted HA, made my user a non-advanced one and re-created the integration along with my device trackers. I'm happy, and confused, to report that the device tracking has been working as expected since then. I suspect it's an issue with having the previous integration config contain specific SSIDs to track on or because I added the tracking clients without an accompanying network block switch config (I noticed that the switch was still added to my device even if not requested) I'll monitor my new setup and report back if it suddenly stops working again

pascal-de-ladurantaye commented 10 months ago

It happened again! At exactly 11PM which is pretty specific. Could it be a timezone issue? Both my Unifi controller and my home assistant are configured with the correct timezone though (UTC-5 Toronto) but I don't think they are configured to use any specific NTP server.

pascal-de-ladurantaye commented 10 months ago

I'm still not able to reproduce the issue in my dev environment so my new assumption is that it might be already fixed on the dev branch. I'm currently attempting to override the unifi component with the latest dev version of it using a custom_component.

The only major-ish difference between the 2 versions is https://github.com/home-assistant/core/pull/105691 which does touch device trackers. I'll report tomorrow.

Note that I've also confirmed that both versions are using the same id and unique id.

ChrisMZ commented 10 months ago

Same issue here, tracked WiFi device keeps returning to away state in HA even though its online the entire time. Seems to happen at random. Reloading the integration restores the tracking for some time. image

edit: Tracking was working fine before I upgraded from USG (Network 8.0.24) to UDM-Pro (Unifi OS 3.2.7 / Network 8.0.24) on thursday, including a reinstall of the HA unifi integration.

vcdx71 commented 10 months ago

I'm still not able to reproduce the issue in my dev environment so my new assumption is that it might be already fixed on the dev branch. I'm currently attempting to override the unifi component with the latest dev version of it using a custom_component.

The only major-ish difference between the 2 versions is #105691 which does touch device trackers. I'll report tomorrow.

Note that I've also confirmed that both versions are using the same id and unique id.

Just curious how your dev branch is holding up? Still working?

pascal-de-ladurantaye commented 10 months ago

Sorry, with holiday gatherings, it slipped my mind to report here. Latest dev version in production shows the same issue. Like others said, I see correct device tracking reports for short while after a reload and then everything changes to away at the same time.

I had been meaning to look into ESPresence for a while now and I'm going to experiment with it today. At least as a temporary crutch to the Unifi integration.

vcdx71 commented 10 months ago

Thanks for the update. Seeing the same behavior. Seems everyone that is having the issue is on Unifi OS 3.2.7, seems something in this release broke the integration.

pascal-de-ladurantaye commented 10 months ago

Likely, I'm just not able to reproduce the issue in dev which makes me doubt that it's on Ubiquiti's side. Maybe it's related to request volume? I have the unifiprotect integration running in my real environment and a lot more devices being tracked due to the various other integrations I have running there as well.

pascal-de-ladurantaye commented 10 months ago

If new reports are coming in that it was fine before updating to 8.0.24 while running 2023.12.x in Home Assistant, then, yeah, most likely a change in the Network application causing this. In my case, both updates happened on the same day.

pascal-de-ladurantaye commented 10 months ago

BTW, I said previously that I was mostly joking talking about reloading the integration every so often... well I did it now. That might be an ok enough crutch for now

alias: Reload Unifi integration every 3 minutes
description: ""
trigger:
  - platform: time_pattern
    minutes: /3
    hours: "*"
    seconds: "0"
condition: []
action:
  - service: homeassistant.reload_config_entry
    data:
      entry_id: 1acf49556e38bed1f9a1818ce85b5fc1
mode: single

The entry ID can be found in .storage/core.config_entries. Find the one for the unifi integration.

Only downside I found so far is that the device trackers become unavailable for a couple seconds every reload

vcdx71 commented 10 months ago

Yeah I'm doing the same, just watching the state of one of my networks and when the client count is zero then reloading..

jaberhadi commented 10 months ago

I have the same problem , keeps reverting to away 5 minutes after reloading. Attribute ap_mac of device_tracker disappears after 5 minutes

margatemarcel commented 10 months ago

I have the same issue (since upgrading my UDM-Pro to Unifi OS 3.2.7 / Network 8.0.24). 2 main device trackers appear after a HA reboot for a few hours max before dropping offline again.

fxfitz commented 10 months ago

Adding another +1 here! Seems to be the same behavior, and versions, that everyone else is reporting.

jaberhadi commented 10 months ago

I have the same problem , keeps reverting to away 5 minutes after reloading. Attribute ap_mac of device_tracker disappears after 5 minutes

I can confirm that my problem has been solved after I restart all Unifi AP then UDM-Pro.

Edited : Devices go offline after about 12hrs

Screenshot 2023-12-29 at 11 52 16 PM
Kane610 commented 10 months ago

I've been running a test for 5 hours which didn't replicate this issue on UniFi OS 3.1.16 and Controller 8.0.24

Screenshot 2023-12-28 at 22 52 55

I will upgrade to latest stable UniFi OS 3.2.7 and see if that changes

The logics for a client tracker availability is quite simple to view in the logs

It validates if its a wired or wireless client, then if wireless it will check against the ssid filter, and finally it will validates timestamp of reportedly last seen and makes sure its within the configured detection time limit (default 300 sec).

arsaboo commented 10 months ago

If it matters, I am on 3.2.7. I don't know if the issue was present in 3.1.16, but on 3.2.7 and controller version 8.0.24 it is 100% reproducible. Devices go offline and stay offline after a few minutes.

pascal-de-ladurantaye commented 10 months ago

I can confirm that my problem has been solved after I restart all Unifi AP then UDM-Pro.

Following this recommendation, I restarted all my unfi devices and, 3 hours in, no new false disconnects to report. Potentially a bug on Unifi's part after the upgrade that fixes itself with a second reboot (first one being the upgrade itself)

Kane610 commented 10 months ago

I can confirm that my problem has been solved after I restart all Unifi AP then UDM-Pro.

Following this recommendation, I restarted all my unfi devices and, 3 hours in, no new false disconnects to report. Potentially a bug on Unifi's part after the upgrade that fixes itself with a second reboot (first one being the upgrade itself)

That is indeed the most common remedy. I should add that to the documentation on things to do before reporting an issue 😅

vcdx71 commented 10 months ago

Reboot doesn’t solve this. It’s only temporary like reloading the integration. I’ve gone as long as 5 hours without issue, but it always comes back.

smitjohan commented 10 months ago

Same problem here. Running the unifi controller as an add on (8.0.24.0) and sometimes the device_tracker status works for a day, then it needs another restart. I'm using the the reload integration script from pascal-de-ladurantaye now, that works, but is only a work-around of course.

casaintelegente commented 10 months ago

Hi guys, plot twist. I have been having the same problem like everyone else and I have been monitoring this thread ever since. I have a UDMSE and I did a RMA and got a replacement UDMSE because my current UDMSE was one of the faulty ones with the power failure issue.

I backed up the old and restore the settings on the new one and the presence detection has been working since. No issues at all.

pascal-de-ladurantaye commented 10 months ago

24h without issues since doing the full restart of all Unifi devices. I've never went this long without the issue since the upgrade

Kane610 commented 10 months ago

I've upgraded to UniFi OS 3.2.7 and test has been running positive for 6 hours

Kane610 commented 10 months ago

I've upgraded to UniFi OS 3.2.7 and test has been running positive for 6 hours

It ran for 9 hours before I turned it off and the iPhone tracker was active the whole time. Running a new test today with my UDMP tracker.

ChrisMZ commented 10 months ago

@Kane610 just to let you know, the longest time it worked for me after a reload was ~14h before it stopped tracking again. image This is so annoyingly random xD

rajil commented 10 months ago

In my case the device shows up as online even when it is turned off. In unifi webpage it is correctly marked as offline. The unifi controller is 8.0.24.

arsaboo commented 10 months ago

24h without issues since doing the full restart of all Unifi devices. I've never went this long without the issue since the upgrade

Looks like the restarts helped. Will update again if it continues to work.

arsaboo commented 10 months ago

24h without issues since doing the full restart of all Unifi devices. I've never went this long without the issue since the upgrade

Looks like the restarts helped. Will update again if it continues to work.

Ok...it did not work. It stayed Home for some time, but after I went out and came back, it never turned to Home.

megakid commented 10 months ago

Also getting this with HA 2023.12.3 - running a UDM-SE with latest OS (v3.2.7) and Network app (8.0.24)

Kane610 commented 10 months ago

I can't reproduce this issue, and logs provided from affected users don't show anything either so its kinda problematic... Someone said upgrading to UniFi Network app release candidate 8.0.26 resolves it, if someone want to try that it would be nice to know if it actually solves the issue.

jaberhadi commented 10 months ago

I can't reproduce this issue, and logs provided from affected users don't show anything either so its kinda problematic... Someone said upgrading to UniFi Network app release candidate 8.0.26 resolves it, if someone want to try that it would be nice to know if it actually solves the issue.

I already install release candidate 8.0.26 , didn’t resolve this issue

Kane610 commented 10 months ago

I already install release candidate 8.0.26 , didn’t resolve this issue

Thanks for testing

vcdx71 commented 10 months ago

I set up a new HA instance with 2024.1b5 and only loaded the UniFi Network integration and it only lasted about an hour as well. image The iPad above has been connected for ~24 hours.. image