Unifi presence detection only works with multiple devices connected?

Hi everbody, I’m quite new to Home Assitant (running for a week now), impressive stuff!
I’m completely puzzled by the UniFi AP integration for presence detection though.

My configuration:

device_tracker:
  - platform: unifi_direct
    host: 192.168.X.XX
    username: USER
    password: PASS
    interval_seconds: 10
    consider_home: 180
    new_device_defaults:
      track_new_devices: true

So I noticed during the week that presence detection seemed a bit buggy now and then. Yesterday I came home after being away for more then 10 hours, finding out Home Assistant thought I was home all day. So I decided to take a closer look.

After a reboot of Home Assistant it seemed to work again, but when testing later that evening, it turned out it stopped working again. I have 3 devices connected to my WiFi on a regular basis: My PC, my Laptop and my Phone. The Phone is used for presence detection for my user.

During my test last night:

  • Laptop away, PC away, Phone home.
  • Disconnected WiFi on my phone > after 1h it still showed home
  • Turned on PC > after 30m it still showed away
  • Turned on Laptop > within seconds it showed my laptop at home, PC at home and after 3m phone away??

Then I switched WiFi on and off on my PC and Phone a few times, Home Assistant registered it every time. But as soon as I turned off my laptop, the presence detection completely stopped working again.

This morning, I decided to try it again in the same way, thinking somehow my laptop was the key. So:

  • Turned off WiFi on my phone (only connected device) > nothing happens, for several hours
  • Turned on my PC > within seconds PC showed up as home, 3 minutes later Phone switched to away.
  • Turned on WiFi on phone again > Phone registered home
  • Turned off WiFi on PC > PC registered away after 3 minutes
  • Turned off WiFi on Phone > nothing happens
  • Turned on Laptop > Laptop registered home, 3 minutes later Phone away
  • Turned on WiFi again on Phone > Phone at home
  • Repeat, repeat

It also happens the other way around:

  • PC and Phone connected, home
  • Turned off WiFi on phone > phone away
  • Turned off WiFi on PC > nothing happens

Somehow, to me, it looks like the presence detection workes when multiple devices are connected to WiFi, but completely stops working when only one devices is connected and disconnects after a while. Unfortunately this is often the case with my Phone.

Is this a known issue? Am I crazy?

Relevant background info:

  • Home Assistant installed on a existing RaspberryPi with Raspbian
  • Unifi controller is installed on my Laptop, but was never running during these tests.

This is my config, has always worked very well.

I have found through playing about that when the interval_seconds is too low, I get issues. Perhaps look at dropping your consider_home time as well. Do you really want it to wait 3 minutes to see you are home?

- platform: unifi_direct
  host: 192.168.1.200
  interval_seconds: 30
  consider_home: 30
  username: MYLOGIN
  password: MYPASS
  new_device_defaults:
    track_new_devices: false

consider_home workes exactly the other way around: after you disconnect from WiFi it waits 3 minutes before it considers you away from home. This is fine, as I don’t need my house to shut down when my phone disconnects very short. Arriving home is registered within seconds with this settings.

Is your situation the same? Are you the last device leaving WiFi when leaving home? So nothing is connected to WiFi while you are away? That seems to be the cause of the issue in my case.

Edit: I changed the interval_seconds to 30, but this makes no difference to the situation.

Yeah, my bad. It’s been ages since I looked at it tbh.

Mine takes about 30secs to see me home once I connect to the WiFi. My wife and I are both tracked in this way while home (using life360 while away), and don’t see the issue you are describing.

What does your known_devices.yaml file look like for the items you want to track. As an example, these are our two phones.

kym:
  hide_if_away: false
  mac: 64:c2:de:21:XX:XX
  name: Kym
  picture:
  track: true
  vendor: LG

jason:
  hide_if_away: false
  mac: b6:ae:ee:01:XX:XX
  name: Jason
  picture:
  track: true
  vendor: Xiaomi

and then for items we don’t want tracked, change to track: false

yeelight_steps:
  hide_if_away: false
  mac: 28:6C:07:B1:XX:XX
  name: Yeelight Steps
  picture:
  track: false
  vendor: XIAOMI Electronics,CO.,LTD

If you don’t need to track something as home/away, then mark it false.

I would also suggest running the Unifi Controller on your Pi. If you are using Home Assistant Supervised, install the add-on from the store. Take a backup from the current controller and restore it to the new one.

If you don’t have Home Assistant Supervised and are running Docker or Venv, install it using Docker. It’s better to have it always running. I would hazard a guess that the controller not running all the time is contributing to the issue.

My known_devices looks like this. I deleted it yesterday before starting testing again, to make sure it’s all original auto generated

Pixel3a:
  icon:
  mac: xxxxxxxxx
  name: Pixel3a
  picture:
  track: true

xps_13:
  icon:
  mac: xxxxxxx
  name: XPS-13
  picture:
  track: true

pc:
  icon:
  mac: xxxxxxxxxxxxx
  name: PC
  picture:
  track: true

I don’t know if I’m running Supervised? Used this manual to install HA on an existing Raspberry that has several other tasks.

I like to avoid to install the full controller as long as possible, as I have no use for it and don’t want to maintain a lot of software I won’t use anyway on my Pi. That’s why I did pick unifi_direct, as it should work without controller.

Ran a few tests again since this morning and the problem for sure seems to be presence detection does no longer work when there’s only 1 device connected to the Unifi AP. It won’t detect when that last device disconnects.

Nobody else who has seen this issue before?

I tried running the UniFi Controller permanently, but the load on my Raspberry becomes way to high when it’s switched on.

So if there’s anybody who knows how to fix the unifi_direct version?