I have this template triggered every day at 10 that checks if anything in the house has a battery level below 20 % and sends a mail with the “offending” devices. This is the template, which filters out my car and phone as well as some non-numerical states:
{%- set sensors = states.sensor
| selectattr('object_id', 'search', 'battery')
| rejectattr('state', 'in', ['idle', 'unavailable', 'unknown', 'good','discharging'])
| rejectattr('entity_id', 'search', 'vog')
| rejectattr('entity_id', 'search', 'starter_battery')
| list -%}
{%- for s in sensors if s.state | int(0) < 40 %}
{{s.name}}: {{ s.state }}%
{%- endfor %}
But the mail is sent no matter what. So is there a way I can use a similar template to stop the automation if there are no devices that has less than 20 % battery left? If I could run the same template with “is empty” that would work, but I don’t think that’s a condition.
Thanks for answering! The notification is a mail notifiction I have set up, but it doesn’t want to work. The 40 % btw is because I want to test that it works, I’ll set it to 20 when it works. I just don’t have anything below 20 right now. Here is the action part the way it is with the mail set:
Sorry, my mistake. Indentation error. Thanks for answering! But I do not get a mail with 40 %, I assume that is because it is not defined as low battery. Or am I mistaken? I need it to react to at least 20 % because from there and down to non-functional is a very short time for my Z-Wave lock, so I always replace at 20.
Thank you very much! That works! Only a few details, is it possible to insert a line feed after each post, remove "Battery level: " and add a space before %? This is how it looks now.