Advertisement
Guest User

ZWave Garage Switch

a guest
Dec 27th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. /**
  2. * Copyright 2015 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: "My Z-Wave Garage Switch", namespace: "smartthings", author: "Cameron") {
  16. capability "Actuator"
  17. capability "Indicator"
  18. capability "Switch"
  19. capability "Polling"
  20. capability "Refresh"
  21. capability "Sensor"
  22.  
  23. fingerprint inClusters: "0x25"
  24. }
  25.  
  26. // simulator metadata
  27. simulator {
  28. status "on": "command: 2003, payload: FF"
  29. status "off": "command: 2003, payload: 00"
  30.  
  31. // reply messages
  32. reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
  33. reply "200100,delay 100,2502": "command: 2503, payload: 00"
  34. }
  35.  
  36. // tile definitions
  37. tiles(scale: 2) {
  38. multiAttributeTile(name:"switch", width: 6, height: 4){
  39. tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
  40. attributeState "on", label: 'open', action: "switch.off", icon: "st.doors.garage.garage-open", backgroundColor: "#79b821"
  41. attributeState "off", label: 'closed', action: "switch.on", icon: "st.doors.garage.garage-closed", backgroundColor: "#ffffff"
  42. }
  43. }
  44.  
  45. standardTile("openIt", "device.switch", width:2, height:2, inactiveLabel: false, decoration: "flat") {
  46. state "default", label:'open', action:"switch.on", icon:"st.doors.garage.garage-opening"
  47. }
  48.  
  49. standardTile("closeIt", "device.switch", width:2, height:2, inactiveLabel: false, decoration: "flat") {
  50. state "default", label:'close', action:"switch.off", icon:"st.doors.garage.garage-closing"
  51. }
  52.  
  53. standardTile("indicator", "device.indicatorStatus", width:2, height:2, inactiveLabel: false, decoration: "flat") {
  54. state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
  55. state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
  56. state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
  57. }
  58. standardTile("refresh", "device.switch", width:2, height:2, inactiveLabel: false, decoration: "flat") {
  59. state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
  60. }
  61.  
  62. main "switch"
  63. details(["switch","openIt","closeIt","refresh","indicator"])
  64. }
  65. }
  66.  
  67. def parse(String description) {
  68. def result = null
  69. def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
  70. if (cmd) {
  71. result = createEvent(zwaveEvent(cmd))
  72. }
  73. if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
  74. result = [result, response(zwave.basicV1.basicGet())]
  75. log.debug "Was hailed: requesting state update"
  76. } else {
  77. log.debug "Parse returned ${result?.descriptionText}"
  78. }
  79. return result
  80. }
  81.  
  82. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
  83. [name: "switch", value: cmd.value ? "on" : "off", type: "physical"]
  84. }
  85.  
  86. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
  87. [name: "switch", value: cmd.value ? "on" : "off", type: "physical"]
  88. }
  89.  
  90. def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  91. [name: "switch", value: cmd.value ? "on" : "off", type: "digital"]
  92. }
  93.  
  94. def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
  95. def value = "when off"
  96. if (cmd.configurationValue[0] == 1) {value = "when on"}
  97. if (cmd.configurationValue[0] == 2) {value = "never"}
  98. [name: "indicatorStatus", value: value, display: false]
  99. }
  100.  
  101. def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
  102. [name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false]
  103. }
  104.  
  105. def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
  106. if (state.manufacturer != cmd.manufacturerName) {
  107. updateDataValue("manufacturer", cmd.manufacturerName)
  108. }
  109. }
  110.  
  111. def zwaveEvent(physicalgraph.zwave.Command cmd) {
  112. // Handles all Z-Wave commands we aren't interested in
  113. [:]
  114. }
  115.  
  116. def on() {
  117. delayBetween([
  118. zwave.basicV1.basicSet(value: 0xFF).format(),
  119. zwave.switchBinaryV1.switchBinaryGet().format()
  120. ])
  121. }
  122.  
  123. def off() {
  124. delayBetween([
  125. zwave.basicV1.basicSet(value: 0x00).format(),
  126. zwave.switchBinaryV1.switchBinaryGet().format()
  127. ])
  128. }
  129.  
  130. def poll() {
  131. delayBetween([
  132. zwave.switchBinaryV1.switchBinaryGet().format(),
  133. zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
  134. ])
  135. }
  136.  
  137. def refresh() {
  138. delayBetween([
  139. zwave.switchBinaryV1.switchBinaryGet().format(),
  140. zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
  141. ])
  142. }
  143.  
  144. def indicatorWhenOn() {
  145. sendEvent(name: "indicatorStatus", value: "when on", display: false)
  146. zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()
  147. }
  148.  
  149. def indicatorWhenOff() {
  150. sendEvent(name: "indicatorStatus", value: "when off", display: false)
  151. zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()
  152. }
  153.  
  154. def indicatorNever() {
  155. sendEvent(name: "indicatorStatus", value: "never", display: false)
  156. zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()
  157. }
  158.  
  159. def invertSwitch(invert=true) {
  160. if (invert) {
  161. zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
  162. }
  163. else {
  164. zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement