Home Assistant release with the issue: 0.102.2
Last working Home Assistant release (if known):
Operating environment (Hass.io/Docker/Windows/etc.): Both HASS and the Unifi controller (v5.12.35) are running in docker on Ubuntu server v19.04. Here are the relevant entries from docker-compose.yaml
:
unifi:
container_name: unifi
image: jacobalberty/unifi:latest
restart: always
depends_on:
- mongo
networks:
- unifi
ports:
- '10001:10001/udp'
- '3478:3478/udp'
- '8080:8080/tcp'
- '8443:8443/tcp'
- '27117:27117/tcp'
volumes:
- ./unifi/data:/unifi/data
- ./unifi/log:/unifi/log
- ./unifi/cert:/unifi/cert
- ./unifi/init:/unifi/init.d
- ./unifi/var/run:/var/run/unifi
- /etc/localtime:/etc/localtime:ro
environment:
DB_URI: mongodb://mongo/unifi
STATDB_URI: mongodb://mongo/unifi_stat
DB_NAME: unifi
TZ: America/Chicago
UNIFI_UID: 999
UNIFI_GUID: 999
RUNAS_UID0: 'false'
hass:
container_name: hass
image: homeassistant/home-assistant:stable
volumes:
- ./hass:/config
- /etc/localtime:/etc/localtime:ro
restart: always
network_mode: host
environment:
TZ: 'America/Chicago'
devices:
- "/dev/ttyACM0"
Integration: https://www.home-assistant.io/integrations/unifi/
Description of problem: Devices tracked by the Unifi integration are marked as not_home
well before the amount of time specified by detection_time
has elapsed.
Problem-relevant configuration.yaml
entries and (fill out even if it seems unimportant): The Unifi component was configured via the Integrations menu, and detection_time
was set to 400
seconds using the integration's config options menu. I confirmed the setting was recorded in core.config_entries
:
I also attempted to increase detection_time
in configuration.yaml
see below) to see if that helped but this had no effect.
unifi:
controllers:
- host: localhost
site: !secret UNIFI_SITE_ID
detection_time: 600
Traceback (if applicable):
Additional information:
Having compared the state changes recorded in HASS' database to the connect/disconnect events reported by Unifi, it looks like tracked devices are marked as not_home
immediately, without taking detection_time
into account at all. Here's an example for one of the affected devices:
Unifi Events
Database
(Note: UTC times were converted to my local time zone to facilitate comparison)
Hey there @kane610, mind taking a look at this issue as its been labeled with a integration (unifi
) you are listed as a codeowner for? Thanks!
Thanks for reporting, I will look into this in a couple of weeks
I have been struggling with the same issue and for me it ended up being related to the Unifi Controller bug referenced in the is_connected method in the device_tracker.py file where a disconnected wireless device still shows it connected as a LAN device. This was also leading to some devices toggling between Home and Not_Home many times per hour. In that circumstance the current code will immediately mark the device as not connected and will hot honour the detection_time set by the user.
While a bit sloppy, I was able to fix my issue with some changes to the is_connected method to store a temporary timestamp if self.is_wired != self.client.is_wired and use that instead of last_seen. I have attached my updated code for the method, which has been working well for me for about a day now without any issues. This may not be the best way to solve the issue, but it does the trick for me and handles the Unifi Controller bug while still honouring the detection_time option set by the user.
@mjmccans great input!
I'm also seeing the exact same situation on my end. Same variables set in core.config_entries appropriately and everything. I'm also easily able to see when the device switches APs in the house that this has been happening and triggering the not_home on my device tracker / Person.
I'll have to try your change @mjmccans -- would hate to disable all my automations in the meantime. Would there be an alternative workaround?
Just an update -- I integrated @mjmccans fix into my local Home Assistant python Unifi script and I haven't been experiencing these disconnects in the past two days.
@rwarner that's great, I just pushed a fix based on @mjmccans fix. It will probably be a part of the 103 release
Was this fix already deployed?
I have been experiencing the same issue, devices that are disconnected that still show a 'ap_mac' instead of "None". Sometimes it works, others don't. I found this because my automations based on specific AP connections are messed up.
Yes this was released with HASS 0.103
them this is another bug. I'm I the only one with this broken behaviour?
Possibly Noone else has reported it
Most helpful comment
@rwarner that's great, I just pushed a fix based on @mjmccans fix. It will probably be a part of the 103 release