Blockly Timer Not Canceling On Retrigger

I am trying to make a rule to turn off teh HVAC if teh door is left openfor more than x amount of time. That works OK but if teh door is opened and then closed while the timer is running the timer is not canceled. I’ve tried some different variations with no luck. Here is how I have the rule set up:

When - The door sensor changes from any to any

Then - Blockly script (check for door sensor = OPEN, start timer, turn off HVAC when timed out, cancel if retriggered)

Blockly script:

Hmm, won’t let me upload image…

Rule code:

configuration: {}
triggers:
  - id: "2"
    configuration:
      itemName: Door_Sensor_Front_Door
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="controls_if" id="-d?#@^Qt}psU~AK[!|`Z" x="38" y="12"><value
        name="IF0"><block type="logic_compare" id="u2Y,p-Bk~xFrajRua(?l"><field
        name="OP">EQ</field><value name="A"><block type="oh_getitem_state"
        id="]uR.x^^8g{r|aoBj(U*4"><value name="itemName"><shadow type="oh_item"
        id=",G(wRIfF!)0mRgMUoPTW"><field
        name="itemName">Door_Sensor_Front_Door</field></shadow></value></block></value><value
        name="B"><block type="text" id="L-)awhPsS3tdLCa3RnpQ"><field
        name="TEXT">OPEN</field></block></value></block></value><statement
        name="DO0"><block type="oh_log" id="EvS:Dw2V9-V5d*@8)Evq"><field
        name="severity">info</field><value name="message"><shadow type="text"
        id="V,A;6--|N.+5P.ZeWh0;"><field name="TEXT">Door Open HVAC Off Rule
        Started</field></shadow></value><next><block type="oh_log"
        id="%$YI!NUC49z3ke)w0k1,"><field name="severity">info</field><value
        name="message"><shadow type="text" id="G^3AUxe9wc$hOyunX}/%"><field
        name="TEXT">Door Open Timer Started</field></shadow></value><next><block
        type="oh_timer_ext" id="s.lI~FEDhX|*^T*?vmkq"><field
        name="delayUnits">plusMinutes</field><field
        name="retrigger">cancel</field><value name="delay"><shadow
        type="math_number" id="?23;@*F}5G#8*s0E.eGK"><field
        name="NUM">1</field></shadow></value><value name="timerName"><shadow
        type="text" id=",uW.!XZI]EfKs[zq(QQp"><field name="TEXT">Door Open
        Timer</field></shadow></value><statement name="timerCode"><block
        type="oh_event" id="HA_,?eO9BM(7=r=CH-q."><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="JTAj2L3s.aro.6%E{pi5"><field
        name="TEXT">off</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="f5A~-tiWVpR8p!golz[X"><field
        name="itemName">Ecobee_Mode</field></shadow></value><next><block
        type="oh_event" id="qY3!p|2H_|7_GqJCai:G"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="BoFh0~Au$JwDQj}u3Eld"><field
        name="TEXT">OFF</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="_3cnMR%nx4*{[t[B,d!E"><field
        name="itemName">Dehu_Wall_Switch</field></shadow></value><next><block
        type="oh_log" id="S$L71uS0Y^vJ+*,Y^8_{"><field
        name="severity">info</field><value name="message"><shadow type="text"
        id="(l-pDZNVlF,lu1/F/yzr"><field name="TEXT">Ecobee &amp; Dehu Wall
        Switch Turned
        Off</field></shadow></value></block></next></block></next></block></statement></block></next></block></next></block></statement></block></xml>
      type: application/javascript
      script: >
        var logger =
        Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' +
        ctx.ruleUID);


        var scriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');


        var zdt = Java.type('java.time.ZonedDateTime');


        if (typeof this.timers === 'undefined') {
          this.timers = [];
        }



        if (itemRegistry.getItem('Door_Sensor_Front_Door').getState() == 'OPEN') {
          logger.info('Door Open HVAC Off Rule Started');
          logger.info('Door Open Timer Started');
          if (typeof this.timers['Door Open Timer'] === 'undefined' || this.timers['Door Open Timer'].hasTerminated()) {
            this.timers['Door Open Timer'] = scriptExecution.createTimer(zdt.now().plusMinutes(1), function () {
              events.sendCommand('Ecobee_Mode', 'off');
              events.sendCommand('Dehu_Wall_Switch', 'OFF');
              logger.info('Ecobee & Dehu Wall Switch Turned Off');
              })
          } else {
            this.timers['Door Open Timer'].cancel();
            this.timers['Door Open Timer'] = undefined;
          }
        }
    type: script.ScriptAction

