Pass list of string to script and use for each to iterate over the list

I have a script that sets alarms on my android phones, it takes 3 params
device: mobile_app_sm_g986u
time: “6:55”
message: Time to Work

Issue is I’m setting multiple alarms in the automation that calls it (and other automations) and I would like to call it once with a list of the times:
times:

  • time1
    -time2

or
times: [time1, time2]

I have been unable to figure out how to get the script to read the list and spin through it, could be invalid script or I’m passing them incorrectly. Google has returned examples, but all I’ve seen use known entities and not a list of stings. Any help would be appreciated.

Please post the script you are currently using.

You will likely just need to use a Repeat for Each action. This type of repeat accepts templates that supply a list or dictionary to the for_each configuration key.

Well I had a long response typed out, but trying to duplicate the issue I wound up finding something that worked. Not sure what I did different this time, could be the quotes around the time var, could be that I passed the times as:

- "4:30"
- "4:55"

instead of [“4:30”, “4:55”]

Or most likely I hit the wrong add action button, the one outside of the repeat.

but anyway here’s what I have that’s working.
repeat:
for_each:
“{{ time }}”
sequence:
- service: notify.alexa_media_wayne_office
data:
message: “{{ repeat.item }}”


thanks for offering to help, glad I got it working.