Yeah, my groovy is not so groovy.
What’s the best way to delay a call to event?
In my case: if a door is open, let’s wait 1 minute to see if it get closed - if not, send message or blah, blah, blah
I’m trying to decipher “Left It Open” but there’s too much there I don’t need.
I want to capture time of “contact.open” evt by declaring a variable def nowTime = now()
Then declare another variable to add 60 seconds to nowTime?
def delayTime = now() + 3000*20
And finally call second event openTooLong after one minute…
The following code works but it doesn’t wait for the delay to call openTooLong…
preferences {
section("Select a sensor...") {
input "allyDoor", "capability.contactSensor", title: "Available Sensors...", multiple: false
}
section("Select a switch") {
input "allySwitch", "capability.switch", title: "Available Switches...", multiple: false
}
}
def installed() {
subscribe (allyDoor, "contact.open", doorHandler)
}
def updated() {
unsubscribe()
subscribe (allyDoor, "contact.open", doorHandler)
}
def doorHandler(evt) {
log.trace "doorHandler($evt.name: $evt.value)"
def timeNow = now()
log.trace "current time is ${timeNow}"
def delay = 5000
runIn(timeNow + delay, openTooLong)
}
def openTooLong() {
log.trace "running part 2"
}