Home Assistant Community

Additionally Track UniFi Devices with UniFi Device Tracker

#1

I am currently using the UniFi Device Tracker component to track when networked devices go offline. This is working well for all of the non-UniFi equipment on my network. However, it doesn’t appear that the device tracker currently tracks the UniFi hardware itself.

  • The UniFi hardware didn’t automatically get added to known_devices.yaml
  • When manually added to known_devices.yaml, their state is “not_home” and the source is “null”, where as the other devices have a source of “router”.

In the UniFi Controller, UniFi hardware is listed under the Devices tab and does not appear in the Clients tab. All hardware that appears in the Clients tab does appear to get tracked.

I’d be happy to test, if someone knows how to code the update!

0 Likes

#2

what about using the ping or nmap device tracker?

0 Likes

#3

Tried nmap last night and I couldn’t get it to return devices from different VLANs, even though my HA server has access to those other VLANs. I haven’t tried ping as-of-yet. Started trying snmp, until I realized the version of pfSense I’m running doesn’t support the encrypted version 3. Upgraded pfSense tonight, because the latest version is supposed to support it, but I don’t see any new settings added to it’s snmp abilities.

I’m sure I can figure out an alternative, but the UniFi device tracker has gotten me the closest so far. Seems strange that it tracks everything except its own hardware, even though they are devices on the network too.

0 Likes

#4

Unifi component likely won’t track because.it only looks at client devices.
You could possible create custom component if the python package is uses supports tracking hardware

Ping should work
Nmap should work as well if it can see vlan.

0 Likes

#5

I’ll give nmap another go tonight. See if I can find the cause of it’s inability to find MAC addresses for devices on different VLANs than the HA server is on.

0 Likes

#6

Sorry for the bump for such an old post. I revisited this after months of settling with the ping workaround and found the following to work:

Inserted at line 97 of homeassistant/components/device_tracker/unifi.py

        try:
            clients_ap = self._controller.get_aps()
        except APIError as ex2:
            _LOGGER.error("Failed to scan aps: %s", ex2)
            clients_ap = []

        clients.extend(clients_ap)

While the method get_aps(), according to the api documentation here https://github.com/finish06/pyunifi would return a list of all APs (access points), looking at the source code, it returns devices (eg gateway, switches and accesspoints) as defined in the UniFi Controller.

The names of the UniFi devices defaulted to their respective mac addresses, which is easy enough to override with a friendly name.

Hope this helps. I’ve yet to setup a full dev environment and go through the entire development process (don’t have the time at the moment) but hopefully this can help one of the full fledged developers.

1 Like

#7

Thank for the old bump and sharing knowledge - With your help, I successfully created a custom component that tracks both clients and all my ubiquiti gear (AP names display correctly, all other gear shows MAC addresses for names).

USAGE:

  1. Copy my custom Unifi custom component to your HA’s custom_components/my_unifi/ directory
  2. Add this component as a device_tracker with your desired options/settings (mine listed below):
device_tracker:
    - platform: my_unifi
      host: !secret unifi_host
      port: !secret unifi_port
      username: !secret unifi_username
      password: !secret unifi_password
      verify_ssl: False
      site_id: default
      track_new_devices: no
      interval_seconds: 2
      consider_home: 180
      monitored_conditions:
        - ap_mac
        - essid
        - last_seen
        - first_seen
        - ip
        - hostname
        - is_guest
1 Like