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```
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
Jiri,
Great idea, I’m trying to implement this now. Should the chip still show up if a battery is under a certain percent (or is there a way for me to test that)?
I can get then sensor.devices_with_low_battery entity to show up as a regular chip, but when trying your chip code it’s blank.
Thanks in advance!!
Here are a couple of my battery levels:
That seems like correct behavior, as your “normal” chip shows 0 devices with low battery. Mine is conditional:
- type: conditional
conditions:
- entity: sensor.devices_with_low_battery
state_not: '0'
so it shows only if the sensor is not 0.
Good to know that’s working, thank you!
In what part of the code can I change the level/percentage to do some testing?
map('int', -1) | select('le', 15)
This line, le 15 means less or equal to 15
Thank you!
I have the yaml code in and is working, but the chip code I’m getting an error. It doesn’t tell me what the issue is. I have the mushroom cards, browser mod, ad layout-card installed. What am I doing wrong?
what error you are getting?
Configuration errors detected:
- No type provided.
can you post a screenshot how you are configuring the chip card and where the error is? It is hard to say what could be wrong without more info
I now have it showing up. I had to add the 2 lines of code on the top. The only thing that shows is my phone. I set the value to 85%, so now I have 9 devices that have low battery. None of the sensors actually show up in the popup
yes, sorry, that was not mentioned in my post that it has to be in the type: custom:muschroom-chips-card.
Do you have the tap_action set to action: fire-dom-event as mentioned in my post?
in the code it is, but it doesn’t show up in the config. Should it? Like I said, the chip shows 9 low batteries, but when the popup comes up it only shows my phone.
You say you set the value to 85% to test the chip
But in this screenshot, the pop up auto-entities card filters by state < 30
.
There are two filters. You likely need to change the one for the popup auto-entities card too.
Ah, good catch. I only was changing in the 1 location.
Thanks for the code. I have setup an auto-entities list that populates if the battery percent is below 40%.
This shows up automatically at the bottom of my Media Control page.
Changed the sort method to state so the list starts with the lowest percentage.
type: custom:auto-entities
filter:
include:
- attributes:
device_class: battery
state: < 40
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: true
card:
type: custom:layout-card
cards: []
layout_type: masonry
sort:
method: state