Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* This is an updated version that will hopefully help other who just starting out with
* the SmartThings Arduino Shield. The earlier versions of this file had not been
* updated with the newer "definition, capability, attribute, and command" section. Without
* this new section, the Device Type will only partially work (just the on/ff switch).
*
* Author: ogiewon
* Date: 2014-06-20
*
* Credit to urman the original author...
*/
/**
* On/Off Shield (example)
*
* Author: urman
* Date: 2013-03-14
* Capabilities:
* Switch
* Custom Attributes:
* greeting
* Custom Commands
* hello
* goodbye
*/
// for the UI
metadata {
definition (name: "On/Off Shield (example)", author: "urman") {
capability "Switch"
attribute "greeting", "string"
command "hello"
command "goodbye"
}
// 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"])
}
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
}
// handle commands
def on() {
log.debug "Executing 'on'"
zigbee.smartShield(text: "on").format()
}
def off() {
log.debug "Executing 'off'"
zigbee.smartShield(text: "off").format()
}
def hello() {
log.debug "Executing 'hello'"
zigbee.smartShield(text: "hello").format()
}
def goodbye() {
log.debug "Executing 'goodbye'"
zigbee.smartShield(text: "goodbye").format()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment