Error initializing 'template' trigger UndefinedError: 'fenster_azimut' is undefined

Hi,
I try to setup an Blueprint, which based on some parameter, one beeing the azimut of the window, opens or closes the shutter. My Blueprint looks like this:

blueprint:
  name: Automatische Beschattung
  description: >
    Steuert die Rollläden basierend auf der Sonnenposition, Temperatur und Helligkeit.
  domain: automation
  input:
    fenster_azimut:
      name: Azimut des Fensters
      description: Der Azimut-Winkel des Fensters (Kompassgrad)
      selector:
        number:
          min: 0
          max: 360
          unit_of_measurement: "°"
    rollladen_entity:
      name: Rollladen-Entity
      description: Die Entity-ID des Rollladens
      selector:
        entity:
          domain: cover
  
variables:
  fenster_azimut: !input fenster_azimut
  rollladen: !input rollladen_entity
  
triggers:
  - trigger: template
    value_template: >
      {{ state_attr('sun.sun', 'azimuth') > (fenster_azimut - 90) and state_attr('sun.sun', 'azimuth') < (fenster_azimut + 90) }}
  - trigger: numeric_state
    entity_id: sensor.wetterstation_beleuchtungsstarke
    above: 3000
  - trigger: numeric_state
    entity_id: sensor.wetterstation_temperatur
    above: 20

after that also some conditions are testet. but the problem is in the template, which does not work:
homeassistant.exceptions.TemplateError: UndefinedError: ‘fenster_azimut’ is undefined
in the respective automation the value for azimut is set.
Any idea?

When you got that error, had you set a value for the input?

You haven’t provided default values either at the input level or in the template. So if you don’t set the input, the template will fail.

You can add defaults to the input:

...
  input:
    fenster_azimut:
      name: Azimut des Fensters
      description: Der Azimut-Winkel des Fensters (Kompassgrad)
      default: 0
      selector: 
        number:
          min: 0
          max: 360
          unit_of_measurement: "°"
    rollladen_entity:
      name: Rollladen-Entity
      description: Die Entity-ID des Rollladens
      selector:
        entity:
          domain: cover
...

Or in the template:

...
trigger_variables:
  fenster_azimut: !input fenster_azimut
triggers:
  - trigger: template
    value_template: >
      {% set fenster_azimut = fenster_azimut | default(0,true) %}
      {{ (fenster_azimut - 90) < state_attr('sun.sun', 'azimuth') < (fenster_azimut + 90) }}
  - trigger: numeric_state
    entity_id: sensor.wetterstation_beleuchtungsstarke
    above: 3000
  - trigger: numeric_state
    entity_id: sensor.wetterstation_temperatur
    above: 20

or both, but that shouldn’t be necessary.

EDIT: Added trigger_variables as mentioned below by petro… which I completely missed :man_facepalming:

You need to use trigger_variables to input fenster_azimut because variables is resolved between triggers and conditions, where trigger_variables are resolved before.