- id: notify_if_batteries_are_low
  alias: Daily alert that zigbee batteries Are Low
  initial_state: true
  trigger:
    - platform: time
      at: "19:00:00"
  condition:
    - condition: or
      conditions:
        - condition: template
          value_template: >
            {% set min_battery_level = 20 -%}
            {% set ns = namespace(found=false) -%}
            {% for entity_id in states.group.battery_levels.attributes.entity_id -%}
              {% set parts = entity_id.split('.') -%}
              {% if (states(entity_id) | replace("%","") | int) < min_battery_level -%}
                {% set ns.found = true -%}
              {% endif -%}
            {% endfor -%}
            {{ ns.found }}
  action:
    - service: notify.pushover_zorruno
      data:
        title: View Road Sensors
        message: >
          {%- set min_battery_level = 20 -%}
          {%- for entity_id in states.group.battery_levels.attributes.entity_id -%}
            {%- set parts = entity_id.split('.') -%}
            {%- if (states(entity_id) | replace("%","") | int) < min_battery_level -%}
              {{ states[parts[0]][parts[1]].name }} level is {{ states(entity_id) }}%.{{ '\n' }}
            {%- endif -%}
          {%- endfor -%}
