Additionally Track UniFi Devices with UniFi Device Tracker

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!

what about using the ping or nmap device tracker?

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.

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.

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.

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

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

Hello, old thread but relevant subject.

Just wanted to say that this has been merged and will be available with HASS 0.97

Port code from Synology SRM to UniFi
can some one help me to port the code beneath from https://github.com/i00/Chatter/issues/1
to a card usefull for UniFi users.

card:
  show_header_toggle: false
  title: Devices
  type: entities
filter:
  include:
    - attributes:
        scanner: SynologySrmDeviceScanner
      entity_id: device_tracker.*
      options:
        entities:
          - attribute: mac
          - attribute: ip_addr
          - icon: 'mdi:ethernet'
          - icon: 'mdi:wifi-strength-1'
          - icon: 'mdi:wifi-strength-2'
          - icon: 'mdi:wifi-strength-4'
          - icon: 'mdi:gamepad-variant-outline'
          - icon: 'mdi:cellphone-android'
          - icon: 'mdi:television'
          - icon: 'mdi:dlna'
          - icon: 'mdi:desktop-tower'
          - icon: 'mdi:nas'
          - icon: 'mdi:laptop-chromebook'
          - icon: 'mdi:tablet-android'
          - icon: 'mdi:cctv'
          - icon: 'mdi:printer'
          - icon: 'mdi:router-wireless'
        icon: 'mdi:devices'
        secondary_info:
          attribute: band
        show_state: false
        style: >
          {% set lMAC = 1 %} {% set lIP = 2 %} {% set iEthernet = 3 %} {% set
          iWiFiBad = 4 %} {% set iWiFiOK = 5 %} {% set iWiFiGood = 6 %} {% set
          iGame = 7 %} {% set iPhone = 8 %} {% set iTV = 9 %} {% set iDLNA = 10
          %} {% set iDesktop = 11 %} {% set iNAS = 12 %} {% set iLaptop = 13 %}
          {% set iTablet = 14 %} {% set iCamera = 15 %} {% set iPrinter = 16 %}
          {% set iRouter = 17 %}
          div.entity:nth-child({{lMAC}}),div.entity:nth-child({{lIP}}) {
            margin-right:0;
          } div.entity:nth-child({% if state_attr(config.entity, 'ip_addr') ==
          '' %}{{lIP}}{% else %}{{lMAC}}{% endif %}) {
            display: none !important;
            visibility: hidden !important;
            position: absolute !important;
          } .secondary {
            padding-left:16px;
          } {% if state_attr(config.entity, 'is_wireless') == false %}
          .secondary {
            visibility: hidden;
          } .secondary:before {
            content: 'Ethernet';
            visibility: visible;
          } {% else %} .secondary:after {
            content: ' (Level {% if state_attr(config.entity, 'mesh_node_id') == 0 %}1{% elif state_attr(config.entity, 'mesh_node_id') == 4 %}3{% elif state_attr(config.entity, 'mesh_node_id') == 3 %}4{% else %}?{% endif %})';
          } {% endif %}


          div.entity:nth-child({{iEthernet}}),div.entity:nth-child({{iWiFiBad}}),div.entity:nth-child({{iWiFiOK}}),div.entity:nth-child({{iWiFiGood}})
          {
            --mdc-icon-size: 16px;
            position: absolute;
            top: 8px;
            left: 50px;
            visibility: hidden;
          } div.entity:nth-child({% if state_attr(config.entity, 'is_wireless')
          == false %}{{iEthernet}}{% elif state_attr(config.entity,
          'rate_quality') == 'low' %}{{iWiFiBad}}{% elif
          state_attr(config.entity, 'rate_quality') == 'middle' %}{{iWiFiOK}}{%
          elif state_attr(config.entity, 'rate_quality') == 'high'
          %}{{iWiFiGood}}{% endif %}) {
              visibility: visible;
          } :host>state-badge {
            {% if state_attr(config.entity, 'dev_type') != 'others' and state_attr(config.entity, 'dev_type') != 'default' %}
              visibility: hidden;
            {% endif %}
          } div.entity:nth-child(n+{{iGame}}{# << This is the first icon for the
          device type #}) {
            position: absolute;
            top: 0px;
            left: 8px;
            visibility: hidden;
          } div.entity:nth-child({% if state_attr(config.entity, 'dev_type') ==
          'gamebox' %}{{iGame}}{% elif state_attr(config.entity, 'dev_type') ==
          'phone' %}{{iPhone}}{% elif state_attr(config.entity, 'dev_type') ==
          'tv' %}{{iTV}}{% elif state_attr(config.entity, 'dev_type') == 'dlna'
          %}{{iDLNA}}{% elif state_attr(config.entity, 'dev_type') == 'computer'
          %}{{iDesktop}}{% elif state_attr(config.entity, 'dev_type') == 'nas'
          %}{{iNAS}}{% elif state_attr(config.entity, 'dev_type') == 'notebook'
          %}{{iLaptop}}{% elif state_attr(config.entity, 'dev_type') == 'tablet'
          %}{{iTablet}}{% elif state_attr(config.entity, 'dev_type') == 'ipcam'
          %}{{iCamera}}{% elif state_attr(config.entity, 'dev_type') ==
          'printer' %}{{iPrinter}}{% elif state_attr(config.entity, 'dev_type')
          == 'router' %}{{iRouter}}{% endif %}) {
              visibility: visible;
          }
        type: 'custom:multiple-entity-row'
      state: home
sort:
  ignore_case: true
  method: name
type: 'custom:auto-entities'

1 Like