Skip to content

Instantly share code, notes, and snippets.

@bflorian
Last active November 17, 2016 14:15
Show Gist options
  • Save bflorian/5690633 to your computer and use it in GitHub Desktop.
Save bflorian/5690633 to your computer and use it in GitHub Desktop.
metadata {
// simulator metadata
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
// reply messages
reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
reply "200100,delay 100,2502": "command: 2503, payload: 00"
}
// tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: 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("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh", icon:"st.secondary.refresh"
}
standardTile("indicator", "device.indicatorStatus", inactiveLabel: false, decoration: "flat") {
state "when off", label:'lit when off', action:"indicatorWhenOn"
state "when on", label:'lit when on', action:"indicatorNever"
state "never", label:'never lit', action:"indicatorWhenOff"
}
main "switch"
details(["switch","refresh","indicator"])
}
}
def parse(String description) {
log.debug description
def result = null
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
log.debug "Parse returned ${result?.descriptionText}"
return result
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
[name: "switch", value: cmd.value ? "on" : "off", type: "physical"]
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
[name: "switch", value: cmd.value ? "on" : "off", type: "digital"]
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren't interested in
[:]
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
def value = "when off"
if (cmd.configurationValue[0] == 1) {value = "when on"}
if (cmd.configurationValue[0] == 2) {value = "never"}
[name: "indicatorStatus", value: value, display: false]
}
def on() {
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
])
}
def off() {
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
])
}
def poll() {
zwave.switchBinaryV1.switchBinaryGet().format()
}
def refresh() {
zwave.switchBinaryV1.switchBinaryGet().format()
}
def indicatorWhenOn() {
[
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format(),
zwave.configurationV1.configurationGet(parameterNumber: 3).format()
]
}
def indicatorWhenOff() {
[
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format(),
zwave.configurationV1.configurationGet(parameterNumber: 3).format()
]
}
def indicatorNever() {
[
zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format(),
zwave.configurationV1.configurationGet(parameterNumber: 3).format()
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment