What is this? A simple jinja template that will show battery level for mobile devices only.
There are 2 options:
- Alert first, then list of device
- List of device first, then alert
| type: vertical-stack | |
| cards: | |
| - type: markdown | |
| content: >- | |
| {% set ns = namespace(low_count=0) %} | |
| {% for state in states.sensor | selectattr('entity_id', 'search', | |
| 'battery_level') %} | |
| {% if state.state | int < 50 %}{% set ns.low_count = ns.low_count + 1 %}{% | |
| endif %}{% endfor %} | |
| {% if ns.low_count > 0 %}<ha-alert alert-type="warning">The device(s) | |
| below requires attention.<br />Battery is running low:</ha-alert> | |
| {% else %}<ha-alert alert-type="success">All devices are well | |
| charged.</ha-alert>{% endif %} | |
| {% for state in states.sensor | selectattr('entity_id', 'search', | |
| 'battery_level') %} | |
| {% if state.state | int < 50 %} | |
| - {{ state.name.split(' Battery')[0] | title }} ({{ state.state }}%) | |
| Last Updated: {{ relative_time(state.last_updated) }} ago | |
| {% endif %}{% endfor %} | |
| title: ๐ Low Battery | |
| - type: markdown | |
| content: >- | |
| {% set ns = namespace(low_count=0) %} | |
| {% for state in states.sensor | selectattr('entity_id', 'search', | |
| 'battery_level') -%} | |
| {% if state.state | int < 50 %} | |
| {% set ns.low_count = ns.low_count + 1 %} | |
| - {{ state.name.split(' Battery')[0] | title }} ({{ state.state }}%) | |
| Last Updated: {{ relative_time(state.last_updated) }} ago{% endif %} | |
| {% endfor -%} | |
| {% if ns.low_count > 0 %}<ha-alert alert-type="warning">The device(s) | |
| above requires attention.<br />Battery is running low!</ha-alert> | |
| {% else %}<ha-alert alert-type="success">All devices are well | |
| charged.</ha-alert>{% endif %} | |
| title: ๐ Low Battery |