In my application, I am interfacing between the relatively fast world of Smartthings and the relatively slow world of X10. (It’s one of the challenges of investing in home automation long ago)
So I have set up a smart app to control multiple devices using:
section {
input "theSwitch", "capability.switch", title: "Which is the master switch"
input "theSwitches", "capability.switch", title: "Which switches will you control?", multiple: true, required: false
}
The first line sets up the master control, the second one lists the potentially many switches to be controlled in response to the master. So far so good.
If I just let it fly, Smartthings will iterate through all of the switches listed when the SmartApp is installed. But this goes too fast for X10 to keep up. Is there a way to add a delay between each firing of the Smartthings as it iterates over the list of controlled devices?"
I tried something like this in the event handler, but ummm… didn’t work.
def on() {
sendEvent(name: "switch", value: "on", isStateChange: "true", delay: 250)
}
But of course, that is not guaranteed to work since SmartThings is asynchronous.
I think I have to somehow override the multiple device command and send the commands to each selected theSwitches
individually with a long enough delay to ensure some separation in time.
So, I tried catching each instance of the to-be-controlled switches and set up a runIn()
method to trigger each of them to run 1 second apart.
def switchOffHandler(evt) {
def int delayIncrement = 1
def int currentDelay = 1
log.debug "MULTISWITCH: off"
def individualSwitch
theSwitches.each { eswitch ->
individualSwitch = eswitch
log.debug "switchname: ${individualSwitch.displayName}"
runIn(currentDelay,makeItGoOffLater, [data: [theSwitch: individualSwitch]])
currentDelay += delayIncrement
}
}
and the makeItGoOffLater method looks like this:
def makeItGoOnLater(theSwitch) {
sendEvent(name: theSwitch, value: "on", isStateChange: "true")
log.debug "Sent event with ${theSwitch}"
}
I get some sense that it is properly stepping through the various switches in the .each
loop above… but the events never trigger.
Paul