I am creating a low battery sensor which is a list of batteries that are less than 30 percent in my case. My batteries are split among multiple groups. I have the following template sensor which I have checked as much as I can in the template editor. It seems good in the template editor, but has no value when implemented as follows:
- platform: template
sensors:
low_batteries:
value_template: >-
{% set lock_batteries = states | selectattr('entity_id', 'in', state_attr('group.door_lock_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set door_batteries = states | selectattr('entity_id', 'in', state_attr('group.door_sensor_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set motion_batteries = states | selectattr('entity_id', 'in', state_attr('group.motion_sensor_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set temperature_batteries = states | selectattr('entity_id', 'in', state_attr('group.temp_sensor_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set other_batteries= states | selectattr('entity_id', 'in', state_attr('group.other_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set button_cube_batteries= states | selectattr('entity_id', 'in', state_attr('group.button_cube_batteries', 'entity_id')) | selectattr('state', 'lessthan', '30') |map(attribute='name') | list %}
{% set low_batteries = lock_batteries + door_batteries + motion_batteries + temperature_batteries + other_batteries + button_cube_batteries %}
{{ low_batteries | list | join(', ') }}