While Loops

Can someone explain what this loop i wrote is doing…or more likely…doing wrong?
The goal here was to switch the hue color every 20 seconds as defined by that times.
What i see happening is it changed every second.
I thought the if else would escape once the first condition is met…however it looks like it continues in the loop checking each condition? The reason i say that is i see the color changing every second when i run this.

Setting one color switch on(as in the loop), will set the colors and subsequently turn all other color switches off.
So when this happens: sendCommand(KitchenHuePurpleSwitch,ON)
it fires that switch on which sets the color to purple and turns off all switches(red, blue, etc) if they are on.

while (ColorHueParty1.state == ON){
HueParty1Timer = createTimer(now.plusSeconds(20))[|
if (KitchenHueRedSwitch.state == ON){
sendCommand(KitchenHuePurpleSwitch,ON)

		}
		else if (KitchenHuePurpleSwitch.state == ON){
			sendCommand(KitchenHueBlueSwitch,ON)
			
		}		
		else if (KitchenHueBlueSwitch.state == ON){
			sendCommand(KitchenHueLightBlueSwitch,ON)
			
		}
		else if (KitchenHueLightBlueSwitch.state == ON){
			sendCommand(KitchenHueGreenSwitch,ON)
			
		}
		else if (KitchenHueGreenSwitch.state == ON){
			sendCommand(KitchenHueYellowSwitch,ON)
			
		}
		else if (KitchenHueYellowSwitch.state == ON){
			sendCommand(KitchenHueOrangeSwitch,ON)
			
		}
		else if (KitchenHueOrangeSwitch.state == ON){
			
		}
	HueParty1Timer = null
	]
}

It looks to me as if your loops fires another timer during each run.
What is the trigger of your rule
.
I think you don’the need a loop at all. By using a trigger like PurpleSwitch.States changed or Blue witch. State changed… you can trigger a rule that uses a timer to switch the lamp using your if code.

when ColorHueParty1 changed from off to on is the trigger

yeah i see what you are saying, i could rewrite it all to key off of each colors state change and then put an individual timer in each one i suppose

Just one rule like:

Rule "HuePartyTime"
when
  (ColorHueParty1 changed from off to on) and (KitchenHuePurpleSwitch.state changed or KitchenHueLightBlueSwitch.state changed or.....)
then 
    HueParty1Timer = createTimer(now.plusSeconds(20))[|
    if (KitchenHueRedSwitch.state == ON){       
      sendCommand(KitchenHuePurpleSwitch,ON)
        }
      else if (KitchenHuePurpleSwitch.state == ON){
        sendCommand(KitchenHueBlueSwitch,ON)
        }   
      else if (KitchenHueBlueSwitch.state == ON){
          sendCommand(KitchenHueLightBlueSwitch,ON)
        }
      else if (KitchenHueLightBlueSwitch.state == ON){
          sendCommand(KitchenHueGreenSwitch,ON)
        }
      else if (KitchenHueGreenSwitch.state == ON){
          sendCommand(KitchenHueYellowSwitch,ON)
        }
      else if (KitchenHueYellowSwitch.state == ON){
          sendCommand(KitchenHueOrangeSwitch,ON)
        }
      else if (KitchenHueOrangeSwitch.state == ON){
        }
      HueParty1Timer = null
      ]
    }
end

Now that i look at that, if there is no loop, it would only change one time right? Wouldn’t that timer only run one time thereby changing the color only once?

I would turn on ColorHueParty1 as the trigger…and some other color(which i don’t really want to do but for the sake of discussion let’s say i do).

The timer waits 20 secs and changes the color once.
Then, that is it…it wouldn’t color cycle anymore

Yes are correct, my mistake!
That rule should trigger in case of any switch change (all seperated by or!) and in the “then” you need to surround all with the if-clause which is checking wether the ColorHueParty1 is On! Sorry for that.