Tirador
September 1, 2023, 12:06pm
1
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
123
(Taras)
September 1, 2023, 2:42pm
2
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 }}'
Tirador
September 1, 2023, 3:54pm
3
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.
123
(Taras)
September 1, 2023, 3:59pm
4
Post the entire blueprint.
Tirador
September 1, 2023, 4:01pm
5
Ok
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).
123
(Taras)
September 1, 2023, 4:38pm
6
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
).
Sir_Goodenough
((SG) WhatAreWeFixing.Today)
September 1, 2023, 6:39pm
7
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.
Tirador
September 2, 2023, 9:50am
8
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?
123
(Taras)
September 2, 2023, 1:33pm
10
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
Tirador
September 3, 2023, 8:06am
11
I tried that.
Incorrect type. Expected “object”:
Tirador
September 3, 2023, 8:16am
12
There is no complete grammar of the yaml-Language. It´s mostly guessing the right syntax
123
(Taras)
September 3, 2023, 1:58pm
13
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.
123
(Taras)
September 3, 2023, 2:04pm
14
For future reference, the correct indentation of choose
and delay
is explained in the Script Syntax documentation.