Blueprint: Delay in "repeat until" calling sequence template

Hello, I´m trying to loop through a sequence template in a blueprint.
After each iteration I want to add a delay in the loop.
Does anybody know how to do it?

          sequence:
            - repeat:
                while: '{{ repeat.index < button_2_long_max_loop_repeats | int }}'
                sequence: !input button_2_held
                - delay:
                   hours: 0
                   minutes: 0
                   seconds: 0
                   milliseconds: !input longpress_duration

I suggest you define a variable and assign it the value of longpress_duration

  - variables:
      longpress: !input longpress_duration

Use the variable in a template:

  - delay:
      milliseconds: '{{ longpress }}'

Thanks for your input.

The problem is that the syntax above is ok at edit time but in the automatations the template “is not available”.

I don´t know how to call the sequence first and then add a delay in the while-loop.

Post the entire blueprint.

Ok :slight_smile:

raw.githubusercontent.com/St0Ma/homeassistant/main/enocean-ptm-215z-friends-of-hue-switch_st0ma.yaml

Explanation:
The blueprint is a controller for a zigbee switch (Enocean).
I´m emulating a “hold button” because the device doesn´t send that event natively.
When the user holds the button actions should be iteratively executed.
Therefore the next event should be first executed after the delay time.

Example:
When holding the up button a light should dim up (while holding the button the dimming is +10 percent at half a second).

Your blueprint already has this section where variables are created from input tags.

variables:
  # convert input tags to variables, to be used in templates

Just define the longpress variable there then use longpress in templates wherever needed (like in delay).

The duration selector is good for this, except there doesn’t seem to be a sub-second component.
You can test something like 0.5 seconds but I don’t know if that will work. Would need to test.

The Problem ist not to define a selector.

The syntax of the Script ist wrong. Hast anyone an example of a loop until with calling a sequence AND delay?

Try this:

          sequence:
            - repeat:
                while: '{{ repeat.index < button_2_long_max_loop_repeats | int }}'
                sequence:
                  - choose:
                    default: !input button_2_held
                  - delay:
                      milliseconds: !input longpress_duration

I tried that.

Incorrect type. Expected “object”:

There is no complete grammar of the yaml-Language. It´s mostly guessing the right syntax :frowning:

In the screenshot you posted, milliseconds is not sufficiently indented. Refer to the example I posted.

As for this:

        - choose:
          default: !input button_2_held

I copied that from someone else’s functional blueprint.

For future reference, the correct indentation of choose and delay is explained in the Script Syntax documentation.