Hi,
I’m trying to set up a system in my company’s office where a Flic button affixed to the wall on the inside will allow people to lock the door easily as they leave. In order to give them a fighting chance at leaving the office, I want to add a five-second delay to the locking action during rule execution, but no matter what I try, I don’t seem to be able to get said delay into place.
Following the Design Pattern: Motion Sensor Timer example, I now have something like this as my script:
// ECMAScript type
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Motion Timer");
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
var now = ZonedDateTime.now();
var runme = function(){
// code that executes later goes here
events.sendCommand('main_door_DoorLock', 'ON')
this.timer = undefined; // reset the timer back to undefined
}
if(this.timer === undefined) {
this.timer = ScriptExecution.createTimer(now.plusSeconds(5), runme);
}
else {
this.timer.reschedule(now.plusSeconds(5));
}
and the Rule Designer has two actions:
- Play Sound: a warning klaxon sound from an MP3 on the file system, 4s long
- Run Script: the above script verbatim.
However, any time I hit the Flic Button, the sound plays (as it should) and the lock activates immediately, while the sound is playing (as it should not).
I also tried using the Rules DSL as my script type, having this as the script:
createTimer(now.plusSeconds(5), [ |
events.sendCommand('main_door_DoorLock', 'ON')
])
but either this didn’t run at all or it ran in parallel with the sound again.
Does anyone have any ideas as to what I’m doing wrong?