Problem getting Item State

Go back a step. If you want your rule to do anything when the light turns off, then you would need the rule to run I.e. trigger when the light turns off.

It’s not about language, it is about logic. The machine is a dimwit, it’s up to you to instruct it precisely.

Ahhh! I thought that part of the script was dependent on it initializing above. Didn’t realize these two functions were independent. That makes sense now and it’s working properly.

Thanks so much for your help!

For anyone trying to do this, here is the final rule code:

  - id: "1"
      itemName: Door_Sensor_Sliding_Door
    type: core.ItemStateChangeTrigger
  - id: "3"
      itemName: Door_Sensor_Sliding_Door
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      type: application/javascript
      script: >-
        var logger =
        Open - HVAC Off");

        var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");"D Open - HVAC Off Rule Started");

        var ZonedDateTime = Java.type("java.time.ZonedDateTime"); 

        var now =;

        var runme = function() {
  "Ecobee Mode Off");
          events.sendCommand("Ecobee_Mode", "off");
            this.timer = undefined; // reset the timer back to undefined
        }"this.timer = " + this.timer);

        if (items.Door_Sensor_Sliding_Door == ON) {
             if(this.timer === undefined) {
                this.timer = ScriptExecution.createTimer(now.plusSeconds(300), runme);
            }"Door_Sensor_Sliding_Door is ON");

        else if (items.Door_Sensor_Sliding_Door == OFF) {
             if(this.timer !== undefined) {
            }"Door_Sensor_Sliding_Door is OFF");
        }"this.timer = " + this.timer)
    type: script.ScriptAction
1 Like