Scheduling rule for thermostat help needed

Hi ,

I apologise if this is not relevant as it is relating to HestiaPi which is an openhab based themostat .

I need someone who is wiser than myself to check my scheduling rule and advise me on corrections and if it would work at all.

these are my item, sitemap and rules files but edited to some degree to only show relevant entries

default items

Switch HeatingPin23 "Heating" { gpio="pin:23", mqtt=">[mosquitto:hestiapidown/local/heatingstate:command:ON:1],>[mosquitto:hestiapidown/local/heatingstate:command:OFF:0],<[mosquitto:hestiapidown/local/heatingstate:state:MAP(binary.map)]" }


String MyTemp "Temperature" <temperature> { channel="exec:command:gettemp:output" }
Number MyTempProxy "Temperature [%.1f °C]" <temperature> { mqtt=">[mosquitto:hestiapidown/local/temperature:state:*:default]" }

String MyHumi "Humidity" <humidity> { channel="exec:command:gethumi:output" }
Number MyHumiProxy "Humidity [%.0f %%]" <humidity> { mqtt=">[mosquitto:hestiapidown/local/humidity:state:*:default]" }

String MyPressure "Pressure" <pressure> { channel="exec:command:getpress:output" }
Number MyPressureProxy "Pressure [%.2f hPa]" { mqtt=">[mosquitto:hestiapidown/local/pressure:state:*:default]" }

Number TempSetpoint "Temperature Setpoint[%.1f °C]" { mqtt=">[mosquitto:hestiapidown/local/tempsetpoint:state:*:default],<[mosquitto:hestiapidown/local/settempsetpoint:command:default]"}
Number TempSetpointChart "Heating Setpoint" (charts)
Switch IncTargetTemp "IncTargetTemp"
Switch DecTargetTemp "DecTargetTemp"
Number TargetTemp
Number PreviousTempReading "Temperature" <temperature> (charts)

Number HeatingBoostTime "Heating Boost Time [%.0f min]"
Switch HeatingBoostTimeDec "HeatingBoostTimeDec"
Switch HeatingBoostTimeInc "HeatingBoostTimeInc"

String HeatingMode "Heating Mode"
Switch MainSwitch "MainSwitch"
String HeatingTimer "Heating Timer"

default rules


rule "Initialisation"
when
    System started
then
    MainSwitch.sendCommand("OFF")
    HeatingMode.sendCommand("OFF")
    HotWaterMode.sendCommand("OFF")
    HumiMode.sendCommand("OFF")
    HeatingTimer.sendCommand("OFF")
    /**CELSIUS*/ if(TempSetpoint.state == NULL) postUpdate(TempSetpoint, 18)
    /**CELSIUS*/ if(TempSetpoint.state > 40) postUpdate(TempSetpoint, 18)
    //FAHRENHEIT if(TempSetpoint.state == NULL) postUpdate(TempSetpoint, 70)
    //FAHRENHEIT if(TempSetpoint.state < 32) postUpdate(TempSetpoint, 70)
    if(HumiSetpoint.state == NULL) postUpdate(HumiSetpoint, 50)
    if(HeatingBoostTime.state == NULL) postUpdate(HeatingBoostTime, 10)
    if(HotWaterBoostTime.state == NULL) postUpdate(HotWaterBoostTime, 10)
    if(HumiBoostTime.state == NULL) postUpdate(HumiBoostTime, 10)
    TempSetpointChart.sendCommand(0);
    HumiSetpointChart.sendCommand(0);
    PreviousTempReading.sendCommand(0);
    PreviousHumiReading.sendCommand(0);
    chart_period.sendCommand(0);
end



rule "checkcurrtemp"
when
  Item TempSetpoint changed or
  Item PreviousTempReading changed
then
  if (MyTempProxy.state > TempSetpoint.state){
    HeatingPin23.sendCommand(OFF)
    TempSetpointChart.sendCommand(0)
  } else if ((MyTempProxy.state < TempSetpoint.state) &&
      ((HeatingMode.state=="ON") || (HeatingMode.state=="Boost") || (HeatingTimer.state=="ON"))) {
    HeatingPin23.sendCommand(ON)
    TempSetpointChart.sendCommand(TempSetpoint.state)
  }
