Last active
May 27, 2018 07:13
-
-
Save aurman/6862503 to your computer and use it in GitHub Desktop.
Device Handler Code for On/Off Shield (example)
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
/* | |
* On/Off Shield (example) | |
* | |
* Author: urman | |
* Date: 2013-03-14 | |
* Revision: 2014-07-10 | |
* Capabilities: | |
* Switch | |
* Custom Attributes: | |
* greeting | |
* Custom Commands | |
* hello | |
* goodbye | |
*/ | |
metadata { | |
definition (name: "On/Off Shield (example)", author: "urman") { | |
capability "Switch" | |
command "hello" | |
command "goodbye" | |
attribute "greeting","string" | |
} | |
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"]) | |
} | |
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" | |
// 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" | |
} | |
} | |
Map parse(String description) { | |
def value = zigbee.parse(description)?.text | |
def linkText = getLinkText(device) | |
def descriptionText = getDescriptionText(description, linkText, value) | |
def handlerName = value | |
def isStateChange = value != "ping" | |
def displayed = value && isStateChange | |
def result = [ | |
value: value, | |
name: value in ["on","off"] ? "switch" : (value && value != "ping" ? "greeting" : null), | |
handlerName: handlerName, | |
linkText: linkText, | |
descriptionText: descriptionText, | |
isStateChange: isStateChange, | |
displayed: displayed | |
] | |
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() | |
} | |
def goodbye() { | |
log.debug "Bye Bye!" | |
zigbee.smartShield(text: "goodbye").format() | |
} | |
def parse(String description) { | |
log.debug "Parsing '${description}'" | |
// TODO: handle 'switch' attribute | |
// TODO: handle 'greeting' attribute | |
} |
This code do not show text coming from Arduino. However, there is a built in device type with this name which show that on the time. Don't know how to get that done. Ex. "buttonhello" example has a line item "smartthing.send("fancy");" with which can show "fancy" in a time. Don't know how to get that.
To fix change line 33 from
valueTile("message", "device.greeting", inactiveLabel: false) {
to
valueTile("message", "device.message", inactiveLabel: false) {
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just got everything setup and the on/off button is not working. The hello button works fine. Using a new hub, a new Arduino Shield, the latest lib, and the on/off example from the web site, unmodified.