Hello if I have this situation:
SCRIPT_A --> TASK_A --> SCRIPT_B --> TASK_B
SCRIPT_B -->DELAY_10_SEC -->TASK_C
TASK_B will run before of after TASK_C ?
I mean, by design, of course!
Hello if I have this situation:
SCRIPT_A --> TASK_A --> SCRIPT_B --> TASK_B
SCRIPT_B -->DELAY_10_SEC -->TASK_C
TASK_B will run before of after TASK_C ?
I mean, by design, of course!
Scripts basically run in parallel. So the answer is: before.
If you want to make them serial, add a wait_template:
script:
script_a:
sequence:
- alias: task_a
...
- script.script_b
- wait_template: "{{ is_state('script.script_b', 'off') }}"
- alias: task_b
...
script_b:
sequence:
- delay: '00:00:10'
- alias: task_c
...
This can be tricky, though. What I’ve found is that when you start a script, it can be a significant amount of time before that causes a state change such that the script is shown as ‘on’. (Significant relative to how long it takes to get to the wait_template.)
One way to deal with that is to add two wait_templates: one that waits for the script to be ‘on’, then another that waits for it to be ‘off’. But that can be tricky, too, depending on how long the script runs. It’s possible the first wait_template misses the script being on entirely. But, in your case, where script_b takes at least 10 seconds to run, it should work.
If you really want to serialize, then the best way that I’ve found is with an input_boolean. It’s ugly, but it works:
input_boolean:
script_b_running:
initial: off
script:
script_a:
sequence:
- alias: task_a
...
- service: input_boolean.turn_on
entity_id: input_boolean.script_b_running
- script.script_b
- wait_template: "{{ is_state('input_boolean.script_b_running', 'off') }}"
- alias: task_b
...
script_b:
sequence:
- delay: '00:00:10'
- alias: task_c
...
- service: input_boolean.turn_off
entity_id: input_boolean.script_b_running
If script_b has a condition or wait_template of its own that could abort early, or if you ever cancel script_b while it’s running, then you have to deal with the fact that the input_boolean won’t get changed back to ‘off’, so you’d have to do that some other way.
If someone has a better way, guaranteed by design, to serialize this, I’m all ears, too!