Hi,
I need to get the count of the item with power < 10%.
I able to get the list of the power value (of this 4 entity zigbee group) but not the number of then above a value (f.i 10%)
Thanks
Try pasting this into your Template Editor-
{% set x = [20, 30, 50] %}
{{ x | select('lt', 50)| map('int') | list }}
lt
stands for less than, if you want greater than, use gt
1 Like
Thanks you two all!
Last question… how to get name of device in the list (and not the value of battery)?
This gets the value
{{ expand('group.all_zigbee_power') | map(attribute='state') | map('float') | select('lessthan', 10) | list }}
Thanks.
Try this-
{{ expand('group.all_zigbee_power') | rejectattr('state', 'eq', '100') | selectattr('state', 'lt', '10') | map(attribute='name') | list | join(', ') }}
Edit: incorrect suggestion. See Petro’s explanation.
1 Like
That won’t work with state because it’s a string. 9 will be greater than 10, but 09 won’t.
The only way this can be done using the state is with namespace
{% set ns = namespace(entities = []) %}
{% for s in expand('group.all_zigbee_power') %}
{% if s.state | float > 10 %}
{% set ns.entities = ns.entities + [ s ] %}
{% endif %}
{% endfor %}
{{ ns.entities | map(attribute='name') | list | join(', ') }}
1 Like