|
| 1 | +/** |
| 2 | + * Copyright 2018 SmartThings |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at: |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed |
| 10 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License |
| 11 | + * for the specific language governing permissions and limitations under the License. |
| 12 | + * |
| 13 | + */ |
| 14 | +metadata { |
| 15 | + definition(name: "Z-Wave Binary Switch Endpoint", namespace: "smartthings", author: "SmartThings", mnmn: "SmartThings", vid:"generic-switch") { |
| 16 | + capability "Actuator" |
| 17 | + capability "Health Check" |
| 18 | + capability "Refresh" |
| 19 | + capability "Sensor" |
| 20 | + capability "Switch" |
| 21 | + } |
| 22 | + |
| 23 | + simulator { |
| 24 | + } |
| 25 | + |
| 26 | + // tile definitions |
| 27 | + tiles(scale: 2) { |
| 28 | + multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) { |
| 29 | + tileAttribute("device.switch", key: "PRIMARY_CONTROL") { |
| 30 | + attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00A0DC" |
| 31 | + attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff" |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { |
| 36 | + state "default", label: '', action: "refresh.refresh", icon: "st.secondary.refresh" |
| 37 | + } |
| 38 | + |
| 39 | + main "switch" |
| 40 | + details(["switch", "refresh"]) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +def installed() { |
| 45 | + configure() |
| 46 | +} |
| 47 | + |
| 48 | +def updated() { |
| 49 | + configure() |
| 50 | +} |
| 51 | + |
| 52 | +def configure() { |
| 53 | + // Device-Watch simply pings if no device events received for checkInterval duration of 32min |
| 54 | + sendEvent(name: "checkInterval", value: 30 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"]) |
| 55 | + refresh() |
| 56 | +} |
| 57 | + |
| 58 | +def handleZWave(physicalgraph.zwave.commands.basicv1.BasicReport cmd) { |
| 59 | + switchEvents(cmd) |
| 60 | +} |
| 61 | + |
| 62 | +def handleZWave(physicalgraph.zwave.commands.basicv1.BasicSet cmd) { |
| 63 | + switchEvents(cmd) |
| 64 | +} |
| 65 | + |
| 66 | +def handleZWave(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) { |
| 67 | + switchEvents(cmd) |
| 68 | +} |
| 69 | + |
| 70 | +def switchEvents(physicalgraph.zwave.Command cmd) { |
| 71 | + def value = (cmd.value ? "on" : "off") |
| 72 | + sendEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value") |
| 73 | +} |
| 74 | + |
| 75 | +def handleZWave(physicalgraph.zwave.Command cmd) { |
| 76 | + sendEvent(descriptionText: "$device.displayName: $cmd", isStateChange: true, displayed: false) |
| 77 | +} |
| 78 | + |
| 79 | +def on() { |
| 80 | + // We do not use delayBetween, as delay required may be different for each parent device |
| 81 | + parent.sendCommand(device, [zwave.switchBinaryV1.switchBinarySet(switchValue: 0xFF), |
| 82 | + zwave.switchBinaryV1.switchBinaryGet()]) |
| 83 | +} |
| 84 | + |
| 85 | +def off() { |
| 86 | + // We do not use delayBetween, as delay required may be different for each parent device |
| 87 | + parent.sendCommand(device, [zwave.switchBinaryV1.switchBinarySet(switchValue: 0x00), |
| 88 | + zwave.switchBinaryV1.switchBinaryGet()]) |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * PING is used by Device-Watch in attempt to reach the Device |
| 93 | + * */ |
| 94 | +def ping() { |
| 95 | + refresh() |
| 96 | +} |
| 97 | + |
| 98 | +def refresh() { |
| 99 | + parent.sendCommand(device, zwave.switchBinaryV1.switchBinaryGet()) |
| 100 | +} |
0 commit comments