Rule assistance

Good afternoon.

Giving it is the festive period as probably the same as a lot of your selves I have been organising my Christmas decorations!

I currently have a rule in place that works great but only want it active when say switch item ChristmasLights is ON. When ChristmasLights is OFF I don’t want the rule to run.

Here is my current rule. Can somebody help improve the rule please.

rule "Turn Front Christmas Lights On"
when
Item  Night_State  changed from OFF to ON
then

sendCommand(Front_Outdoor_Socket, ON)
end


rule "Turn Front Christmas Lights Off"
when
Time cron "0 0 23 1/1 * ? *"
then
sendCommand(Front_Outdoor_Socket,OFF)
end
rule "Turn Front Christmas Lights On"
when
Item  Night_State  changed from OFF to ON
then
if (ChristmasLights.state == ON) {
sendCommand(Front_Outdoor_Socket, ON)
}
end


rule "Turn Front Christmas Lights Off"
when
Time cron "0 0 23 1/1 * ? *"
then
if (ChristmasLights.state == ON) {
sendCommand(Front_Outdoor_Socket,OFF)
}
end

The rules themselves will always run, because rules can only be triggered by events, but the commands will only be sent if ChristmasLights is ON.

If it was me, I would probably not use the IF in the second rule, so that the socket is always sent an OFF command each day. This would prevent that socket staying ON if ChristmasLights was switched off at some point after the outdoor socket was switched on.

Thank you very much. I will do what you said and not put the if on the second part of the rule. Enjoy the rest of your evening :grinning:

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