Hi all, I have a spare zigbee on-off switch lying around, which I thought I’d use for opening my garage door, yet I’m looking to make it behave as a momentary switch, rather than the on-off toggle switch it behaves like per default. The switch runs on the standard “Zigbee Switch” device handler. I’m attempting to mod a copy of that DH to implement a “flick” function, basically doing this:
- turn switch on
- wait a couple of seconds
- turn switch off
Browsing the community I see some folks have worked on this already. Taking a couple of clues, I’ve implemented a push() method to support a momentary close>open of the switch. Not 100% sure if this is the right way to go about it, yet the method seems to trigger just fine, according to the debug log. Here’s what’s weird. The regular zigbee.on() and off() methods work just fine on their own, but when I use them inside my own event-scheduled method, they seem to have no effect?
I would be most grateful if someone would lend a pair of eyeballs to my DH and explain what I’m doing wrong and give me a nudge in the right direction. Thanks a bunch in advance. Code below:
metadata {
definition (name: “ZigBee Switch PLUS”, namespace: “MySpaceHaha”, author: “MeSomeWhat”, ocfDeviceType: “oic.d.switch”, runLocally: false, minHubCoreVersion: ‘000.019.00012’, executeCommandsLocally: true) {
capability “Actuator”
capability “Configuration”
capability “Refresh”
capability “Switch”
capability “Health Check”
capability “Momentary”
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0006", outClusters: "0003, 0006, 0019, 0406", manufacturer: "Leviton", model: "ZSS-10", deviceJoinName: "Leviton Switch"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0006", outClusters: "000A", manufacturer: "HAI", model: "65A21-1", deviceJoinName: "Leviton Wireless Load Control Module-30amp"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006", outClusters: "0003, 0006, 0008, 0019, 0406", manufacturer: "Leviton", model: "DL15A", deviceJoinName: "Leviton Lumina RF Plug-In Appliance Module"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006", outClusters: "0003, 0006, 0008, 0019, 0406", manufacturer: "Leviton", model: "DL15S", deviceJoinName: "Leviton Lumina RF Switch"
fingerprint profileId: "C05E", inClusters: "0000, 0003, 0004, 0005, 0006, 1000, 0B04, FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "Plug 01", deviceJoinName: "OSRAM SMART+ Plug"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0B05, FC01, FC08", outClusters: "0003, 0019", manufacturer: "LEDVANCE", model: "PLUG", deviceJoinName: "SYLVANIA SMART+ Smart Plug"
}
// simulator metadata
simulator {
// status messages
status "on": "on/off: 1"
status "off": "on/off: 0"
// reply messages
reply "zcl on-off on": "on/off: 1"
reply "zcl on-off off": "on/off: 0"
}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
}
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("push", "device.push", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:"Flick", action:"momentary.push", icon:"st.secondary.activity"
}
main "switch"
details(["switch", "refresh","push"])
}
}
// Parse incoming device messages to generate events
def parse(String description) {
log.debug “description is $description”
def event = zigbee.getEvent(description)
if (event) {
sendEvent(event)
}
else {
log.warn “DID NOT PARSE MESSAGE for description : $description”
log.debug zigbee.parseDescriptionAsMap(description)
}
}
def off() {
log.debug “*** OFF!!”
zigbee.off()
}
def on() {
log.debug “*** ON!!”
zigbee.on()
}
// —here are the bit’s I’ve glommed on ---------------------------------------------------------------------
def startTimer(ms) {
log.debug “*** DelayTimer: start”
def now = new Date()
def runTime = new Date(now.getTime() + ms)
runOnce(runTime, offEventHandler)
}
def offEventHandler() {
off()
log.debug “*** DelayTimer: time to turn off”
}
def push() {
on() // turn the thingymagoo on for a bit
log.debug “*** Flick begin”
startTimer(2000) // schedule 2 sec into the future to turn off
}
/**
- PING is used by Device-Watch in attempt to reach the Device
- */
def ping() {
return refresh()
}
def refresh() {
zigbee.onOffRefresh() + zigbee.onOffConfig()
}
def configure() {
// Device-Watch allows 2 check-in misses from device + ping (plus 2 min lag time)
sendEvent(name: “checkInterval”, value: 2 * 10 * 60 + 2 * 60, displayed: false, data: [protocol: “zigbee”, hubHardwareId: device.hub.hardwareID])
log.debug “Configuring Reporting and Bindings.”
zigbee.onOffRefresh() + zigbee.onOffConfig()
}