Make the colors random of Hue or RGB light

I have made a small rule that you can use to have a random/different color on your Hue or RGB lights

val java.util.Random rand = new java.util.Random

rule "testbutton" 
when 
 Item TestButton changed 
then 

    // these pairs are the numbers that make the color
    val firstColor = newArrayList(  0,  0, 6, 11, 14, 15, 28, 35, 38, 39, 40, 44, 53, 61, 120, 143, 340)
    val secondColor = newArrayList(14,100,78, 66, 85,100 ,90,100,100 ,56, 45, 80, 81, 28, 100, 100, 100)
    // set the level of the lichts
    val level = 1

    // first choose one randomly
    var choice = rand.nextInt(firstColor.size-1)
    // use the random number of the color pairs
    var color = new HSBType(new DecimalType(firstColor.get(choice)), new PercentType(secondColor.get(choice)), new PercentType(level) )
    HueFirstLightColor.sendCommand(color)

    // repeat for every light
    choice = rand.nextInt(firstColor.size-1)
    color = new HSBType(new DecimalType(firstColor.get(choice)), new PercentType(secondColor.get(choice)), new PercentType(level) )
    HueNextLightColor.sendCommand(color)


end

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.