[SOLVED] Time based rule

Hi All,

I read some documentation and managed to use the Cron expression maker to create a rule that successfully turns on my gas heater in winter at 5.30am and off at 10.30am, Mon-Friday.

I’d like to turn it on at 7.30am and off at 10.30am on Saturday and Sundays. I know that I can just write another two rules, but perhaps theres a more intelligent/compact way of doing it within my existing rules?

Any thoughts?


rule "Turn Heater on in June/July/Aug @ 5.30am, Monday to Friday"
   when
      Time cron "0 30 5 ? 6-8 MON,TUE,WED,THU,FRI *"
   then
      Heater.sendCommand("HeaterOn")
end

rule "Turn Heater Off in June/July/Aug @ 10.30am, Monday to Friday"
   when
      Time cron "0 30 10 ? 6-8 MON,TUE,WED,THU,FRI *"
   then
      Heater.sendCommand("HeaterOff")
end





You can have several trigger conditions combined with with “or”. For your “heating on” rule that would be:

   when
      Time cron "0 30 5 ? 6-8 MON,TUE,WED,THU,FRI *" or
      Time cron "0 30 7 ? 6-8 SAT,SUN *" 
   then

perfect!!! Thank you Thomas, I couldnt find an example with that.

My new rule :slight_smile:


rule "Turn Heater on in June/July/Aug @ 5.30am, Mon to Fri in Winter"
   when
      Time cron "0 30 5 ? 6-8 MON,TUE,WED,THU,FRI *" or

      // Turns on the Heater @ 7.30am, Sat to Sun

      Time cron "0 30 7 ? 6-8 SAT,SUN *"
   then
      Heater.sendCommand("HeaterOn")
end

rule "Turn Heater Off in June/July/Aug @ 10.30am, Mon to Fri in Winter"
   when
      Time cron "0 30 10 ? 6-8 MON,TUE,WED,THU,FRI *"
   then
      Heater.sendCommand("HeaterOff")
end


1 Like

Glad I could help.

Btw, you need to add another “or” clause to the switch of as well. Right now you heat all weekend until Monday.

Thanks, yes thats intentional. On Saturdays & Sundays, I’m home and prefer to manually control the Off of a weekend.

Hi All, ive expanded this a little now to look at Temperature state however it doesnt appear to work.

The rules that relate to HeaterTimer ON & HeaterTimer Off, work correctly. But the rule which turns the heater on/off does not.

I can see the FibaroEye1Temp item is receiving updates and changing the temp. I wonder is this related to the use of a variable? currentTemp? This may actually not be needed as the FibaroEye1Temp is already a number as defined here:

/*ZWave Motion Sensor Near Bifolds*/
Group FibaroEye1                    "Motion Sensor"                                         (Zwave)
Number FibaroEye1Lux                 "Motion Sensor [%.2f Lux]"   <sun>       (FibaroEye1)      { channel="zwave:device:512:node10:sensor_luminance" }
Number FibaroEye1Battery             "Motion Sensor [%.1f %%]"      <battery>    (FibaroEye1)     { channel="zwave:device:512:node10:battery-level" }
Number FibaroEye1Temp                "Motion Sensor [%.1f C]"     <temperature>(FibaroEye1)     { channel="zwave:device:512:node10:sensor_temperature" }
Number FibaroEye1Motion              "Motion Sensor Motion [%s]"               (FibaroEye1)     { channel="zwave:device:512:node10:sensor_binary" }
Switch FibaroEye1Alarm               "Motion Sensor Alarm [%s]"   <fire>   (FibaroEye1)         { channel="zwave:device:512:node10:alarm_general" }
Switch FibaroEye1AlarmBurglar        "Motion Sensor Alarm b [%s]" <fire>   (FibaroEye1)         { channel="zwave:device:512:node10:alarm_burglar" }
Number FibaroEye1Seismic             "Motion Sensor Seismic [%f]"                (FibaroEye1)   { channel="zwave:device:512:node10:sensor_seismicintensity" }

Any suggestions? Here is my rule:


rule "HeaterTimer ON"
when
    Time cron "0 0 6-9 ? 6-8 MON,TUE,WED,THU,FRI *" or
    Time cron "0 0 7-9 ? 6-8 SUN,SAT *"
then
    HeaterTimer.postUpdate(ON)
end

rule "HeaterTimer OFF"
when
    Time cron "0 0 9 ? 6-8 MON,TUE,WED,THU,FRI *" or
    Time cron "0 0 9 ? 6-8 SUN,SAT *"
then
    HeaterTimer.postUpdate(OFF)
end

rule "FibaroEye1 Temperature Controlled Gas Heater turns on when Temp is below 16°C. Turns off when temp is above 18°C"
when
    Item FibaroEye1Temp received update
then
    val currentTemp = FibaroEye1Temp.state as Number
    if (HeaterTimer == ON) {
        if (currentTemp < 16 ) {
            Heater.sendCommand("HeaterOn")
                logInfo("FibaroEye1Temp","Eye1 temp below 16°C, Turning on Heater")
         } else if (currentTemp > 20) {
             logInfo("FibaroEye1Temp", "Eye1 temp above 20°C, Turning off Heater")
             Heater.sendCommand("HeaterOff")
         }
    } else if (HeaterTimer == OFF) {
        if (Heater.state.toString == "HeaterOn") Heater.sendCommand("HeaterOff")
    }
end

1 Like