Last active
December 28, 2015 21:39
-
-
Save rappleg/7566571 to your computer and use it in GitHub Desktop.
CentraLite Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
metadata { | |
// 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" | |
} | |
// UI tile definitions | |
tiles { | |
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) { | |
state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff" | |
state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821" | |
} | |
valueTile("power", "device.power", decoration: "flat") { | |
state "power", label:'${currentValue} W' | |
} | |
standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat") { | |
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh" | |
} | |
main "switch" | |
details(["switch","power","refresh"]) | |
} | |
} | |
// Parse incoming device messages to generate events | |
def parse(String description) { | |
log.debug "Parse description $description" | |
def name = null | |
def value = null | |
if (description?.startsWith("read attr -")) { | |
log.debug "Read attr" | |
def reportValue = description.split(",").find {it.split(":")[0].trim() == "value"}?.split(":")[1].trim() | |
name = "power" | |
// assume 16 bit signed for encoding and power divisor is 10 | |
value = Integer.parseInt(reportValue, 16) / 10 | |
} else if (description?.startsWith("on/off:")) { | |
log.debug "Switch command" | |
name = "switch" | |
value = description?.endsWith(" 1") ? "on" : "off" | |
} | |
def result = createEvent(name: name, value: value) | |
log.debug "Parse returned ${result?.descriptionText}" | |
return result | |
} | |
// Commands to device | |
def on() { | |
'zcl on-off on' | |
} | |
def off() { | |
'zcl on-off off' | |
} | |
def meter() { | |
"st rattr 0x${device.deviceNetworkId} 1 0xB04 0x50B" | |
} | |
def refresh() { | |
"st rattr 0x${device.deviceNetworkId} 1 0xB04 0x50B" | |
} | |
def configure() { | |
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment