mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 23:36:51 +00:00
Add for each item support to repeat action (#22400)
This commit is contained in:
parent
f36774bfc9
commit
6f92bbdcb9
@ -411,6 +411,53 @@ script:
|
|||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
|
||||||
|
### For each
|
||||||
|
|
||||||
|
This repeat form accepts a list of items to iterate over. The list of items
|
||||||
|
can be a pre-defined list, or a list created by a template.
|
||||||
|
|
||||||
|
The sequence is ran for each item in the list, and current item in the
|
||||||
|
iteration is available as `repeat.item`.
|
||||||
|
|
||||||
|
The following example will turn a list of lights:
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
repeat:
|
||||||
|
for_each:
|
||||||
|
- "living_room"
|
||||||
|
- "kitchen"
|
||||||
|
- "office"
|
||||||
|
sequence:
|
||||||
|
- service: light.turn_off
|
||||||
|
target:
|
||||||
|
entity_id: "light.{{ repeat.item }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
|
Other types are accepted as list items, for example, each item can be a
|
||||||
|
template, or even an mapping of key/value pairs.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
repeat:
|
||||||
|
for_each:
|
||||||
|
- language: English
|
||||||
|
message: Hello World
|
||||||
|
- language: Dutch
|
||||||
|
hello: Hallo Wereld
|
||||||
|
sequence:
|
||||||
|
- service: notify.phone
|
||||||
|
data:
|
||||||
|
title: "Message in {{ repeat.item.language }}"
|
||||||
|
message: "{{ repeat.item.message }}!"
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
### While Loop
|
### While Loop
|
||||||
|
|
||||||
This form accepts a list of conditions (see [conditions page] for available options) that are evaluated _before_ each time the sequence
|
This form accepts a list of conditions (see [conditions page] for available options) that are evaluated _before_ each time the sequence
|
||||||
|
Loading…
x
Reference in New Issue
Block a user