I’m trying to understand nested repeat loops for a script I’m working on. When I try to nest a repeat
for_each:
loop inside another like this:
mode: parallel
alias: banana
sequence:
- repeat:
for_each:
- "living_room1"
- "kitchen1"
- "office1"
sequence:
- delay:
seconds: 1
- service: light.turn_off
data:
transition: 0
target:
entity_id: light.office_lamp
- service: light.turn_on
data:
transition: 0
target:
entity_id: light.office_lamp
- repeat:
for_each:
- "living_room2"
- "kitchen2"
- "office2"
sequence:
- delay:
seconds: 1
- service: light.turn_off
data:
transition: 0
target:
entity_id: light.office_lamp
- service: light.turn_on
data:
transition: 0
target:
entity_id: light.office_lamp
I get the error:
2024-03-29 06:08:45.430 ERROR (MainThread) [homeassistant.components.script] Script with alias 'banana' could not be validated and has been disabled: extra keys not allowed @ data['sequence'][0]['repeat']['sequence'][3]['sequence']. Got [{'delay': {'seconds': 1}}, {'service': 'light.turn_off', 'data': {'transition': 0}, 'target': {'entity_id': 'light.office_lamp'}}, {'service': 'light.turn_on', 'data': {'transition': 0}, 'target': {'entity_id': 'light.office_lamp'}}]
required key not provided @ data['sequence'][0]['repeat']['sequence'][3]['repeat']['sequence']. Got None
After commenting out the nested loop the script validates and runs fine, flashing my light three times.
mode: parallel
alias: banana
sequence:
- repeat:
for_each:
- "living_room1"
- "kitchen1"
- "office1"
sequence:
- delay:
seconds: 1
- service: light.turn_off
data:
transition: 0
target:
entity_id: light.office_lamp
- service: light.turn_on
data:
transition: 0
target:
entity_id: light.office_lamp
#- repeat:
# for_each:
# - "living_room2"
# - "kitchen2"
# - "office2"
# sequence:
# - delay:
# seconds: 1
# - service: light.turn_off
# data:
# transition: 0
# target:
# entity_id: light.office_lamp
# - service: light.turn_on
# data:
# transition: 0
# target:
# entity_id: light.office_lamp
Why is my nested loop invalid? What have I missed in the documentation?
This script is just for debugging and understanding the issue. In the real script I’m working on, the repeat
for_each:
at line 1091 is nested inside the repeat
for_each:
started at line 930. So I know it’s possible to do, but I can’t get add a third nest loop. I must be missing something, so I’m trying to simply the problem with this script.