Why? Why not start from when the Item that triggers the relay to turn on/off receives a command?
Your stated problem is you want to know whether the button press on the screen actually happened or not so when you arrive the door won’t be closed.
Well, the first thing that happens is the Item associated with the opener button receives a command. You can trigger a Rule based on that event.
This is the absolute earliest point in the process and that is what you want.
So trigger a Rule when that Item receives the command to turn on your light, send your alert message or whatever. Immediately after this point the door should be in motion.
Most people use just two reed sensors to detect the position of the door. They use two either on the doorway or on the rod. One sensor at the bottom and one sensor at the top and the magnet on the door or chain. When the bottom one is closed then you know the door is closed. If the bottom one goes to open then you know the door is in motion. When the top one goes to closed you know the door is open. And so on.
So far no timing is required.
The only place where timing is required is if you do not trust that the relay will actually trip after you tell it to. In that case you can set a timer to check after a second. But this is optional and only needed if you don’t trust the relay.
var Timer garageDoorTimer = null
rule "Garage Door Triggered"
when
Item DoorTrigger received command
then
// DoorTrigger is linked to the physical device so we know the relay has triggered at this point
// turn on your alert light
GarageLight.sendCommand(ON)
// send an alert message
sendPushoverMessage(pushoverBuilder("Garage door was triggered!", "GalaxyS7", 1))
// set a timer to make sure the door actually starts to open/close
garageDoorTimer = createTimer(now.plusSeconds(1), [ |
if(GarageDoorSensors.state != OPEN) sendPushoverMessage(pushoverBuilder("Garage door didn't start moving!", "GalaxyS7", 1))
garageDoorTimer = null
])
end
rule "Garage Door Sensors Changed"
when
Member of GarageDoorSensors changed
then
if(triggeringItem.state == NULL) return;
// If there is a Timer then we know the door was just triggered. Since one of the sensors changed state
// we know the door is in motion so cancel the Timer
garageDoorTimer?.cancel
val name = triggeringItem.name
val st = triggeringItem.state
var status = "NA"
switch name {
"GarageDoorBottom": status = if(st == OPEN) "OPENING" else "CLOSED"
"GarageDoorTop": status = if(st == OPEN) "CLOSING" else "OPEN"
}
// door has stopped moving
if(status == "CLOSED" || status == "OPEN") {
GarageLight.sendCommand(OFF)
}
sendPushoverMessage(pushoverBuilder("Garage door status = " + status + "!", "GalaxyS7", 1))
end