puttyman / hass-amplifi

A home assistant integration for Ubiquiti Amplifi
27 stars 16 forks source link

Add an "access point" entry to the wireless device tracker params #29

Closed icandesign closed 2 months ago

icandesign commented 1 year ago

Would it be possible to add an entry to the wireless device tracker parameters that reports the MAC address of the mesh point that device is connected to?

Here's the context: I've been mucking about with an ad-hoc presence sensor for my garage lights. I have an AmplifiHD mesh point set up in the garage, and an automation set up to toggle the lights based on the mesh point I'm connected to and the wifi signal strength.

What I'm trying to do is convert an existing binary sensor so that it taps into hass-amplifi rather than the HA mobile app. The app only seems to 'phone home' every 60 seconds, which is a long time to wait for the lights to come on!

garage_wifi: friendly_name: "Garage Wifi" value_template: > {% set bssid = states('sensor.phone_wifi_bssid_mobile_app') %} {% if bssid in ('XX:XX:XX:XX:XX:XX', 'YY:YY:YY:YY:YY:YY') %} true {% else %} false {% endif ##%}

From what I can see this should be possible. The topology map provided in the Amplifi web interface shows which mesh point the devices are connected to. Additionally I can see the hass-amplifi code referencing { "role" : "Router" }, while the JSON response from info-async.php also contains references to { "role" : "Extender" }.

I've tried to tackle this myself but honestly it's all a bit above my pay grade!

hawksj commented 8 months ago

I know the person that opened this issue may not still be interested in this functionality but I also think it would be a useful feature and one I would like to look into implementing.

In the coordinator file, this section:

        raw_wifi_devices = self.data[WIFI_DEVICES_IDX]
        if raw_wifi_devices:
            for access_point in raw_wifi_devices:
                for wifi_band in raw_wifi_devices[access_point]:
                    for network_type in raw_wifi_devices[access_point][wifi_band]:
                        for macAddr in raw_wifi_devices[access_point][wifi_band][
                            network_type
                        ]:
                            device_info = raw_wifi_devices[access_point][wifi_band][
                                network_type
                            ][macAddr]
                            wifi_devices[macAddr] = device_info

already uses this information. The info-async.php file already includes which AP the device is connected to. I think adding the MAC address of the mesh point a device is connected to would be as simple as returning [access_point] and writing that as an attribute of the device_tracker entity.

This would still require some manual setup in HA for automations (e.g. checking that the MAC address in the entity attributes matches the AP you want to be connected to) but maybe it would be possible to list a device as an extender based on the references to Extender/Router as @icandesign says. One thing at a time though...

@puttyman is this repo still maintained (I know you don't use Amplifi any more) or would I be better off making my own fork and just pushing commits to that? Happy to assist as much as possible in maintaining your repo if you want to keep it that way.

Cheers, S

hawksj commented 2 months ago

The MAC address of the mesh point a client is connected to is now reported as an attribute of the device_tracker entity. See #45 for an example of how to implement this. This is a possible solution to this issue. Returning the MAC address is far easier than returning the name of the AP per the AmpliFi app and not something I am intending to add at this time.