Alerter sur Batterie Faible

Pour ceux qui souhaiteraient passer par un template plus générique (sans nommer chaque batterie à surveiller)

ce qui donne pour moi

automation:
# # https://community.home-assistant.io/t/battery-alert-automation-stuck-with-syntax/141216
  - alias: 'Battery alert'
    trigger:
    - platform: time
      at: '07:03:00'
    condition:
    - condition: template
      value_template: >-
        {%- set threshold = 40 -%}
        {%- 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.HA
      data_template:
        title: '{{ as_timestamp(now()) | timestamp_custom("%d-%m-%Y, %H:%M:%S",True) }}'
        message: >-
          {%- set threshold = 40 -%}
          Les appareils suivants ont un niveau de batterie faible :
          {%- 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 -%}
2 « J'aime »