Check Battery Status And Notify iOS Device

I built an automation to check all devices in the group ‘batterie_sub’. (By the way: Some words are in german)
It checks at a specific time all entities in this group an notifies me on my iphone. It stops as soon as one device is below the predetermined value. In this case 34%.

# Check Battery
- alias: Check Battery
  hide_entity:  True
  trigger:
    - platform: time
      at: '10:24:00'
  condition:
    - condition: template
      value_template: >-
        {% for entity_id in states.group.batterie_sub.attributes.entity_id if states(entity_id) | int < 34 %}
        {%- if loop.first -%}
        {{ true }}
        {%- endif -%}
        {% endfor %}
  action:
    - service: notify.ios_renes_iphone
      data_template:
        title: "Batteriestatus"
        message: >-
          {% for entity_id in states.group.batterie_sub.attributes.entity_id if states(entity_id) | int < 34 %}
          {%- if loop.first -%}
          {{ "Batterie "+ states[entity_id.split(".")[0]][ entity_id.split(".")[1]].attributes.friendly_name +" auf "+states(entity_id) +"% gefallen" }}
          {%- endif -%}
          {% endfor %}
        data:
          push:
            category: "battery"

I don’t know if its ‘best practice’, but hey it works for me.

1 Like

Thank you for this.

My Xiaomi devices seem to be around 30% when they emerge from the box, but all still working well. I’d set the alarm level a bit lower myself.

Me too. All Xiaomi devices came with less than 45% battery remaining. I set the alarm level to 15%. There will be still enough time to change the battery.