I have a simple rule I’m trying to create to check if it is after sunset AND the date is between the day after Thanksgiving and New Years.
I found where a when statement can use “or”, but I didn’t find any examples of using “and” for a rule.
I’m also uncertain if you can use “between” in a rule.
rule "Garage Lights"
when
Item Daylight changed to OFF and ( Between Time cron "0 0 12 ? 11 FRI#4 *" and Time cron 0 0 12 31 12 ? *)
then
sendCommand(Garage_Left, HSBType::GREEN)
sendCommand(Garage_Right, HSBType::RED)
end
Rules are triggered by events, not steady conditions. You can trigger on an event and then test to see if some other condition/state is true before doing doing stuff.
Well, it is more like “as and when it changes to night” rather than checking to see if it is night, if you follow.
But yes, then you can check within the rule if that event happens on a certain day or suchlike. (i.e. is it that day now?)
Rules trigger on events. Technically only one event can occur at all times. Every further logic goes inside the rule. Example:
rule "Garage Lights"
when
Item Daylight changed to OFF
then
if (Night.state == ON) {
sendCommand(Garage_Left, HSBType::GREEN)
sendCommand(Garage_Right, HSBType::RED)
}
end