I’ve just looked at the json returned from an Appdaemon app I use and it does return the MAC of the AP (ap_mac
) a client is connected to, maybe it could be added to the attributes in the device_tracker
in the unifi integration.
That way you could check if a device is connected to an access point and automate from that.
Be aware though that devices don’t always connect to the nearest AP and switching between APs is not very quick
This is the returned JSON for a client
{
'site_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'ap_mac': 'xx:xx:xx:xx:xx:xx',
'assoc_time': 1691693844,
'latest_assoc_time': 1692868612,
'oui': 'Espressif Inc.',
'user_id': 'xxxxxxxxxxxxxxxxxxxxxxxx',
'last_ip': '192.168.40.103',
'first_seen': 1637689931,
'last_seen': 1692869617,
'is_guest': False,
'fingerprint_engine_version': '',
'disconnect_timestamp': 1688045857,
'dev_id_override': 2058,
'is_wired': False,
'dev_family': 16879,
'mac': 'xx:xx:xx:xx:xx:xx',
'score': 87,
'hostname': 'front-garden-lightbulb-b2',
'device_name': 'Embedded OS',
'dev_cat': 16879,
'local_dns_record_enabled': False,
'use_fixedip': False,
'local_dns_record': '',
'usergroup_id': '',
'fingerprint_override': True,
'last_connection_network_name': 'network NoT',
'fingerprint_source': 0,
'dev_id': 36994,
'noted': True,
'last_connection_network_id': 'xxxxxxxxxxxxxxxxxxxxxx',
'network_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'fixed_ap_enabled': False,
'name': 'front-garden-lightbulb-b2',
'_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'fixed_ip': '192.168.40.103',
'dev_vendor': 0,
'fw_version': '',
'wlanconf_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
'_uptime_by_uap': 685655,
'_last_seen_by_uap': 1692869617,
'_is_guest_by_uap': False,
'channel': 1,
'radio': 'ng',
'radio_name': 'wifi0',
'essid': 'network NoT',
'bssid': 'xx:xx:xx:xx:xx:xx',
'powersave_enabled': False,
'is_11r': False,
'user_group_id_computed': 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'anomalies': -1,
'anon_client_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'ccq': xxx,
'dhcpend_time': 2050,
'idletime': 11,
'ip': '192.168.40.103',
'noise': -113,
'nss': 1,
'rx_rate': 6000,
'rssi': 48,
'satisfaction': 100,
'satisfaction_now': 100,
'satisfaction_real': 100,
'satisfaction_reason': 0,
'signal': -48,
'tx_mcs': 7,
'tx_power': 22,
'tx_rate': 72222,
'tx_retry_burst_count': 162,
'hostname_source': 'ubios',
'radio_proto': 'ng',
'channel_width': 20,
'satisfaction_avg': {
'total': 87096141,
'count': 893152
},
'uptime': 1175773,
'tx_bytes': 3058331,
'rx_bytes': 6785034,
'tx_packets': 55923,
'rx_packets': 96091,
'tx_retries': 3470,
'wifi_tx_attempts': 59390,
'authorized': True,
'qos_policy_applied': True,
'_uptime_by_usw': 2325473,
'_last_seen_by_usw': 1692869653,
'_is_guest_by_usw': False,
'sw_mac': 'xx:xx:xx:xx:xx:xx',
'wired_rate_mbps': 1000,
'sw_depth': 1,
'network': 'network NoT',
'_uptime_by_ugw': 2325473,
'_last_seen_by_ugw': 1692869653,
'_is_guest_by_ugw': False,
'gw_mac': '68:d7:9a:62:aa:93',
'gw_vlan': 40,
'_last_reachable_by_gw': 1692869634,
'bytes-r': 0.0,
'tx_bytes-r': 0.0,
'rx_bytes-r': 0.0,
'roam_count': 3,
'vlan': None
}