Use template in entity list in an automation?

Hi,
I have a simple automation which sends me a message to my phone when the battery_level of an entity is below 15. As trigger for this automation I have inserted a list of all the entities. Did someone know if i can template this entity list? All entities have “battery_level” in their name.

Here is the code for the automation:

- alias: 'Notify Battery'

  trigger:

    platform: numeric_state

    entity_id: sensor.hue_motion_sensor_wohnzimmer_battery_level,

               sensor.hue_motion_sensor_esszimmer_battery_level,

               sensor.motion_sensor_arbeitszimmer_battery_level,

               sensor.motion_sensor_schlafzimmer_battery_level,

               sensor.arbeitszimmer_dimm_battery_level,

               sensor.button_tim_battery_level,

               sensor.button_kitchen_battery_level,

               sensor.rechtes_fenster_schlafzimmer_battery_level,

               sensor.arbeitszimmer_tuer_battery_level,

               sensor.wc_guests_door_battery_level,

               sensor.lumi_sensor_smoke_battery_level,

               sensor.linkes_fenster_schlafzimmer_battery_level,

               sensor.wohnzimmer_dimm_battery_level,

               sensor.esszimer_fernbedienung_battery_level

    below: '15'

  action:

  - service: notify.ios_devices

    data_template:

        title: "Batterien"

        message: "{{ trigger.to_state.attributes.friendly_name }} benötigt eine neue Batterie!"

        data:

         push:

          thread-id: "Batterie"

  - service: persistent_notification.create

    data_template:

        title: Batterien

        message: "{{ trigger.to_state.attributes.friendly_name }} benötigt eine neue Batterie!"

        notification_id: Batterien

While not exactly what you’re looking for, personally, I use this custom auto-entities card for situations like this on my dashboard that shows instead of notifications/alerts - as they’re more ‘static’:

Yes I know the card, it is quite usefull but I need this “wildcarding” in an automation.

Does this help?

You appear to be using tabs for indentation. Home assistant will not like this. Use only spaces for indentation.

1 Like

Oh okay, thank you for this. I will use this in the future:)