puttyman / hass-amplifi

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

Connected to device attribute #45

Closed hawksj closed 2 months ago

hawksj commented 3 months ago

This is a duplicate of PR #41 but my branch was out of sync. I have now figured out how to correct that so this PR is only for the code changes relating to this feature. The text below is copied from that PR

Appends a "connected_to" attribute to the list of attributes for the device_tracker entity

The format of info-async.php is such that each connected device is listed beneath the MAC address of the AP is it connected to. We can simply return this as we do with other attributes. This can then be used in a markdown card with a configuration such as:

Mesh Point 1

{% for item in (states.device_tracker
|selectattr('entity_id', 'match', 'device_tracker.amplifi.*')
|selectattr('state', 'eq', 'home')
|map(attribute='entity_id')) %}
{% if (state_attr(item,'connected_to') == 'f0:9f:c2:xx:xx:xx') %}
* {{ item.replace('device_tracker.amplifi_','') }} 
{% endif %}
{% endfor %}

which gives you a result such as: image

This is already merged in my fork and operating in my HA instance: image

This provides a solution https://github.com/puttyman/hass-amplifi/issues/29 by triggering an automation based on the attributes of a device_tracker identity updating to the MAC address of the mesh point

@atudor2 if you are still using AmpliFi, would you do me the favour of testing this in your instance for a few days for stability? It has been running in my HA since my initial PR (so almost 6 months) without issue but I want to test on another instance before merging. Thanks!

hawksj commented 3 months ago

This also bumps the version number in the manifest which may make the request in #44 redundant if they can be packaged together into a single "release".

atudor2 commented 3 months ago

@hawksj sure - I'll install now and give feedback on Saturday?

hawksj commented 2 months ago

Thanks @atudor2 appreciate it!

atudor2 commented 2 months ago

@hawksj looks good my side based on the last few days 👍

hawksj commented 2 months ago

Thanks for testing @atudor2, much appreciated. I will merge this PR.