Determine UniFi AP a device is connected to

I’m about to switch from openHAB to Home Assistant. I used to use UniFi for presence detection and I want to use it with Home Assistant, too.

So I have three UniFi AP’s, one in every floor of my house (only the basement is missing an AP atm). As the ceilings in my house are quite strong, an AP’s signal on one floor isn’t picked up by clients on the other floor. That’s the actual reason I have an AP per floor and it enables me to track my devices around the floors.

In openHAB I was able to check to which AP a device is connected to (see attached image). As far as my research has shown this isn’t possible yet with the UniFi WAP component, is it? (If the component maintainer reads this: Would be really nice if this could be added so one could use the attribute change as a trigger)

Any ideas how to implement such functionality?

I though about using the UniFi Direct component. I would have three device trackers and therefore three entities for each device. But I guess I will face situations where multiple entities for a device are ‘home’, e.g. when I walk from ground to first floor and my device is connected to one floor’s AP while the other floor’s AP still not considers me to be away.

You would need to modify unifi component in some fashion yo provide this detail.

FIND may work well for you if floor is your only concern. Actually FIND estimate indoor location very well

Modifiying the Unifi component seems not to be somethin I can do right away :slight_smile:

Finally “found” what you probably meant with FIND. Thanks for that suggestion. I will have a look into that when I find the time.

That’s it. Sorry I left no link.
I installed this in docker and had it running in about 5minutes a few months back. I don’t use it but remember it being able to locate me to room in my home when I had single uninstalled ap hanging off server rack for wifi

Seems like they introduced a load of attributes support in the Unifi WAP component in Home Assistant 0.68. I can now see an ap_mac attribute which holds the MAC address of the AP my device is connected to.

Of course I’m trying to use this for my automations so I have created some entities for easy determining the connected AP of my or my wife’s device. Just wanna share this piece of configuration in case someone needs it or can give hints for simplifying this (e.g. defining the AP list only once and re-use it in the value_template).

configuration.yaml

sensor:
  - platform: template
    sensors:
      # WLAN AP devices are connected to
      wlan_ap_device_one:
        friendly_name: WLAN AP Device 1
        value_template:  >
          {{ {"12:34:56:78:90:ab": "EG", "12:34:56:78:90:cd": "OG", "12:34:56:78:90:ef": "DG"}[states.device_tracker.device_one.attributes.ap_mac] | default("N/A") }}
      wlan_ap_device_two:
        friendly_name: WLAN AP Device 2
        value_template:  >
          {{ {"12:34:56:78:90:ab": "EG", "12:34:56:78:90:cd": "OG", "12:34:56:78:90:ef": "DG"}[states.device_tracker.device_two.attributes.ap_mac] | default("N/A") }}

automation.yaml (not tested yet, but may work this way)

# Turn light off when there's nobody on ground floor
- alias: absent_ground_floor
  trigger:
    - platform: state
      entity_id:
        - sensor.wlan_ap_device_one
        - sensor.wlan_ap_device_two
      from: 'EG'
      to: 'OG'
  condition:
    condition: state
    entity_id:
      - sensor.wlan_ap_device_one
      - sensor.wlan_ap_device_two
    state: 'OG'
  action:
    - service: homeassistant.turn_off
      entity_id: light.wohnzimmer

Nevertheless, as I know about the possibility of indoor positioning with utilizing the signal strength I still will try FIND3 and replace floors with concrete rooms :slight_smile:

1 Like

Hi, I’m looking into FIND3 but the website is not working and the app is not available anymore in Google Play. I downloaded it via f-droid but it seems it is built for an old Android version and maybe the GPS tracking won’t work well because the app doesn’t request permissions to get GPS access while in background.

The project seems a bit abandoned (the last commit was 4 years ago). Does anybody know if it really is and if there are any maintained alternatives?

Wow, it has been 6 years. I have to admit that I still track position via connected AP and never actually tried out FIND3. Guess I’m lazy :sweat_smile:

However, have a look at https://espresense.com/