Advertisement
erocm123

NZW30 Z-Wave Replace

Feb 12th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. /**
  2. * Inovelli Switch NZW30
  3. * Author: Eric Maycock (erocm123)
  4. * Date: 2017-12-16
  5. * Copyright 2017 Eric Maycock
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  8. * in compliance with the License. You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  13. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing permissions and limitations under the License.
  15. *
  16. */
  17.  
  18. metadata {
  19. definition (name: "Inovelli Switch NZW30", namespace: "erocm123", author: "Eric Maycock") {
  20. capability "Switch"
  21. capability "Refresh"
  22. capability "Polling"
  23. capability "Actuator"
  24. capability "Sensor"
  25. //capability "Health Check"
  26. capability "Indicator"
  27.  
  28. attribute "lastActivity", "String"
  29. attribute "lastEvent", "String"
  30.  
  31. fingerprint mfr: "0312", prod: "0117", model: "1E1C", deviceJoinName: "Inovelli Switch"
  32. fingerprint mfr: "015D", prod: "0117", model: "1E1C", deviceJoinName: "Inovelli Switch"
  33. fingerprint mfr: "015D", prod: "1E01", model: "1E01", deviceJoinName: "Inovelli Switch"
  34. fingerprint mfr: "0312", prod: "1E01", model: "1E01", deviceJoinName: "Inovelli Switch"
  35. }
  36.  
  37. simulator {
  38. }
  39.  
  40. preferences {
  41. input "autoOff", "number", title: "Auto Off\n\nAutomatically turn switch off after this number of seconds\nRange: 0 to 32767", description: "Tap to set", required: false, range: "0..32767"
  42. input "ledIndicator", "enum", title: "LED Indicator\n\nTurn LED indicator on when light is:\n", description: "Tap to set", required: false, options:[1: "On", 0: "Off", 2: "Disable"], defaultValue: 1
  43. input "invert", "enum", title: "Invert Switch", description: "Tap to set", required: false, options:[0: "No", 1: "Yes"], defaultValue: 0
  44. }
  45.  
  46. tiles {
  47. multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
  48. tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
  49. attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  50. attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  51. attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  52. attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  53. }
  54. tileAttribute("device.lastEvent", key: "SECONDARY_CONTROL") {
  55. attributeState("default", label:'${currentValue}')
  56. }
  57. }
  58. standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
  59. state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh"
  60. }
  61.  
  62. valueTile("lastActivity", "device.lastActivity", inactiveLabel: false, decoration: "flat", width: 4, height: 1) {
  63. state "default", label: 'Last Activity: ${currentValue}',icon: "st.Health & Wellness.health9"
  64. }
  65.  
  66. valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 4, height: 1) {
  67. state "default", label: '', icon: "https://inovelli.com/wp-content/uploads/Device-Handler/Inovelli-Device-Handler-Logo.png"
  68. }
  69. }
  70. }
  71.  
  72. def installed() {
  73. refresh()
  74. }
  75.  
  76. def updated() {
  77. state.sec = 0
  78. sendEvent(name: "checkInterval", value: 3 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
  79. def cmds = []
  80. cmds << zwave.associationV2.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)
  81. cmds << zwave.associationV2.associationGet(groupingIdentifier:1)
  82. cmds << zwave.configurationV1.configurationSet(configurationValue: [ledIndicator? ledIndicator.toInteger() : 1], parameterNumber: 3, size: 1)
  83. cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
  84. cmds << zwave.configurationV1.configurationSet(configurationValue: [invert? invert.toInteger() : 0], parameterNumber: 4, size: 1)
  85. cmds << zwave.configurationV1.configurationGet(parameterNumber: 4)
  86. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: autoOff? autoOff.toInteger() : 0, parameterNumber: 5, size: 2)
  87. cmds << zwave.configurationV1.configurationGet(parameterNumber: 5)
  88. response(commands(cmds))
  89. }
  90.  
  91. def parse(description) {
  92. def result = null
  93. state.sec = 0
  94. if (description.startsWith("Err 106")) {
  95. state.sec = 0
  96. result = createEvent(descriptionText: description, isStateChange: true)
  97. } else if (description != "updated") {
  98. def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x70: 1, 0x98: 1])
  99. if (cmd) {
  100. result = zwaveEvent(cmd)
  101. log.debug("'$description' parsed to $result")
  102. } else {
  103. log.debug("Couldn't zwave.parse '$description'")
  104. }
  105. }
  106. def now
  107. if(location.timeZone)
  108. now = new Date().format("yyyy MMM dd EEE h:mm:ss a", location.timeZone)
  109. else
  110. now = new Date().format("yyyy MMM dd EEE h:mm:ss a")
  111. sendEvent(name: "lastActivity", value: now, displayed:false)
  112. result
  113. }
  114.  
  115. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
  116. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "physical")
  117. }
  118.  
  119. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
  120. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "physical")
  121. }
  122.  
  123. def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  124. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital")
  125. }
  126.  
  127. def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
  128. def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x25: 1])
  129. if (encapsulatedCommand) {
  130. state.sec = 1
  131. zwaveEvent(encapsulatedCommand)
  132. }
  133. }
  134.  
  135. def zwaveEvent(physicalgraph.zwave.Command cmd) {
  136. log.debug "Unhandled: $cmd"
  137. null
  138. }
  139.  
  140. def on() {
  141. commands([
  142. zwave.basicV1.basicSet(value: 0xFF),
  143. zwave.switchBinaryV1.switchBinaryGet()
  144. ])
  145. }
  146.  
  147. def off() {
  148. commands([
  149. zwave.basicV1.basicSet(value: 0x00),
  150. zwave.switchBinaryV1.switchBinaryGet()
  151. ])
  152. }
  153.  
  154. def ping() {
  155. refresh()
  156. }
  157.  
  158. def poll() {
  159. refresh()
  160. }
  161.  
  162. def refresh() {
  163. commands(zwave.switchBinaryV1.switchBinaryGet())
  164. }
  165.  
  166. private command(physicalgraph.zwave.Command cmd) {
  167. if (state.sec) {
  168. zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
  169. } else {
  170. cmd.format()
  171. }
  172. }
  173.  
  174. private commands(commands, delay=500) {
  175. delayBetween(commands.collect{ command(it) }, delay)
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement