How can I use variable names in automation for an entity_id?

Hi all,

I would like to use a trigger variable as an entity id. I have following entities:
kamera_einfahrt_bewegung, kamera_tuerklingel_person and kamera_garten_personen

When trying to use entity_id: input_boolean.kamera_{{ trigger.id }}, while trigger_id I get the following error message when trying to save my automation:

Message malformed: Entity input_boolean.kamera_{{ trigger.id }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['conditions'][0]['entity_id']

Here is the full code of my automation. Any ideas, how I

alias: Push - Einfahrt Bewegung
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.einfahrt_tuerklingel_bewegung
    to: "on"
    id: "einfahrt_bewegung"
  - trigger: state
    entity_id:
      - binary_sensor.einfahrt_tuerklingel_fahrzeug
    to: "on"
    id: "einfahrt_bewegung"
  - trigger: state
    entity_id:
      - binary_sensor.einfahrt_tuerklingel_person
    to: "on"
    id: "einfahrt_bewegung"
  - trigger: state
    entity_id:
      - binary_sensor.reolink_garten_rlc_843_tier
    to: "on"
    id: "garten_tiere"
  - trigger: state
    entity_id:
      - binary_sensor.reolink_garten_rlc_843_person
    to: "on"
    id: "garten_personen"
conditions:
  - condition: state
    entity_id: input_boolean.kamera_{{ trigger.id }}
    state: "on"
actions:
  - action: notify.mobile_app_oneplus12
    enabled: true
    data:
      message: {{ trigger.id }}
      data:
        url: /dashboard-kameras/0
        actions:
          - action: URI
            title: Open
            destructive: true
            uri: /dashboard-kameras/0
mode: single

The state condition does not seem to allow templating, but you can easily rewrite it to a template condition:

conditions:
  - "{{ is_state('input_boolean.kamera_'+trigger.id, 'on') }}"
2 Likes

AFAIK, you cannot use templates in any triggers, actually.

1 Like

You can use limited templates, so basically stuff that does not use the state machine.

Also to the original poster, you need to put templates in quotes if you are using them. (llke here:)

1 Like