The wife and I have recently finished a living room renovation project which included new ceiling lights. We opted for Philips Hue spots as accent lights. One thought led to another and I wondered how one would control theses lights in a way that a column would light up sequentially, as in a light show - one light turning on, then off, after another. I suspected that a for-loop would be the most practical way and started experimenting with rules (this was just an exercise to expand my knowledge of rules. I have no intention of turning the living room into a disco!) After googling I learned that the Rules DSL equivilant is a forEach loop. When I wrote the rule the order of the lights turning on were out of order (lights 3, 4, 5, 1, 2 turned on sequentially.) After more googling I added a line to sort the items in the group…"gLights.members.sortby[name] - that line resulted in the lights firing in order of 3, 4, 5, 2, 1…very strange. After more googling I finally got the code needed to successfully accomplish the task - provided by non other than @rikoshak:
Hallway_Spots.members .sortBy[name] .forEach [spot | spot.sendCommand(ON) Thread::sleep(150) spot.sendCommand(OFF) Thread::sleep(100) ]
With this success I was interested in learning more about the “members.sortBy” and “members.forEach” statements, but I couldn’t find any documentation. Is there a source where I could learn more about these, and other statements available in the Rules DSL? I tried looking at X-Text, X-base, and X-tend sources but they didn’t match up with openHAB’s rules DSL.
- Platform information:
- Hardware: i7 based miniPC
- OS: Ubuntu 20.04
- Java Runtime Environment: openJDK 11
- Issue of the topic: lessons learned from forEach loops