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?
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 open() {
if (device.currentValue("doorstate") == "Door is closed, open/on to open") {
log.debug "Sending open event to open door"
opening()
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())
}
}
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 ?
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?
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.