Multiple conditions met for rule to activate

I need help creating a rule that has more then one “when” statement for it to activate. I have a rule to run my Christmas lights on at a certain time. I want the rule to be activated only when the “christmas switch” is on.

rule “ChristmasLightsOn”
when
Time cron “0 15 17 1/1 * ? *”
and
Item christmas received update ON
then
{
sendCommand(GarageCeilingOutlet, ON)
sendCommand(BackyardOutlet, ON)
sendCommand(GarageWallOutlet, ON)
sendCommand(UpStairsSnowflakes, ON)
sendCommand(ChristmasTreeLights, ON)
}
end

I am not at my computer right now, but it’s something like

then
if (ChristmasSwitch.state == “ON”)
{
Sendcommand()
}

The When clause is only able to hold OR statements. This is because you trigger on events and not an states. In the body of the rule you should add then the AND statements like mikey has described

rule "ChristmasLightsOn" when Time cron "0 15 17 1/1 * ? *" then if (ChristmasSwitch.state == "ON") { sendCommand(GarageCeilingOutlet, ON) sendCommand(BackyardOutlet, ON) sendCommand(GarageWallOutlet, ON) sendCommand(UpStairsSnowflakes, ON) sendCommand(ChristmasTreeLights, ON) } end

Thomas

If the christmas switch is only named “christmas”, would the command be: if (christmas.state == “ON”) ?
Also, doesn’t a double equal sign normally mean not on equal?
Thanks for your help!

The correct Term is if (christmas.state == ON) - yes, without double quote, ON is a state, “ON” is a string.

== means equal
!= means not equal
<= means less or equal
>= means more or equal

1 Like