Timer reschedule loop will not end properly

Hi folks,
I have a problem with my timer reschedule in a rule. The reschedule loop will not end properly. The rule should shut down my heater immediately, when the window is opend. If the outside temperature is lower than 12°C and the window is opend for more than 30min I want so send a push message.

Mi_DW_WC_Status = window contact switch
Heating_Day.state = for setting my heaters to day or night temperature

val String logfilename = "heating.rules"
val Number TempMid = 19.0
val Number TempOff = 4.5
var CurrentHour = now.getHour
var Timer Timer_WC = null

rule "WC Fenster"
when
	Item Mi_DW_WC_Status changed
then
	if (Heating_Mode.state == "NORMAL" && Mi_DW_WC_Status.state == OPEN && Heating_Day.state == ON && Mi_Aqara_THP_Aussen_Temperature.state <= 12.0 | "°C") {
        ZWave_Popp_WC_Setpoint.sendCommand(TempOff)
        logInfo(logfilename, "Heating NORMAL: Fenster AUF, WC AUS")
        Timer_WC = createTimer(now.plusMinutes(30)) [| 
            sendNotification("xxx@xxx.net", "WC Fenster offen")
            if (Virtual_Window_WC.state == OFF) {
                Virtual_Window_WC.sendCommand(ON)
            }
            Timer_WC.reschedule(now.plusMinutes(30))
        ]
    }
    else if (Heating_Mode.state == "NORMAL" && Mi_DW_WC_Status.state == CLOSED && Heating_Day.state == ON && Timer_WC !== null) {
        Timer_WC?.cancel
        ZWave_Popp_WC_Setpoint.sendCommand(TempMid)
        if (Virtual_Window_WC.state == ON) {
            Virtual_Window_WC.sendCommand(OFF)
            sendNotification("xxx@xxx.net", "WC Fenster geschlossen")
        }
        logInfo(logfilename, "Heating NORMAL: Fenster ZU, WC 19°C")
    }
    else if (Heating_Mode.state == "NORMAL" && Mi_DW_WC_Status.state == CLOSED && Heating_Day.state == OFF && Timer_WC !== null) {
        Timer_WC?.cancel
    	ZWave_Popp_WC_Setpoint.sendCommand(TempOff)
        if (Virtual_Window_WC.state == ON) {
            Virtual_Window_WC.sendCommand(OFF)
            sendNotification("xxx@xxx.net", "WC Fenster geschlossen")
        }
        logInfo(logfilename, "Heating NORMAL: Fenster ZU, WC 4,5°C")
    }
end

Maybe it would be easier to write, debug, and understand if this were split into two rules, one for the “shut down the heater immediately” and another for the "outside temp is lower than 12 °C and the window is open.

The first would be very simple, triggered by the window Item changing to OPEN. You just need an if(HeaterItem.state == ON) HeaterItem.sendCommand(OFF) (use what ever commands make sense for the heater obviously) and that part is handled.

What I notice here is the rule is only triggered by the window Item changing. You need to trigger the second rule also by the outside temp. So the second rule would trigger based on the window Item changing and the outside temp changing.

  1. if the timer already exists, the window is OPEN, and the temp is below 12 °C, do nothing
  2. if the timer doesn’t exist, the window is OPEN, and the temp is below 12 °C, create the timer to send the alert notification
  3. if the timer already exists, the window is CLOSED or the temp is above 12 °C, cancel the timer.

That’s all you need.

Splitting the rules was a good hint, I got it working. Thanks for the help Rich!