Make "holiday switch" to specify at what time a rule is executed

I have a rule to open the rollershutters in the bedrooms. On weekdays the time is different than on weekends. That is rather easily done with cron times.

rule "Zeitsteuerung_Rolladen_Schlafzimmer_Hoch"
when
 Time cron "0 0 7 ? * MON-FRI *" or Time cron "0 30 8 ? * SAT,SUN *"
then
  FF_MasterBedroom_Shutter.sendCommand(UP)
end

What I want to do now is to have a switch item with which I can define if it is a holiday or not. I already have an item defined:

Switch          Holiday         "Holiday"         <vacation>               (Home)  

and editet the sitemap so that a switch appears in the basic ui:

Text label="Holiday" icon="vacation" {
            Default item=Holiday label="Holiday"
        }

What I do not know how to do now is how to integrate the state of that switch in the rule. If it is on, the rollershutter should go up at the late time, even if it is a workday.

Simplest; make two rules with different cron triggers. In the body of the rule, test holiday switch before carrying out the action. e.g.

when
 Time cron "0 0 7 ? * MON-FRI *" or Time cron "0 30 8 ? * SAT,SUN *"
then
   if (holiday.state != ON) {
     FF_MasterBedroom_Shutter.sendCommand(UP)
   }

// other rule, different cron

   if (holiday.state == ON) {

1 Like

That is almost embarrassingly simple. :slightly_smiling_face: It will double the lines of code in the rules, which is probably why I did not think of this. Thank you.

This costs you nothing.

The alternative “one rule” approach means you’d have to run the rule at every possible time, and add code in the rule to compare “now” with target hours of day to see if action is due this time.

The technical and flexible way is to run a scheduling job at midnight to schedule jobs for the day ahead. That rapidly becomes complicated when you must add in code to deal with reboot durng the day, change of holiday condition during the day, etc.

Yes, thats true.

Ok, implemented. Test is working ok, and if I did not make a copy/paste error in one of the rules for the many rollershutters we will not wake up prematurely tomorrow.