I am trying to create a custom device handler for a switch such that when i press a tile it toggles the switch off, pauses 1 second, then back on again. I am new to ST programming and cannot even get the switch/light to turn off correctly. When i try the code below it says the switch is off after running it but the light on my switch is still on. what am i doing wrong? (I am using a modified z wave switch device handler)
def toggle() {
def swStat = device.currentValue(“switch”)
log.debug “Toggle Color switch status: ${swStat}”
def dStart = new Date().getTime()
if (swStat == “on”) {
log.debug(“turn off”)
sendEvent(name: "switch", value: "off")
off()
//sleepForDuration(100)
// log.debug("turn toggle on")
//sendEvent(name: "switch", value: "on")
//on()
}
}
def sleepForDuration(duration, callback = {})
{
def dTotalSleep = 0
def dStart = new Date().getTime()
def cmds =
cmds << “delay 1000”
cmds << refresh()
while (dTotalSleep <= duration)
{
//cmds
dTotalSleep = (new Date().getTime() - dStart)
}
log.debug "Slept ${dTotalSleep}ms"
callback(dTotalSleep)
}