Blueprint: use area name as variable for entity name

Hi,

I’m trying to create my first blueprint.It should automate the behaviour, what to do if I open a windows in a specific room.

I did group my window sensors.

How do I do this right?

blueprint:
        name: Heizung-Fenster-Steuerung
        domain: automation
        input:
            area:
                name: Raum
                selector:
                    area:
    
        description: ""
    variables:
        area: !input 'area'
        trigger:
          - platform: state
            entity_id:
              - binary_sensor.raum_{{area}}
            for:
              hours: 0
              minutes: 0
              seconds: 10
        condition:
          - condition: not
            conditions:
              - condition: state
                entity_id: switch.schedule_heizperiode_aus
                state: "on"
                enabled: true
        action:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: binary_sensor.raum_{{area}}
                    state: "on"
                sequence:
                  - service: scene.create
                    data:
                      snapshot_entities:
                        - switch.schedule_{{area}}
                        - climate.thermostat_{{area}}
                      scene_id: temp_{{area}}
                  - repeat:
                      sequence:
                        - service: climate.turn_off
                          data: {}
                          target:
                            entity_id: climate.thermostat_{{area}}
                      until:
                        - condition: state
                          entity_id: climate.thermostat_{{area}}
                          state: "off"
              - conditions:
                  - condition: state
                    entity_id: binary_sensor.raum_{{area}}
                    state: "off"
                sequence:
                  - repeat:
                      sequence:
                        - service: climate.turn_on
                          data: {}
                          target:
                            entity_id: climate.thermostat_{{area}}
                      until:
                        - condition: not
                          conditions:
                            - condition: state
                              entity_id: climate.thermostat_{{area}}
                              state: "off"
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 10
                      milliseconds: 0
                  - service: scene.turn_on
                    target:
                      entity_id: scene.temp_{{area}}
                    metadata: {}

Variables are not rendered until after the trigger, so there is nothing in area until after the trigger, meaning no trigger…

You need to use trigger_variables , which are limited, when the data has to be there for the trigger.
Automation Trigger - Home Assistant.

I got a working solution:

blueprint:
  name: 'XX Raum: Heizungssteuerung'
  domain: automation
  #description: ''
  input:
    # area_input:
    #   name: Raum
    #   selector:
    #     area:
    window_sensor_input:
      name: Fensterkontakt-Gruppe
      selector:
        entity:
          filter:
            #  - domain: binary_window_sensor
            - device_class: window

variables:
  window_sensor: !input window_sensor_input #'{{''binary_sensor.raum_'' + var_area }}'
#  var_area0: !input area_input
  var_area: "{{area_id('window_sensor')}}"  # "{{window_sensor.split('_')[2]}}" # "{{var_area0 | lower}}" # "{{window_sensor.split('_')[1]}}"
  scene_name: "{{'temp_' + var_area}}"
  scene_id: "{{'scene.' + scene_name}}"
  room_thermostat: "{{'climate.thermostat_' + var_area}}"
  schedule: "{{'switch.schedule_' + var_area}}"

trigger:
  - platform: state
    entity_id:
      - input_boolean.tester
  - platform: state
    entity_id:
      - !input window_sensor_input
    from: "on"
    to: "off"
    id: "off"
    for:
      seconds: 10
  - platform: state
    entity_id:
      - !input window_sensor_input
    from: "off"
    to: "on"
    id: "on"
    for:
      seconds: 10

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: switch.schedule_heizperiode_aus
        state: "on"
        enabled: true

action:
  - choose:
      - conditions:
          - condition: trigger
            id: 
              - "on"
        sequence:
        - service: scene.create
          data:
            snapshot_entities:
              - "{{schedule}}"
              - "{{room_thermostat}}"
            scene_id: "{{scene_name}}"
        - service: switch.turn_off
          data: {}
          target:
            entity_id: "{{schedule}}"
        - service: climate.turn_off
          data: {}
          target:
            entity_id: "{{ room_thermostat }}"
        # - service: persistent_notification.create
        #   data:
        #     message: "{{window_sensor + ': ' + room_thermostat + ' in ' + var_area + ' ausgeschaltet'}}"
      - conditions:
          - condition: trigger
            id: 
              - "off"
        sequence:
        - service: climate.turn_on
          data: {}
          target:
            entity_id: "{{ room_thermostat }}"
        - service: scene.turn_on
          data: {}
          target: 
            entity_id: "{{scene_id}}"
        # - service: persistent_notification.create
        #   data:
        #     message: "{{window_sensor + ': ' + room_thermostat + ' in ' + var_area + ' eingeschaltet'}}"

mode: single