I’m attempting to use “for_each” in a script which was introduced in the 2022.5 release, I’m using 2022.6.5.
As “for_each” isn’t available as a repeat type in the visual editor, I’m using the example from here Script Syntax - Home Assistant in the script YAML editor as a starting point. Although the YAML editor doesn’t show any formatting errors, I get the following error when I save the script
Message malformed: extra keys not allowed @ data[‘repeat’]
Here’s my test script
alias: For Each Test
mode: single
repeat:
for_each:
- "living_room"
- "kitchen"
- "office"
sequence:
- service: light.turn_off
target:
entity_id: "light.{{ repeat.item }}"
If that is a script it needs to be formatted like this:
script:
for_each_test:
alias: For Each Test
mode: single
sequence: ### <------ You are missing this
- repeat:
for_each:
- "living_room"
- "kitchen"
- "office"
sequence:
- service: light.turn_off
target:
entity_id: "light.{{ repeat.item }}"
There’s no need for a “for each” to do this though. You can just do:
script:
lights_off:
alias: Lights Off
mode: single
sequence:
- service: light.turn_off
target:
entity_id:
- light.living_room
- light.kitchen
- light.office
Sorry for disturbing again regarding this topic.
Actually I understood everything and now I wonder, whether there is an error in Studio Code Server? When I type code like this: