Skip to content

Instantly share code, notes, and snippets.

@bflorian
Created May 7, 2013 14:05
Show Gist options
  • Save bflorian/5532811 to your computer and use it in GitHub Desktop.
Save bflorian/5532811 to your computer and use it in GitHub Desktop.
/**
* Button Shield
*
* Author: bob
* Date: 2013-02-08
*/
metadata {
// simulator
simulator {
status "on": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
status "buttonpush": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A627574746f6e70757368"
status "ping": "catchall: 0104 0000 01 01 0140 00 88E3 00 00 0000 0A 00 0A70696E67"
// reply messages
reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
}
// tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
standardTile("greeting", "device.greeting", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state "default", label: 'hello', action: "hello", icon: "st.switches.switch.off", backgroundColor: "#ccccff"
}
valueTile("message", "device.greeting", inactiveLabel: false) {
state "greeting", label:'${currentValue}', unit:""
}
main "switch"
details(["switch","greeting","message"])
}
}
Map parse(String description) {
def value = zigbee.parse(description)?.text
def linkText = getLinkText(device)
def isStateChange = value != "ping"
def displayed = value && isStateChange
def result = [
value: value,
name: value in ["on","off"] ? "switch" : (value == "buttonpush" ? "button" : "greeting"),
handlerName: value in ["on","off"] ? value : null,
linkText: linkText,
isStateChange: isStateChange,
displayed: displayed
]
if (result.name == "button") {
result.descriptionText = "$linkText button was pushed"
}
else if (result.name == "switch") {
result.descriptionText = "$linkText light was ${result.value}"
}
else {
result.descriptionText = "$linkText received command '${result.value}'"
}
log.debug result.descriptionText
result
}
def on() {
zigbee.smartShield(text: "on").format()
}
def off() {
zigbee.smartShield(text: "off").format()
}
def hello() {
log.debug "Hello World!"
zigbee.smartShield(text: "hello").format()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment