Value template trigger with duration (for)

Hi!
Cannot make it work.
My sensor is not int type, unfortunately, so I need to convert it prior to mathematical comparison, thus I need to use a value template instead of the numeric state. I used for 1 minute, as the value sometimes may change, thus I need to make sure it keeps stable within the pre-selected range in automation for some time.

Trigger doesn’t launch if I use duration.

alias: Outside Lighting Setup
description: ""
trigger:
  - platform: template
    value_template: |-
      {{ states('sensor.tasmota_bh1750_illuminance')|int < 10 }}
      for: "00:01:00"
    id: night
  - platform: template
    value_template: >-
      {{states('sensor.tasmota_bh1750_illuminance')|int  < 750 and
      states('sensor.tasmota_bh1750_illuminance')|int > 20 }}
      for: "00:01:00"
    id: twilight
  - platform: template
    value_template: |-
      {{ states('sensor.tasmota_bh1750_illuminance')|int > 800 }}
      for: "00:01:00"
    id: daylight
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: daylight
        sequence:
          - service: input_select.select_option
            data:
              option: daylight
            target:
              entity_id: input_select.outside_lighting_lux
      - conditions:
          - condition: trigger
            id: twilight
        sequence:
          - service: input_select.select_option
            data:
              option: twilight
            target:
              entity_id: input_select.outside_lighting_lux
      - conditions:
          - condition: trigger
            id: night
        sequence:
          - service: input_select.select_option
            data:
              option: night
            target:
              entity_id: input_select.outside_lighting_lux
    default: []
mode: single

The problem is due to incorrect indentation of the for option. It should be vertically aligned with the other options (platform, value_template, and id).

Move for to the left by two spaces.

For more information, refer to the documentation for Template Trigger.

“for” worked out, however I cannot manage to get conversion to INT working. In my case my Tasmota sensor sends something like string and I supposed my syntax would convert it to INT but the trigger couldn’t be launched unfortunately.
When I experimented with same syntax in templates section, the math operations are OK.
What can be wrong?

You should specify a default value for the int filter in case it’s unable to convert the sensor’s value from string to integer. In the following example, the default value for int is zero.

{{ states('sensor.tasmota_bh1750_illuminance') | int(0) > 800 }}

You should be aware that the Template Trigger you created will trigger only when the sensor’s value increases from below 800 to above 800. In other words, it triggers at the moment the value crosses the threshold. If the sensor’s value is already over 800 and continues to increase, it won’t trigger the Template Trigger.

Hm… You’re right regarding the threshold. I lost track of this detail.
How would you recommend to realize a trigger that would fire everytime the value is higher than “800” regardless of threshold?

I think {{ states('sensor.tasmota_bh1750_illuminance') | int(0) > 800 }}
and

for: "00:01:00"

might be mutually exclusive.

If my illuminance value changes promptly from below 800 to above 800, then 1 minute might be to long period for trigger duration and it may not fire at all.

You may wish to use a State Trigger to trigger for any of the sensor’s state-changes and then use a condition to constrain it to whatever you want.

In case of Condition I cannot use duration for
Initially I was about to do that.

Correct. But given that you said this I thought you were giving up on the idea of employing a for anywhere.