The code looks correct. Please post the logs.

Log:

2022-01-12 16:47:50.381 [INFO ] [org.openhab.rule.Door_Open_HVAC_Off ] - Door Open HVAC Off Rule Started
2022-01-12 16:47:50.384 [INFO ] [org.openhab.rule.Door_Open_HVAC_Off ] - Door Open Timer Started
==> /var/log/openhab/events.log <==
2022-01-12 16:47:53.351 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Door_Sensor_Front_Door' changed from OPEN to CLOSED
2022-01-12 16:47:53.353 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Ecobee_Mode' received command auto
2022-01-12 16:47:53.367 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Dehu_Wall_Switch' received command ON
2022-01-12 16:47:53.370 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Ecobee_Mode' predicted to become auto
2022-01-12 16:47:53.373 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Dehu_Wall_Switch' predicted to become ON
2022-01-12 16:48:01.476 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temp_Second_Floor' changed from 76.9 °F to 76.28 °F
2022-01-12 16:48:02.129 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RH_First_Floor_Attic' changed from 38 to 39
2022-01-12 16:48:28.135 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Motion_Hall' changed from ON to OFF
==> /var/log/openhab/openhab.log <==
2022-01-12 16:48:32.563 [INFO ] [rg.openhab.rule.Alert_Ecobee_Offline] - Ecobee Offline Alert Rule Started
==> /var/log/openhab/events.log <==
2022-01-12 16:48:32.562 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temp_First_Floor' changed from 68.6 °F to 68.5 °F
==> /var/log/openhab/openhab.log <==
2022-01-12 16:48:50.416 [INFO ] [org.openhab.rule.Door_Open_HVAC_Off ] - Ecobee & Dehu Wall Switch Turned Off
==> /var/log/openhab/events.log <==
2022-01-12 16:48:50.412 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Ecobee_Mode' received command off
2022-01-12 16:48:50.414 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Dehu_Wall_Switch' received command OFF
2022-01-12 16:48:50.416 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Ecobee_Mode' predicted to become off
2022-01-12 16:48:50.419 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Dehu_Wall_Switch' predicted to become OFF
2022-01-12 16:48:50.423 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Ecobee_Mode' changed from auto to off
2022-01-12 16:48:50.426 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Dehu_Wall_Switch' changed from ON to OFF
2022-01-12 16:48:50.428 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Dehumidifier_Switch_First_Floor' received command OFF
2022-01-12 16:48:50.434 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Ecobee_Fan_Runtime' received command 0
2022-01-12 16:48:50.440 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Fresh_Air_Switch_First_Floor' received command OFF
2022-01-12 16:48:50.442 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Dehumidifier_Switch_First_Floor' predicted to become OFF
2022-01-12 16:48:50.450 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Ecobee_Fan_Runtime' predicted to become 0
2022-01-12 16:48:50.457 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Fresh_Air_Switch_First_Floor' predicted to become OFF
2022-01-12 16:48:50.463 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Fresh_Air_Switch_First_Floor' changed from ON to OFF
2022-01-12 16:49:22.713 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temp_Second_Floor' changed from 76.28 °F to 76.1 °F

OK, looking more closely at the code now and at the events I see the problem.

if (itemRegistry.getItem('Door_Sensor_Front_Door').getState() == 'OPEN') {

The rule only does something when the door is OPEN. There is nothing to cancel the Timer when the door closes. You need to add an else to that first if to cancel it when Door_Sensor_Front_Door is CLOSED.