I was looking to do something similar to this… After using this post for inspiration, I’ve ended up with a generic solution using device_class=battery
, so there was no need to hardcode group/entity names.
This template outputs a comma delimited list of entity names where battery level is under 30%:
{% set separator = joiner(", ") %}
{% for battery in (states | selectattr('attributes.device_class', 'eq', 'battery')) if battery.state | int < 30 %}
{{- separator() + battery.entity_id -}}
{% endfor %}