Permalink
Switch branches/tags
PROD_2018.10.09 PROD_2018.10.02 PROD_2018.09.25 PROD_2018.09.18 PROD_2018.09.11 PROD_2018.09.05 PROD_2018.08.28 PROD_2018.08.21 PROD_2018.08.14 PROD_2018.08.07 PROD_2018.07.31 PROD_2018.07.24 PROD_2018.07.17 PROD_2018.07.10 PROD_2018.07.03 PROD_2018.06.26 PROD_2018.06.19 PROD_2018.06.12 PROD_2018.06.06 PROD_2018.05.31 PROD_2018.05.22 PROD_2018.05.15 PROD_2018.05.08 PROD_2018.05.01 PROD_2018.04.24 PROD_2018.04.17 PROD_2018.04.10 PROD_2018.04.03 PROD_2018.03.27 PROD_2018.03.20 PROD_2018.03.13 PROD_2018.03.06 PROD_2018.02.27 PROD_2018.02.20 PROD_2018.02.13 PROD_2018.02.06 PROD_2018.01.30 PROD_2018.01.23 PROD_2018.01.17 PROD_2017.12.12 PROD_2017.12.05 PROD_2017.11.14 PROD_2017.11.07 PROD_2017.10.31 PROD_2017.10.25 PROD_2017.10.19 PROD_2017.10.10 PROD_2017.10.03 PROD_2017.09.26 PROD_2017.09.19 PROD_2017.09.12 PROD_2017.09.05 PROD_2017.08.29 PROD_2017.08.22 PROD_2017.08.15 PROD_2017.08.08 PROD_2017.08.01 PROD_2017.07.25 PROD_2017.07.18 PROD_2017.07.11 PROD_2017.07.05 PROD_2017.06.27 PROD_2017.06.20 PROD_2017.06.13 PROD_2017.06.06 PROD_2017.05.31 PROD_2017.05.23 PROD_2017.05.16 PROD_2017.05.09 PROD_2017.05.02 PROD_2017.04.25 PROD_2017.04.18 PROD_2017.04.11 PROD_2017.04.04 PROD_2017.03.28 PROD_2017.03.21 PROD_2017.03.14 PROD_2017.03.07 PROD_2017.03.01 PROD_2017.02.22 PROD_2017.02.14 PROD_2017.02.07 PROD_2017.01.31 PROD_2017.01.24 PROD_2017.01.18 PROD_2017.01.10 PROD_2016.12.07 PROD_2016.11.22 PROD_2016.11.15 PROD_2016.11.08 PROD_2016.11.01 PROD_2016.10.25 PROD_2016.10.18 PROD_2016.10.11 PROD_2016.10.04 PROD_2016.09.27 PROD_2016.09.20 PROD_2016.09.13 PROD_2016.09.06 PROD_2016.08.30
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
216 lines (187 sloc) 7.58 KB
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
metadata {
definition (name: "Z-Wave Switch", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.switch", runLocally: true, minHubCoreVersion: '000.017.0012', executeCommandsLocally: false) {
capability "Actuator"
capability "Indicator"
capability "Switch"
capability "Refresh"
capability "Sensor"
capability "Health Check"
capability "Light"
fingerprint mfr:"0063", prod:"4952", deviceJoinName: "GE Wall Switch"
fingerprint mfr:"0063", prod:"5257", deviceJoinName: "GE Wall Switch"
fingerprint mfr:"0063", prod:"5052", deviceJoinName: "GE Plug-In Switch"
fingerprint mfr:"0113", prod:"5257", deviceJoinName: "Z-Wave Wall Switch"
}
// 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"
}
preferences {
input "ledIndicator", "enum", title: "LED Indicator", description: "Turn LED indicator... ", required: false, options:["on": "When On", "off": "When Off", "never": "Never"], defaultValue: "off"
}
// tile definitions
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00A0DC"
attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
}
standardTile("indicator", "device.indicatorStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "switch"
details(["switch","refresh"])
}
}
def installed() {
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
}
def updated(){
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
switch (ledIndicator) {
case "on":
indicatorWhenOn()
break
case "off":
indicatorWhenOff()
break
case "never":
indicatorNever()
break
default:
indicatorWhenOn()
break
}
response(refresh())
}
def getCommandClassVersions() {
[
0x20: 1, // Basic
0x56: 1, // Crc16Encap
0x70: 1, // Configuration
]
}
def parse(String description) {
def result = null
def cmd = zwave.parse(description, commandClassVersions)
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
result = [result, response(zwave.basicV1.basicGet())]
log.debug "Was hailed: requesting state update"
} else {
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.basicv1.BasicSet 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.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, displayed: false]
}
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
[name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false]
}
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
log.debug "manufacturerId: ${cmd.manufacturerId}"
log.debug "manufacturerName: ${cmd.manufacturerName}"
log.debug "productId: ${cmd.productId}"
log.debug "productTypeId: ${cmd.productTypeId}"
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
updateDataValue("MSR", msr)
updateDataValue("manufacturer", cmd.manufacturerName)
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
}
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
def versions = commandClassVersions
def version = versions[cmd.commandClass as Integer]
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren't interested in
[:]
}
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()
])
}
/**
* PING is used by Device-Watch in attempt to reach the Device
**/
def ping() {
zwave.switchBinaryV1.switchBinaryGet().format()
}
def refresh() {
delayBetween([
zwave.switchBinaryV1.switchBinaryGet().format(),
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
])
}
void indicatorWhenOn() {
sendEvent(name: "indicatorStatus", value: "when on", displayed: false)
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
}
void indicatorWhenOff() {
sendEvent(name: "indicatorStatus", value: "when off", displayed: false)
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
}
void indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", displayed: false)
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
}
def invertSwitch(invert=true) {
if (invert) {
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
}
else {
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
}
}