Hi, I’m planning to add a few more battery powered devices like window sensors. Is there an addon that automatically detects all battery entities and shows a “battery low” warning on a dashboard? It might be a bit tedious to add this manually for each device
Maybe something like this:
Or:
I have it like a chip on frontend which epxands (with browser mod).
the chip - the one with battery ! icon
the expanded window:
the sensor in configuration.yaml:
- platform: template
sensors:
devices_with_low_battery:
friendly_name: 'Zařízení se slabou baterií'
unique_id: devices_with_low_battery
unit_of_measurement: devices
value_template: >-
{% set ignore_entities = [] %}
{{ states.sensor
| selectattr('attributes.device_class', 'eq', 'battery')
| rejectattr('entity_id', 'in', ignore_entities)
| map(attribute='state')
| reject('in', ['unknown', 'unavailable'])
| map('int', -1) | select('le', 15)
| select('ge', 0)
| list | count
}}
icon_template: >-
{% if is_state('sensor.devices_with_low_battery', '0') %}
mdi:battery-check
{% else %}
mdi:battery-alert
{% endif %}
the chip:
- type: conditional
conditions:
- entity: sensor.devices_with_low_battery
state_not: '0'
chip:
type: template
entity: sensor.devices_with_low_battery
icon_color: red
icon: mdi:battery-alert
content: '{{ states(entity) }}'
tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.popup
data:
title: Slabé baterie
content:
type: custom:auto-entities
filter:
include:
- attributes:
device_class: battery
state: < 30
options:
type: custom:mushroom-template-card
primary: '{{ states(entity) }}%'
secondary: '{{ state_attr(entity, ''friendly_name'') | title }}'
icon: >
{% set battery_level = (states(entity) | int / 10) |
round(0) | int * 10 %} {% if battery_level == 100 %}
mdi:battery
{% elif battery_level > 0 %}
mdi:battery-{{ battery_level }}
{% else %}
mdi:battery-outline
{% endif %}
icon_color: |-
{% set battery_level = states(entity) | int %}
{% if battery_level > 90 %}
green
{% elif battery_level > 60 %}
light-green
{% elif battery_level > 50 %}
lime
{% elif battery_level > 40 %}
yellow
{% elif battery_level > 30 %}
amber
{% elif battery_level > 20 %}
orange
{% elif battery_level > 10 %}
deep-orange
{% else %}
red
{% endif %}
layout: horizontal
tap_action:
action: none
badge_icon: |-
{% set battery_level = states(entity) | int %}
{% if battery_level < 10 %}
mdi:exclamation-thick
{% endif %}
badge_color: red
card_mod:
style: |
ha-card {
padding: 4px 12px !important;
}
exclude: null
show_empty: false
card:
type: custom:layout-card
cards: []
layout_type: masonry
sort:
method: friendly_name```
1 Like
I use a combination of auto-entries and battery-entity-row to show battery’s that are in need of attention. As long as your battery sensor names are pretty consistent, you should be able to do something similar. If you look, you’ll notice two different entries in auto-entries. That’s because some of my batteries report a level and others just provide a binary for either “good” or “low.”
type: custom:auto-entities
filter:
include:
- entity_id: '*battery*'
state: <21
options:
type: custom:battery-entity-row
warning: 60
critical: 20
- entity_id: binary_sensor.batt_ecowitt*
state: 'on'
exclude:
- entity_id: '*battery_state*'
- entity_id: '*battery_level*'
card:
type: entities
title: Battery Alerts
sort:
method: state
reverse: false
numeric: true
else:
type: markdown
content: All batteries are at least 20% charged.
title: Battery Alerts
show_empty: false