Loops and arrays - can't figure out how!

In my experience, going down this path in the Rules DSL is a path in the wrong direction.

I think you will find that if you put your items into a group and use the group.members.* methods you will end up with much simpler code.

For example, to do something with each item in the group:

myGroup.members.forEach[dimmer | dimer.sendCommand(foo)]

Or to get all the dimmers greater than a certain value:

val highDimmers = myGroup.members.filter[dimer|(dimmer.state as DecimalType) > foo]

Or to put them in order:

val ordered = myGroup.members.sortBy[state]

I have a pretty good description of how I use these instead of arrays and hashmaps (and basically halved my lines of code count in the process) here..

val numItems = myGroup.members.size

or count of Items above a certain dimming value

val numItems = myGroup.members.filter[(state as DecimalType) > foo].size

I could have guess you came from a structural programming language background. I did too. You will find that if you try to program in the Rules DSL the same as you would in C (i.e. create data structures and iterate over them) you will be unhappy with the size, look, and maintainability of the code. If you instead treat your Items and Groups as your data structures instead of trying to create your own within the rules your code will be shorter, cleaner, and easier to write.

If however, you can’t get into the groove of the DSL, I do recommend the JSR233 binding which lets you write your rules in Python or javascript.