Looping over two lists at the same time?

I would like to loop and perform an action on a list of devices, but evaluate a second list of sensors as a condition. Right now I have three pistons that close 5 different blinds but only if the window is closed. It works fine, but three pistons are running at the same time. I'm about to add more blinds to my setup, so I thought this would be a good exercise to streamline this process, so I don't have to maintain 4 or more pistons that do the same thing.

So, here's what I'd like to do...

Only individually close Shade 1, Shade 2, and Shade 3 if Sensor 1, Sensor 2, Sensor 3 contacts are closed. If Sensor 1 is closed, close Shade 1. If Sensor 2 is open, do not close Shade 2, just loop to the next one.

Thoughts? Is there a way to loop and index two lists or somehow associate the shade with the sensor, even if it's manual when creating the variable?

Dang! ChatGPT with a solution? After a couple prompts to get it to understand I wanted two lists, here's where it led me. I used lights in my example for simplicity.

Did ChatGPT generate that? If so, I'm impressed.

It did! I didn't even know if it could do webCoRE pistons, so I started simple and just asked it to turn on a light with motion from a sensor. Here's the whole conversation.

I would have loved a green snapshot with an import code, but maybe that's asking too much. :laughing:

1 Like

Ok, I don't think this is really that close. It's referencing functions and options that don't appear to exist. lol

if sensor 1 = closed then close shade1
if sensor 1 = closed AND sensor2 = closed AND sensor3 = closed then close shade1, close shade2, close shade 3

i'm not a webcore person, but having multiple conditionals might help. i used to do something similar when i had to automate a remote (before i got a bond bridge) for my shades. i would assign each shade a binary value(1, 2, 4, 8, 16, etc), then if the shade was opened, add its value. when i got to the end, depending on the total value, i would close the respective blinds

Well, this isn't exactly what I was looking for, but it appears to work. I just have to maintain two lists of devices and keep them in the same order.

(I also figured out that using expressions, you can add text to a device name to make a new device name. So, for example if you have an Office Shade device, you can use an expression to append "sensor" making reference to an Office Shade Sensor device. That would work if I had a sensor on every window, but I'm using one sensor to indicate status on a few different windows.)