Using variables in wait trigger statement

I have a simple automation that turns on ventilation in the bathroom if humidity exceed 80% and turn if off again when humidity get below 60%. Now I want to extend my script so the wait trigger for turning off the ventilator using a variable value ‘target_humidity’. the value of the ‘target_humidity’ variable is set as livingroom.humidity +5%
The code is as follows;

alias: Lille bad ventilationstyring
description: Start udsugning hvis luftfugtigheden bliver for høj
trigger:
  - type: humidity
    platform: device
    device_id: d919066ef54386220e1d14f342b4ba69
    entity_id: sensor.0x00124b0022cea1b0_humidity
    domain: sensor
    above: 80
condition: []
action:
  - type: turn_on
    device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
    entity_id: switch.0x540f57fffefc3903
    domain: switch
  - wait_for_trigger:
      - type: humidity
        platform: device
        device_id: d919066ef54386220e1d14f342b4ba69
        entity_id: sensor.0x00124b0022cea1b0_humidity
        domain: sensor
        below: 60
        for:
          hours: 0
          minutes: 1
          seconds: 0
    timeout:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
    entity_id: switch.0x540f57fffefc3903
    domain: switch
mode: single

I understand that I must create a variable but the syntax is unknown for me. In the graphic editor I can select the name of the device but in the YAML it is a device ID of some sort.
I am an experienced C# developer but in HA I am a beginner. I assume that I can replace the line below: 60 with something like below: {{ target_humidity }} but maybe variables is not supported here …
Any help or pointers to examples to use is highly appreciated. Thanks

You can’t use templates with device IDs - you need to use entity states instead.

You have the right idea but Device Triggers don’t support templates.

Use a Numeric State Trigger but even that doesn’t support templating the above and below options. However, it will accept the name of a sensor or input_number entity.

Thanks to @Stiltjack and @Taras for pointing me to Numeric State Trigger, and I now can reference another sensor as below value. As you wrote it does not support templates so I assume that equal variables. The code now looks like the following;

alias: Lille bad ventilationstyring
description: Start udsugning hvis luftfugtigheden bliver for høj
trigger:
  - platform: numeric_state
    entity_id: sensor.0x00124b0022cea1b0_humidity
    above: 80
condition: []
action:
  - type: turn_on
    device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
    entity_id: switch.0x540f57fffefc3903
    domain: switch
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.0x00124b0022cea1b0_humidity
        for:
          hours: 0
          minutes: 2
          seconds: 0
        below: sensor.0x00124b0022ce9963_humidity
    timeout:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
    entity_id: switch.0x540f57fffefc3903
    domain: switch
mode: single

The sensor reference is still a device like ID and not the logical name as selected in the graphical editor … strange :thinking:

So, if I need to offset the below humidity with the sensor value +5%, I cannot do this in HA. I need to use another tool like NodeRed to obtain this logic?

Incorrect, you can add a value template to your Numeric state trigger or use a Template trigger.
In most cases it is better to use a Template trigger.

...
  - wait_for_trigger:
      - platform: template
        value_template: |
          {{ states('sensor.0x00124b0022cea1b0_humidity') | float <
          states('sensor.0x00124b0022ce9963_humidity') | float + 5 }}
        for:
          hours: 0
          minutes: 2
          seconds: 0
....