My solution for checking battery status is this:
template sensor for every battery like this one
battery_living_heating: value_template: '{{ states.climate.living_heating_heating_1_8_1.attributes.battery_level }}' friendly_name: 'Wohnzimmer Heizung' unit_of_measurement: '%'
I put all of them into a group
batterie: view: false name: Batterie Status entities: - sensor.battery_floor_multi_sensor - sensor.battery_floor_door - sensor.battery_bathroom_multi_sensor - sensor.battery_bathroom_window - sensor.battery_bathroom_heating - sensor.battery_bedroom_multi_sensor - sensor.battery_bedroom_window - sensor.battery_bedroom_heating - sensor.battery_kitchen_multi_sensor - sensor.battery_kitchen_window - sensor.battery_kitchen_heating - sensor.battery_living_multi_sensor - sensor.battery_living_window - sensor.battery_living_heating - sensor.battery_living_canvas
And last a little automation running every evening at 7pm
`alias: Batterie Status Check - Alle Items in group.batterie
hide_entity: true
trigger:
- platform: time
after: ‘19:00:00’
action: - service: script.turn_on
entity_id: script.battery_check
data_template:
variables:
message: ‘{% set output = “” %}{% for entity_id in states.group.batterie.attributes.entity_id %}{% set itemData = entity_id.split(".") %}{% set friendly_name = states[itemData[0]][itemData[1]].attributes.friendly_name %}{%- if states(entity_id)|int < 40 -%}{%- set output = output +friendly_name+" auf “+states(entity_id) +”% gefallen" -%}{%- endif -%}{% if loop.last %}{{ output }}{% elif states(entity_id)|int < 40 %}{% set output = output + “\n” %}{% endif %}{% endfor %}’`
And the script
battery_check: alias: "check battery of all devices in group.batterie" sequence: - service: notify.Wohnung data_template: message: "{{message}}"
Unfortunately i could not get the template working until it was in one line, should look like this
{% set output = '' %} {% for entity_id in states.group.batterie.attributes.entity_id %} {% set itemData = entity_id.split('.') %} {% set friendly_name = states[itemData[0]][itemData[1]].attributes.friendly_name %} {%- if states(entity_id)|int < 40 -%} {%- set output = output +friendly_name+' auf '+states(entity_id) +'% gefallen' -%} {%- endif -%} {% if loop.last %} {{ output }} {% elif states(entity_id)|int < 40 %} {% set output = output + '\n' %} {% endif %} {% endfor %}
And if i get new devices i want to check, i just add a sensor template and add it to the group, thats all.
I hope that helps someone of you and maybe someone can help me fix 2 little problems.
- In automation write the template structured instead of in one line
- In script i want to check if message is not empty before sending the message.