Delay between send events in DH?

trying to add a door state in a device handler that takes into consideration the time to fully open or close a garage door.
I can do it when combined with RM but that is not really the correct way of doing it.
It should be done in the device handler.

basically the DH code is like this:

attribute "doorstate", "string"

def open() {
if (device.currentValue("doorstate") == "Door is closed, open/on to open") {
log.debug "Sending open event to open door"
// delayBetween([
sendEvent(name: "doorstate", value: "opening")
// delay (20000 )
sendEvent(name: "doorstate", value: "opened")
// ], 20000)
}
}

As you can see I have tried delayBetween, delay(), and I have also tried sleep()
the second sendEvent does not happen.
Why is there not a delay between setting doorstate from opening then 20 seconds later change to opened?

Maybe do a runIn and schedule it to run a separate routine to send the event later?

runIn( time , method , [data: dataPoint ])

thanks but no go
I am sure it is a typo but I am not seeing it.
I will change the delay to a settable value later but first need to get this delay function working.

def opening() {
sendEvent(name: "doorstate", value: "opening")
}

def opened() {
runIn(5000, sendEvent(name: "doorstate", value: "opened"))
}

def open() {
if (device.currentValue("doorstate") == "Door is closed, open/on to open") {
log.debug "Sending open event to open door"
opening()
opened()
}
}

Try this:

def opening() {
sendEvent(name: "doorstate", value: "opening")
}

def opened() {
sendEvent(name: "doorstate", value: "opened")
}

def open() {
if (device.currentValue("doorstate") == "Door is closed, open/on to open") {
log.debug "Sending open event to open door"
opening()
runIn(5000, opened())
}
}

nope
I get

errorjava.lang.IllegalArgumentException: Name cannot be null. on line 174 (open)

line 174 is
runIn(5000, opened())

Runin is in seconds, and the method name does not include the closure

1 Like

I was going from memory. I should have looked. lol

1 Like

thank you both
that did it!

I was thinking runinmillis for the timer, and forgot no closure on the method. Eh, what can I say? I'm not a professional developer. lol

Glad you got it working!

@mike.maxwell or @JasonJoel
out of curiosity why didn't the delay command work?
Is it simply not used with sendEvents?

Delay and or delay between is for zigbee and zwave commands, not sendEvents

1 Like

I just had to use the runin command to solve an issue, but not sure if it that was the right way.
Hoping for some guidance. I'm fairly new to HE development - and the most useful docs seem to be SmartThings docs.

In a custom driver, I'm using SendEvents to change the state of an attribute.
But I cannot inspect the state of that attribute straight afterwards in order to change the state of another attribute. I assume that sendEvents is asynchronous, so the state change is not immediate. Hence I effectively have to introduce a 5 second delay before checking the state.
That seemed to work, but it seems a bit of a strange solution.

If one attribute is dependent on the state of several other attributes, whats the correct way to implement the dependency ?

Thanks

Yes, there is going to be some lag here.

Howerer, having written hundreds of drivers at this point this isn't anything I couldn't resolve using state or re architecting the driver methods involved.

Why would you have to? The method you used to change that attribute knows exactly what the value it sent it is. You shouldn't need to check the current value right after setting it. Just extend the method when you set the attribute to set the second as well.

Yes, thanks, I may need to rearchitect this a bit. I'm adapting an existing app & driver rather than starting from scratch. So not my design.

I'm in a method which updates about 10 separate attributes and then wants to invoke a method which sets a special attribute that consolidates all the others (into an html string). I guess I could just pass lots of parameters rather than trying to use attributes (due to the lag).

You've confirmed my suspicion at least.
Out of interest, does state have the same lag as attributes?

Thanks

State is read on driver load and written on close, it takes about 50ms for a write.

If all these attributes are sent in via one parse, then you shouldn't need state, just refactor all the sendEvents so they are all within the same method.

1 Like

I have a doubt in the development of a driver, I need a 2-second interval between each event, I did it this way but I don't know if this is correct

def on() {
sendTasmota('IRsend '+ONIR)
sendEvent(name: "switch", value: "on")
runIn(2,cena2)
runIn(4,cena3)
runIn(6,cena4)
runIn(8,cena5)
runIn(10,cena6)
runIn(12,autoturnoff)
}

def cena2() {
sendTasmota('IRsend '+ONIR2)
}

def cena3() {
sendTasmota('IRsend '+ONIR3)
}

def cena4() {
sendTasmota('IRsend '+ONIR4)
}

def cena5() {
sendTasmota('IRsend '+ONIR5)
}

def cena6() {
sendTasmota('IRsend '+ONIR6)
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.