As written what you have is syntactically incorrect (sendCommand(DOWN)
to what Item?) and it doesn’t make sense what you are trying to do on this line.
As written you are:
- for each member of gZoneAchter
a. get a list of all members of gZoneAchterSwitch that are ON - sendCommand(DOWN) to ???
Put in English, you are getting the list of all members of gZonAchterSwitch that are ON twice but not doing anything with it. You are just getting the list over an over, once for each member of gZonAchter. Once you are done with that you sendCommand to nothing.
If I understand what you are trying to do you have a flag for each Rollershitter. When that Switch is ON you need to close the Rollershutter. If that is what you are trying to do you need Design Pattern: Associated Items so you can do something like:
// Get the flags that are ON
val auto = gZonAchterSwitch.members.filter[ a | a.state == ON]
// For each of the flags that are ON, send DOWN to the corresponding Rollershutter
auto.forEach[ a |
val rs = gZonAchter.members.findFirst[ r | r.name == a.name + "_Rollershutter" ]
rs.sendCommand(DOWN)
]
In words we get a list of all the members of gZonAchterSwitch that are ON. For each member of that list we get the Rollershutter associated with that switch and sendCommand DOWN to that Item.