I have several z-wave devices/sensors that are battery-powered. I want a gentle reminder when those batteries get low, without cluttering my UI. Here’s how I used an entity filter card to solve that.
When there are no devices with low batteries, the card is hidden. This is what the low battery card looks like when a device has low battery:
(I don’t actually set the battery level threshold as high as 40%, but I needed to do so to get a screenshot.)
The battery level is displayed with both a numeric % and an icon by setting the device_class to battery.
Here’s the ui-lovelace.yaml entry for the entity filter card. Note that you can define multiple state filters. These report battery_level in increments of 10, so I don’t have to define every value in between. Set show_empty to false to hide the card when no entities have a low battery.
I think he’s just showing people that he’s using the entity-filter to only display batteries below a specific threshold. He doesn’t want an actual alert, which is what you are referencing.
For some reason for me it doesn’t report the battery in 10% increments. If I filter for exact values, the entities show up, otherwise not. Any ideas why?
Just wanted to show what I have come up with from a variety of other ideas. This is a dynamically generated list I have on my maintenance page. Simple but I find effective:
- type: vertical-stack
title: Low Battery
cards:
- type: entities
entities:
- entity: input_number.low_battery_alert_threshold
- type: markdown
content: |
{% set result = namespace(sensors=[]) %}
{% set ignore_entities = ['sensor.mid_1090ips_battery_level'] %}
{% for state in states.sensor | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', '==', 'battery') | rejectattr('entity_id', 'in', ignore_entities)%}
{% if 0 <= state.state | int(-1) < (states.input_number.low_battery_alert_threshold.state | float) | int %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
{% endif %}
{% endfor %}
{% for state in states.binary_sensor | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', '==', 'battery') | selectattr('state', '==', 'on') %}
{% if not state.entity_id in exclude.entity_id %}
{% set result.sensors = result.sensors + [state.name] %}
{% endif %}
{% endfor %}
{{result.sensors|join('\n')}}
edit: added filter to prevent errors if the device_class is not defined
I really like your Idea of this.
In case someone want to get this to work… because there are many hoops to jump throuh that many people might not know how to im going to summarize what to do with the most GUI-able way:
click on “number” and name it low_battery_alert_threshold.
Be sure that it has the “correct entity ID”, otherwise you need to edit later (which is pesky):
on the bottom left you will see “show code editor”
paste the code from above now on the right side you should see the slider. if not, the helper-entity has another name and you didnt read the instruction good enough.