Unifi Network: Detect when new clients connect?

Hi,

I’m trying to figure out how to use the Unifi Network integration to detect / notify me when new clients connect to my WIFI network. It appears like new entities are disabled by default when they are picked up by the Unifi Network integration. If I’m not mistaken it’s impossibles to tell that these new disabled entities where found by the integration from within automations / Home Assistant, is that correct?

Also, is there a way to disable the behavior of adding new client entities disabled? The “Enable newly added entities.” option appears to be on for me already, so that doesn’t seem to work.

The integration’s documentation doesn’t seem to help to solve this.

1 Like

I use the following (YAML) automation to notify me on new Unifi clients:

Note I’m ignoring trackers that get created suffixed with default to workaround Unifi’s habit of adding ghost MAC address based clients.

- id: devicetracker_notification_newdevice
  alias: "Device Tracker new device notification"
  mode: queued
  trigger:
    - platform: event
      event_type: device_tracker_new_device
      event_data:
        action: create
    - platform: event
      event_type: entity_registry_updated
      event_data:
        action: create
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.notify_via_sms
          state: "off"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'device_tracker' }}"
        - condition: template
          value_template: "{{ not (trigger.event.data.entity_id.split('.')[1].startswith('unifi_') and trigger.event.data.entity_id.split('.')[1].endswith('default')) }}"
  action:
3 Likes

Thank you. This seems reasonable. Is my understanding correct that

a) device_tracker_new_device is no longer relevant and deprecated and listening for entity_registry_updated will be enough?
b) that the entity_registry_updated with action create event does not carry any information about the integration that created the entity?
c) There’s no way to automatically enable the entity after the entity_registry_updated fired for new entities?

a. I believe so - there was a discussion thread about new device notifications at the time (which is where I found this alternative approach documented).
b. I can’t honestly say I’ve checked
c. I don’t believe so - the unifi network integration used to default to enable (which is why my automation condition’s include ignoring the ghost mac’s occasionally “found” by the Unifi controller). I believ this was changed some time back by popular request.

In my experience recently it still does enables some by default but not all. actually most aren’t enabled but a few are.

I don’t know why it does that either. My understanding was just like yours and I can’t figure out why it enables those and not the rest.

Intriguing.

I got curious and dug around - on a cursory read I think that (closed) issue 65188 and the referenced pull 63328 may relate.

Did you find a way to enable new clients by default?

No - not really an issue for me tbh as we don’t have a high turnover of network clients