I think I’ve found my own solution. Here’s what I came up with so others can benefit…
I have 3 Hue lights (Left of Couch, Right of Couch, and TV.
Items File Excerpt
/* Items for Hue Lights /*
Color Hue_Couch_Left_Color "Left of Couch Color" <hue> {hue="1"}
Color Hue_Couch_Right_Color "Right of Couch Color" <hue> {hue="2"}
Color Hue_Strip_TV_Color "TV Light Color" <hue> {hue="3"}
/*Party Mode empty Items */
Number LvgRm_Party_Selector "Party Mode Type"
Switch LvgRm_Party_SW "Party Mode ON/OFF"
**Sitemap Entry**
Frame label="Living Room Party" {
Selection item=LvgRm_Party_Selector label="Party Mode" mappings=["1"="All Slow Transition","2"="Color Festival"]
Switch item=LvgRm_Party_SW label="Start/Stop"
}
Rule file
rule "Party Mode Starter"
when
Item LvgRm_Party_SW received command ON
then
callScript("party_mode.script")
end
Script File (party_mode.script)
val java.util.Random rand = new java.util.Random
var Integer num
if (LvgRm_Party_Selector.state == 1) {
postUpdate(Hue_LivingRm_All, ON)
while (LvgRm_Party_SW.state != OFF && Hue_LivingRm_All.state != OFF) {
color = rand.nextInt(360)
brightness = rand.nextInt(100)
sendCommand(Hue_Couch_Left_Color,color.toString + ",100," + brightness.toString)
sendCommand(Hue_Couch_Right_Color,color.toString + ",100,"+ brightness.toString)
sendCommand(Hue_Strip_TV_Color,color.toString + ",100,"+ brightness.toString)
Thread::sleep(3000)
}
sendCommand(Hue_Couch_Left_SW, OFF)
sendCommand(Hue_Couch_Right_SW, OFF)
sendCommand(Hue_Strip_TV_SW, OFF)
postUpdate(Hue_LivingRm_All, OFF)
}
Explanation
The rule calls the script “party_mode.script” of the switch is turned on.
(Sidenote: Seems to me that scripts are able to read item states without recompiling, making them much faster when real-time updates are needed based on state.)
The script runs a while loop that checks the state of the switch as the conditional (I’ve got 2 switches in this one). A Random Number is generated at each iteration that is used for the color hue of the bulb. Then sendCommand(item, string of hue)
to each of the lights. Thread::sleep(5000)
changes it every 5 seconds.
Once the switch is turned off, it’ll turn them all off.
Seems to work for now. Updating the random number between the sendCommands adds the effect of each light changing to something different (another cool effect).
If anyone sees something I missed or is incorrect, please let me know.
Thanks.