"For Each" Functionality?


#1

1) Give a description of the problem
Is it possible to do a “for each” type statement in webcore?

2) What is the expected behavior?
I’d like to design a single piston that will manipulate multiple switches, and treat each on conditional on the current state of the switch. Something like:
For each switch in the group, if the switch is on, setlevel to 25, else setdefaultlevel to 25.

3) What is happening/not happening?
I have a bunch of GE Motion Dimmers (26933) that support setting the level of the switch without turning it on (setdefaultlevel). But if the switch is on and I send setdefaultlevel, it doesn’t take. I think I need to send setlevel if the switch is on. I can design a piston to check a single switch’s state, and manipulate only that switch based on the state of the switch. I’d love it if I didn’t have to create a new piston for each switch!

4) Post a Green Snapshot of the pistonimage
No image :frowning:

5) Attach any logs (From ST IDE and by turning logging level to Full)
N/A


#2

Could you put all the devices you want to set into a device variable.
Then in your piston use
Set Level device variable.


#3

Something like this? Except i just check the states


#4

This! I’m going to try to emulate this.

I haven’t seen the “define” and “settings” stuff before. Is there a “how to become amazing at webcore” somewhere that I can read?


#5

Haha just try things and ask people is the best way :wink: Let me know if it worked or not


#6

Ok, here’s what I have:

It works well enough, but I can only get it to control a single switch at a time. When I pile multiple switches into a variable, the console won’t let me send the setdefaultlevel command to the variable. I think that’s because it isn’t a “default” command? Thoughts?

I think I need to use setdefaultlevel, because my switches (GE Motion Dimmers, 26933) can use that command to set the dimmer level without turning on the switch. Hence, I’m trying to make a piston that will handle multiple devices, check the state of each one, and either setdefaultlevel (if switch off) or setlevel (if switch on). The setlevel part is fine…struggling with setdefaultlevel on multiple switches.

I can and am just cloning pistons and creating new instances for each switch, but there’s got to be a more eloquent method.

Thanks!


#7

Or you could try this. It is a for loop. It will check each device in the variable containing your devices to see if it is on and level is greater than 25. If it is, it will change to 25.


#8

You guys are awesome. I found that I still couldn’t call the custom command setdefaultlevel() to act on the $device object, so I would first enter it as though I was only working with a single switch. Then I’d go back and change the switch to $device. Works like a charm! Here’s what I’ve emerged with:


#9

Correction: with my motion dimmers, for whatever reason setdefaultlevel(100) doesn’t work. So I changed it to 99, and it does just fine :slight_smile:


#11

Thanks @Gopack2. This example was very helpful.