Philips Hue - Random Lights

Here is a rule I came up with to randomize the Hue lights throughout the house. I wanted a ‘party mode’ which constantly changes colors. This did the trick (changes every 2 seconds, for a little over 3 minutes):

Items:

Group:Switch:OR(ON,OFF)	 		LightsLava 		"Lava Lamps" 				<hue>					(All)
Number Scene_Lighting				"Scene (Lighting)"		<colorwheel>

Rule:

rule "Lighting Scene - LightsLava Switch On"
when
	Item LightsLava received command ON
then
        var Number fadeCounter 	
	//RAPIDLY CHANGE HSB FOR ALL LIGHTS ON
	fadeCounter=0
	while(fadeCounter<100 && Scene_Lighting.state == 2 && LightsLava.state == ON) {
         fadeCounter=fadeCounter+1
      	 Lights?.members.forEach(light|
		 sendCommand(light, (((Math::random * 255).intValue)) + "," + (((Math::random * 100).intValue)) + "," + (((Math::random * 100).intValue)))
	 )  
         Thread::sleep(2000)
	}

	//Switch OFF and return to relaxing colors
	postUpdate(LightsLava, OFF)
	sendCommand(Scene_Lighting, 4)
end

Have some cool lighting rules of your own? Please share!!!

3 Likes

Here is my lighting rule, but I think I might adapt yours, but I would like to run yours as long as the switch is on, how to achieve that? Best would be to sync light with music or?

rule "Party time"
	when 
		Time cron "*/15 * * * * ?" //AND partyMode=true
	then
		if (partyMode=true) {
			redColor = (new java.util.Random).nextInt(255)
			greenColor = (new java.util.Random).nextInt(255)
			blueColor = (new java.util.Random).nextInt(255)
			
			hsbValue = HSBType::fromRGB(redColor, greenColor, blueColor)
			Group_DMX_LivingRoom.members.forEach[l|l.sendCommand(hsbValue)]
		}
end