Advertisement
erocm123

NZW30 w/Scene Z-Wave Replace

Feb 12th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.99 KB | None | 0 0
  1. /**
  2. * Inovelli Switch NZW30 w/Scene
  3. * Author: Eric Maycock (erocm123)
  4. * Date: 2017-07-02
  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 Switch NZW30 w/Scene", 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 "Button"
  28. capability "Holdable Button"
  29. capability "Indicator"
  30.  
  31. attribute "lastActivity", "String"
  32. attribute "lastEvent", "String"
  33.  
  34. command "pressUpX1"
  35. command "pressDownX1"
  36. command "pressUpX2"
  37. command "pressDownX2"
  38. command "pressUpX3"
  39. command "pressDownX3"
  40. command "pressUpX4"
  41. command "pressDownX4"
  42. command "pressUpX5"
  43. command "pressDownX5"
  44. command "holdUp"
  45. command "holdDown"
  46.  
  47. fingerprint mfr: "015D", prod: "B111", model: "1E1C", deviceJoinName: "Inovelli Switch"
  48. fingerprint mfr: "015D", prod: "1E00", model: "1E00", deviceJoinName: "Inovelli Switch"
  49. fingerprint mfr: "0312", prod: "1E00", model: "1E00", deviceJoinName: "Inovelli Switch"
  50. }
  51.  
  52. simulator {
  53. }
  54.  
  55. preferences {
  56. 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"
  57. 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
  58. input "invert", "enum", title: "Invert Switch", description: "Tap to set", required: false, options:[0: "No", 1: "Yes"], defaultValue: 0
  59.  
  60. input description: "1 pushed - Up 1x click\n2 pushed - Up 2x click\n3 pushed - Up 3x click\n4 pushed - Up 4x click\n5 pushed - Up 5x click\n6 pushed - Up held\n\n1 held - Down 1x click\n2 held - Down 2x click\n3 held - Down 3x click\n4 held - Down 4x click\n5 held - Down 5x click\n6 held - Down held", title: "Button Mappings", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  61. }
  62.  
  63. tiles {
  64. multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
  65. tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
  66. attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  67. attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  68. attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  69. attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  70. }
  71. tileAttribute("device.lastEvent", key: "SECONDARY_CONTROL") {
  72. attributeState("default", label:'${currentValue}',icon: "st.unknown.zwave.remote-controller")
  73. }
  74. }
  75. standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
  76. state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh"
  77. }
  78. standardTile("pressUpX2", "device.button", width: 2, height: 1, decoration: "flat") {
  79. state "default", label: "Tap ▲▲", backgroundColor: "#ffffff", action: "pressUpX2"
  80. }
  81. standardTile("pressUpX3", "device.button", width: 2, height: 1, decoration: "flat") {
  82. state "default", label: "Tap ▲▲▲", backgroundColor: "#ffffff", action: "pressUpX3"
  83. }
  84. standardTile("pressDownX2", "device.button", width: 2, height: 1, decoration: "flat") {
  85. state "default", label: "Tap ▼▼", backgroundColor: "#ffffff", action: "pressDownX2"
  86. }
  87. standardTile("pressDownX3", "device.button", width: 2, height: 1, decoration: "flat") {
  88. state "default", label: "Tap ▼▼▼", backgroundColor: "#ffffff", action: "pressDownX3"
  89. }
  90. standardTile("pressUpX4", "device.button", width: 2, height: 1, decoration: "flat") {
  91. state "default", label: "Tap ▲▲▲▲", backgroundColor: "#ffffff", action: "pressUpX4"
  92. }
  93. standardTile("pressUpX5", "device.button", width: 2, height: 1, decoration: "flat") {
  94. state "default", label: "Tap ▲▲▲▲▲", backgroundColor: "#ffffff", action: "pressUpX5"
  95. }
  96. standardTile("holdUp", "device.button", width: 2, height: 1, decoration: "flat") {
  97. state "default", label: "Hold ▲", backgroundColor: "#ffffff", action: "holdUp"
  98. }
  99.  
  100. standardTile("pressDownX4", "device.button", width: 2, height: 1, decoration: "flat") {
  101. state "default", label: "Tap ▼▼▼▼", backgroundColor: "#ffffff", action: "pressDownX4"
  102. }
  103. standardTile("pressDownX5", "device.button", width: 2, height: 1, decoration: "flat") {
  104. state "default", label: "Tap ▼▼▼▼▼", backgroundColor: "#ffffff", action: "pressDownX5"
  105. }
  106. standardTile("holdDown", "device.button", width: 2, height: 1, decoration: "flat") {
  107. state "default", label: "Hold ▼", backgroundColor: "#ffffff", action: "holdDown"
  108. }
  109.  
  110. valueTile("lastActivity", "device.lastActivity", inactiveLabel: false, decoration: "flat", width: 4, height: 1) {
  111. state "default", label: 'Last Activity: ${currentValue}',icon: "st.Health & Wellness.health9"
  112. }
  113. valueTile("blank", "device.blank", inactiveLabel: false, decoration: "flat", width: 2, height: 1) {
  114. state "default", label: '', icon: ""
  115. }
  116. valueTile("info", "device.info", inactiveLabel: false, decoration: "flat", width: 3, height: 1) {
  117. state "default", label: 'Tap on the buttons above to test scenes (ie: Tap ▲ 1x, ▲▲ 2x, etc depending on the button)'
  118. }
  119. valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 3, height: 1) {
  120. state "default", label: '', icon: "https://inovelli.com/wp-content/uploads/Device-Handler/Inovelli-Device-Handler-Logo.png"
  121. }
  122. }
  123. }
  124.  
  125. def installed() {
  126. refresh()
  127. }
  128.  
  129. def updated() {
  130. state.sec = 0
  131. sendEvent(name: "checkInterval", value: 3 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
  132. sendEvent(name: "numberOfButtons", value: 6, displayed: true)
  133. def cmds = []
  134. cmds << zwave.associationV2.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)
  135. cmds << zwave.associationV2.associationGet(groupingIdentifier:1)
  136. cmds << zwave.configurationV1.configurationSet(configurationValue: [ledIndicator? ledIndicator.toInteger() : 1], parameterNumber: 3, size: 1)
  137. cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
  138. cmds << zwave.configurationV1.configurationSet(configurationValue: [invert? invert.toInteger() : 0], parameterNumber: 4, size: 1)
  139. cmds << zwave.configurationV1.configurationGet(parameterNumber: 4)
  140. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: autoOff? autoOff.toInteger() : 0, parameterNumber: 5, size: 2)
  141. cmds << zwave.configurationV1.configurationGet(parameterNumber: 5)
  142. response(commands(cmds))
  143. }
  144.  
  145. def parse(description) {
  146. def result = null
  147. state.sec = 0
  148. if (description.startsWith("Err 106")) {
  149. state.sec = 0
  150. result = createEvent(descriptionText: description, isStateChange: true)
  151. } else if (description != "updated") {
  152. def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x70: 1, 0x98: 1])
  153. if (cmd) {
  154. result = zwaveEvent(cmd)
  155. log.debug("'$description' parsed to $result")
  156. } else {
  157. log.debug("Couldn't zwave.parse '$description'")
  158. }
  159. }
  160. def now
  161. if(location.timeZone)
  162. now = new Date().format("yyyy MMM dd EEE h:mm:ss a", location.timeZone)
  163. else
  164. now = new Date().format("yyyy MMM dd EEE h:mm:ss a")
  165. sendEvent(name: "lastActivity", value: now, displayed:false)
  166. result
  167. }
  168.  
  169. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
  170. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "physical")
  171. }
  172.  
  173. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
  174. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "physical")
  175. }
  176.  
  177. def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  178. createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital")
  179. }
  180.  
  181. def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
  182. def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x25: 1])
  183. if (encapsulatedCommand) {
  184. state.sec = 1
  185. zwaveEvent(encapsulatedCommand)
  186. }
  187. }
  188.  
  189. def zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd) {
  190. switch (cmd.keyAttributes) {
  191. case 0:
  192. createEvent(buttonEvent(cmd.keyAttributes + 1, (cmd.sceneNumber == 2? "pushed" : "held"), "physical"))
  193. break
  194. case 1:
  195. createEvent(buttonEvent(6, (cmd.sceneNumber == 2? "pushed" : "held"), "physical"))
  196. break
  197. case 2:
  198. null
  199. break
  200. default:
  201. createEvent(buttonEvent(cmd.keyAttributes - 1, (cmd.sceneNumber == 2? "pushed" : "held"), "physical"))
  202. break
  203. }
  204. }
  205.  
  206. def buttonEvent(button, value, type = "digital") {
  207. if(button != 6)
  208. sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Tap '.padRight(button+5, '▼'):' Tap '.padRight(button+5, '▲')}", displayed:false)
  209. else
  210. sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Hold ▼':' Hold ▲'}", displayed:false)
  211. [name: "button", value: value, data: [buttonNumber: button], descriptionText: "$device.displayName button $button was $value", isStateChange: true, type: type]
  212. }
  213.  
  214. def zwaveEvent(physicalgraph.zwave.Command cmd) {
  215. log.debug "Unhandled: $cmd"
  216. null
  217. }
  218.  
  219. def on() {
  220. commands([
  221. zwave.basicV1.basicSet(value: 0xFF),
  222. zwave.switchBinaryV1.switchBinaryGet()
  223. ])
  224. }
  225.  
  226. def off() {
  227. commands([
  228. zwave.basicV1.basicSet(value: 0x00),
  229. zwave.switchBinaryV1.switchBinaryGet()
  230. ])
  231. }
  232.  
  233. def ping() {
  234. refresh()
  235. }
  236.  
  237. def poll() {
  238. refresh()
  239. }
  240.  
  241. def refresh() {
  242. commands(zwave.switchBinaryV1.switchBinaryGet())
  243. }
  244.  
  245. private command(physicalgraph.zwave.Command cmd) {
  246. if (state.sec) {
  247. zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
  248. } else {
  249. cmd.format()
  250. }
  251. }
  252.  
  253. private commands(commands, delay=500) {
  254. delayBetween(commands.collect{ command(it) }, delay)
  255. }
  256.  
  257. def pressUpX1() {
  258. sendEvent(buttonEvent(1, "pushed"))
  259. }
  260.  
  261. def pressDownX1() {
  262. sendEvent(buttonEvent(1, "held"))
  263. }
  264.  
  265. def pressUpX2() {
  266. sendEvent(buttonEvent(2, "pushed"))
  267. }
  268.  
  269. def pressDownX2() {
  270. sendEvent(buttonEvent(2, "held"))
  271. }
  272.  
  273. def pressUpX3() {
  274. sendEvent(buttonEvent(3, "pushed"))
  275. }
  276.  
  277. def pressDownX3() {
  278. sendEvent(buttonEvent(3, "held"))
  279. }
  280.  
  281. def pressUpX4() {
  282. sendEvent(buttonEvent(4, "pushed"))
  283. }
  284.  
  285. def pressDownX4() {
  286. sendEvent(buttonEvent(4, "held"))
  287. }
  288.  
  289. def pressUpX5() {
  290. sendEvent(buttonEvent(5, "pushed"))
  291. }
  292.  
  293. def pressDownX5() {
  294. sendEvent(buttonEvent(5, "held"))
  295. }
  296.  
  297. def holdUp() {
  298. sendEvent(buttonEvent(6, "pushed"))
  299. }
  300.  
  301. def holdDown() {
  302. sendEvent(buttonEvent(6, "held"))
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement