One Automation for multiple devices (Battery low)

Hello,

is it possible to to use only one automation to trigger a battery warning of all my devices (thermostates, window sensors,…)?

Thx.


Hassio:

Home Assistant Core 2022.5.5

Home Assistant Supervisor 2022.05.3

Home Assistant OS 8.1

Running on rpi4-64 (8gb)

The blueprint found at Low Battery Notification may be of interest.

FWIW. this.

alias: Battery Alert
trigger:
  - platform: time_pattern
    hours: /6
condition:
  - condition: template
    value_template: |-
      {%- set threshold = 30 -%} {%- for item in states 
          if (item.attributes.battery_level is defined and 
              item.attributes.battery_level | int < threshold) or
              ("battery" in item.name | lower and 
               ((item.state | int < threshold and item.state|int != 0) or 
                 item.state | lower == "low" or 
                 item.state | lower == "unknown"))-%}
          {%- if loop.first -%} {{ true }} {%- endif -%}
      {%- endfor -%}
action:
  - service: notify.telegram
    data_template:
      title: '{{ as_timestamp(now()) | timestamp_custom("%m-%d-%Y",True) }}'
      message: >-
        {%- set threshold = 30 -%} The following devices have low battery
        levels: {%- for item in states -%}
          {% if item.attributes.battery_level is defined and 
                item.attributes.battery_level | int < threshold %}
             {{ item.name }} ({{ item.attributes.battery_level }}),
          {% elif "battery" in item.name | lower and 
                   ((item.state | int < threshold and item.state|int != 0) or 
                     item.state | lower == "low" or 
                     item.state | lower == "unknown") %}
             {{ item.name }} ({{ item.state }}),
          {%- endif -%}
        {%- endfor -%}

And a simple card.

type: custom:auto-entities
show_empty: false
card:
  type: entities
  title: Battery Levels
  show_header_toggle: false
  state_color: true
filter:
  include:
    - domain: sensor
      state: < 50
      attributes:
        device_class: battery
sort:
  method: state
  numeric: true

You can also add the following for devices not reporting there state.

    - domain: sensor
      state: unavailable
      attributes:
        device_class: battery

Looks like the following.
image