Add foreach loop in script

Tags: #<Tag:0x00007f73a5586cc0>

I think it would be useful to add foreach as a new type of loop to repeat, as it is not always easy/possible/nice to do it using repeat.index.

Additional related ideas:

  • Saving current value in repeat.value
  • Iterating over arrays created using jinja template
    (e.g. {{ state_attr('group.all_devices', 'entity_id') }})

Calling @pnbruckner (creator of repeat action)

1 Like

why not make life easier? Use Node Red. You can write functions in JavaScript.

I don’t need NR, I can do everything in HA. If I want to write code I use built-in python script.


Could you give an example of how it could be used? Maybe provide some pseudo-code.

Another example use case:

My idea was to use it to call the same service with increasing delays between calls. There are a lot of potential uses :slight_smile:

A draft PR has been created. Still need to create tests and update docs.

1 Like