end



rule "Heating Mode"
when
    Item HeatingMode changed
then
    switch(HeatingMode.state) {
      case "ON": {
        if (MyTempProxy.state < TempSetpoint.state) {
          HeatingPin23.sendCommand(ON)
          TempSetpointChart.sendCommand(TempSetpoint.state)
        }
        HeatingTimer.sendCommand("OFF")
        MainSwitch.sendCommand("ON")
        HeatingPreviousMode="ON"
      }
      case "OFF": {
        HeatingTimer.sendCommand("OFF")
        HeatingPin23.sendCommand(OFF)
        TempSetpointChart.sendCommand(0)
        HeatingPreviousMode="OFF"
      }
      case "TIMER": {
        HeatingPreviousMode="TIMER"
      }
      case "Boost": {
        HeatingTimer.sendCommand("OFF")
        MainSwitch.sendCommand("ON")
        // See below more...
      }
    }
end


rule "Heating Timer"

when
	Time cron "0 * * * * ?" or
	Item HeatingMode changed
then
    TStartOne = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 6, 0, 0)
    TEndOne   = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9,  0, 0)

    TStartTwo = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 17, 0, 0)
    TEndTwo   = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 22,  0, 0)

    if((HeatingMode.state == "TIMER") && ((now.isBefore(TEndOne)) && (now.isAfter(TStartOne)) || (now.isBefore(TEndTwo)) && (now.isAfter(TStartTwo)))) {
         postUpdate(TempSetpoint, 20)
         HeatingTimer.sendCommand("ON")
    }
    
    if((HeatingMode.state == "TIMER") && ((now.isAfter(TEndOne)) && (now.isBefore(TStartTwo)) || (now.isAfter(TEndTwo)) && (now.isBefore(TStartOne)))) {
         postUpdate(TempSetpoint, 16)
         HeatingTimer.sendCommand("ON")
    }

    if (HeatingMode.state == "ON") {
	     HeatingTimer.sendCommand("OFF")
    }

    if (HeatingMode.state == "OFF") {
	     HeatingTimer.sendCommand("OFF")
    }

    if (HeatingMode.state == "Boost") {
	     HeatingTimer.sendCommand("OFF")
    }
  
end






rule "MainSwitch"
when
    Item MainSwitch changed
then
    switch(MainSwitch.state) {
      case ON:{
        // Do nothing
      }
      case OFF:{
        if (HeatingMode.state == "ON") {
          HeatingPreviousMode = "ON"
          HeatingMode.sendCommand("OFF")
        } else if (HeatingMode.state == "TIMER") {
		  HeatingPreviousMode = "TIMER"
		  HeatingMode.sendCommand("OFF")
        } else if (HeatingMode.state == "Boost") {
          //This should never execute
          HeatingPreviousMode="Boost"
          HeatingMode.sendCommand("OFF")
        }

        if (HeatingTimer.state == "ON") {
		  HeatingTimer.sendCommand("OFF")
	  }
       }
    }
end

sitemap

Frame label="Heating" {
    Switch item=HeatingMode mappings=[ "ON"="ON", "OFF"="OFF", "TIMER"="TIMER", "Boost"="BOOST"]
    Text item=MyTempProxy
    Setpoint item=HeatingBoostTime minValue=10 maxValue=1440 step=10 icon="clock"
    /**CELSIUS*/ Setpoint item=TempSetpoint minValue=0 maxValue=40 step=0.5 icon="temperature"
    //FAHRENHEIT Setpoint item=TempSetpoint minValue=32 maxValue=86 step=1 icon="temperature"
  }

now the only thing I have changed is adding the TIMER and editing existing rules and items to suit the added function I not really great with these sorts of things and have put together this from a other few peoples projects but before I implement I wanted to know if it could be done any better or even work at all .

I am aware that some people don’t recommend using a timer but rather an event driven rule .
but ideally a timer/scheduler would really suit my needs.

Based on my rules “Heating Timer” my logic suggests this should if Timer is “ON”, turn the heating ON and set the temp at 20°C between the hours of 06:00 - 09:00 and 17:00 -22:00 and then set the temp to 16°C at all other times is this correct?

thank you in advance for any help .