I think I’m getting close here, but I’m still getting an error in the Template Editor. I’m attempting to count all of the entities in the group “batteries” that have a state less than or equal to a threshold:
{% set threshold = 50 | int %}
{% set nss = namespace(res=0) %}
{% for sensor in state_attr('group.batteries', 'entity_id') | count %}
{% if states(sensor) | int <= threshold %}
{% set nss.res = nss.res + 1 %}
{% endif %}
{% endfor %}
{{ nss.res }}