Hi,
Please could someone give me a hand with a template to list all the devices connected to a specific access point (unifi)?
I understand I can check if a specific device is connected to a specific AP with the following template, however I wish to expand this to list all the devices connected to each AP by mac address on a manual card - is this possible?
{{ is_state('device_tracker.my_phone', 'ap_mac') == "00:00:00:00:00:00" }}
I would also like a count for each AP.
Thanks in advance!
tom_l
July 4, 2020, 9:28am
2
For the count:
{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='entity_id') | list | count }}
For a comma separated list of entity_ids:
{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='entity_id') | list | join(", ") }}
For a comma separated list of friendly names:
{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='name') | list | join(", ") }}
tom_l:
{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='name') | list | join(", ") }}
Hi, thanks for the swift response!
I have just tried this and the count returns ā0ā (and no devices are listed)
Could this be to do with the comparator used on the ap_mac?
Ta
Jon
tom_l
July 4, 2020, 9:37am
4
Did you replace 00:00:00:00:00:00
with the mac of your AP?
tom_l
July 4, 2020, 9:40am
6
Pick any of the device trackers and post the attributes listed in the developer tools states menu.
source_type: router
is_wired: false
hostname: amazon-9fae3ae60
mac: 'd0:d0:d0:d0:d0:d0'
name: Lounge FireTV
oui: ''
_is_guest_by_uap: false
ap_mac: 'a0:a0:a0:a0:a0:a0'
authorized: true
essid: Nacho Wifi
ip: xx.xx.xx.xx
is_11r: false
is_guest: false
noted: true
qos_policy_applied: true
radio: na
radio_proto: ac
vlan: 0
friendly_name: Lounge FireTV
tom_l
July 4, 2020, 9:58am
8
Try removing the quotes from around the mac.
{{ states.device_tracker | selectattr('ap_mac', 'eq', 00:00:00:00:00:00) | map(attribute='entity_id') | list | count }}
{{ states.device_tracker | selectattr('ap_mac', 'eq', 00:00:00:00:00:00) | map(attribute='entity_id') | list | join(", ") }}
{{ states.device_tracker | selectattr('ap_mac', 'eq', 00:00:00:00:00:00) | map(attribute='name') | list | join(", ") }}
That works for me (selecting on a different attribute):
It doesnāt like the colons in the mac:
Error rendering template: TemplateSyntaxError: expected token ā,ā, got ā:ā
tom_l
July 4, 2020, 10:04am
10
Hang on. Post the whole config where you use the template. I might have an idea what the problem is.
Great stuffā¦Thanks
My intention is to have it on a card, but just testing it in the Developer Tools > Template menu currently.
tom_l
July 4, 2020, 10:09am
12
Oh ok.Thatās not the problem then. Was thinking you were doing something like this:
value_template: '{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='entity_id') | list | count }}'
Instead of this:
value_template: "{{ states.device_tracker | selectattr('ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='entity_id') | list | count }}"
tom_l
July 4, 2020, 10:12am
13
One last try:
{{ states.device_tracker | selectattr('ap_mac' == '00:00:00:00:00:00') | map(attribute='entity_id') | list | count }}
{{ states.device_tracker | selectattr('ap_mac', == '00:00:00:00:00:00') | map(attribute='entity_id') | list | join(", ") }}
{{ states.device_tracker | selectattr('ap_mac', == '00:00:00:00:00:00') | map(attribute='name') | list | join(", ") }}
Donāt forget to replace the mac addresses, with the the AP addresses.
Still getting ā0ā returned
tom_l
July 4, 2020, 10:59am
15
Yeah on closer inspection my section template is not working for entity attributes, only state (itās actually returning all my trackers in the example above).
Hopefully someone else may be able to help. I donāt like @ing people but if I see someone I know can help is online Iāll point them this way.
@tom_l was close. To get to an āattributeā of a state object in the selectattr()
function you need to use 'attributes.ATTR'
. (See State Objects .) So:
{{ states.device_tracker | selectattr('attributes.ap_mac', 'eq', '00:00:00:00:00:00') | list | count }}
{{ states.device_tracker | selectattr('attributes.ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='entity_id') | list | join(', ') }}
{{ states.device_tracker | selectattr('attributes.ap_mac', 'eq', '00:00:00:00:00:00') | map(attribute='name') | list | join(', ') }}
1 Like
Awesome, thats done it! Thanks both!
If I want to add this to a card?
tom_l
July 8, 2020, 10:46am
18
Thanks Phil.
Auto entities would be a good fit for this.
Finally released in HACS.
This lovelace plugin lets you automatically put entities into lovelace cards.
You can e.g. make an entities card which shows all your remotes which have a low battery.
Or a glance card which shows all lights that are currently on.
Thereās lots of matching options. Like selecting all media players where the currently playing song matches a regular expression.
And you can also finally sort the entities!
Hereās just some examples from my development setup:
[localā¦
kajmaj
February 5, 2021, 1:56pm
19
I am able to count to the LAN connected devices, i.e. home
state but still not able to find the way how to list connected IPs (ip from device_tracker
attributes )
Could anybody here advice pls?
Edit:
I did it
{{ states.device_tracker | selectattr('attributes.ip') | map(attribute='attributes.ip')| list | join('\n') }}