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:
triggers:
- id: "1"
configuration:
itemName: Door_Sensor_Sliding_Door
type: core.ItemStateChangeTrigger
- id: "3"
configuration:
itemName: Door_Sensor_Sliding_Door
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
var logger =
Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Door
Open - HVAC Off");
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
logger.info("D Open - HVAC Off Rule Started");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
var now = ZonedDateTime.now();
var runme = function() {
logger.info("Ecobee Mode Off");
events.sendCommand("Ecobee_Mode", "off");
this.timer = undefined; // reset the timer back to undefined
}
logger.info("this.timer = " + this.timer);
if (items.Door_Sensor_Sliding_Door == ON) {
if(this.timer === undefined) {
this.timer = ScriptExecution.createTimer(now.plusSeconds(300), runme);
}
logger.info("Door_Sensor_Sliding_Door is ON");
}
else if (items.Door_Sensor_Sliding_Door == OFF) {
if(this.timer !== undefined) {
this.timer.cancel();
}
logger.info("Door_Sensor_Sliding_Door is OFF");
}
logger.info("this.timer = " + this.timer)
type: script.ScriptAction