Advertisement
erocm123

NZW31 Z-Wave Replace

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