Advertisement
erocm123

Inovelli Dimmer NZW31 - Changes for digital vs physical

Jan 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.81 KB | None | 0 0
  1. /**
  2. * Inovelli Dimmer NZW31
  3. * Author: Eric Maycock (erocm123)
  4. * Date: 2018-12-04
  5. *
  6. * Copyright 2018 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. * 2018-12-04: Added option to "Disable Remote Control" and to send button events 1,pushed / 1,held for on / off.
  18. *
  19. * 2018-06-20: Modified tile layout. Update firmware version reporting. Bug fix.
  20. *
  21. * 2018-06-08: Remove communication method check from updated().
  22. *
  23. * 2018-04-23: Added configuration parameters for association group 3.
  24. *
  25. * 2018-04-11: No longer deleting child devices when user toggles the option off. SmartThings was throwing errors.
  26. * User will have to manually delete them.
  27. *
  28. * 2018-03-08: Added support for local protection to disable local control. Requires firmware 1.03+.
  29. * Also merging handler from NZW31T as they are identical other than the LED indicator.
  30. * Child device creation option added for local control setting. Child device must be installed:
  31. * https://github.com/erocm123/SmartThingsPublic/blob/master/devicetypes/erocm123/switch-level-child-device.src
  32. *
  33. * 2018-03-01: Added support for additional configuration options (default level - local & z-wave) and child devices
  34. * for adjusting configuration options from other SmartApps. Requires firmware 1.02+.
  35. *
  36. * 2018-02-26: Added support for Z-Wave Association Tool SmartApp. Associations require firmware 1.02+.
  37. * https://github.com/erocm123/SmartThingsPublic/tree/master/smartapps/erocm123/z-waveat
  38. */
  39.  
  40. metadata {
  41. definition (name: "Inovelli Dimmer NZW31", namespace: "erocm123", author: "Eric Maycock", vid: "generic-dimmer") {
  42. capability "Switch"
  43. capability "Refresh"
  44. capability "Polling"
  45. capability "Actuator"
  46. capability "Sensor"
  47. //capability "Health Check"
  48. capability "Switch Level"
  49. capability "Configuration"
  50. capability "Button"
  51. capability "Holdable Button"
  52.  
  53. attribute "lastActivity", "String"
  54. attribute "lastEvent", "String"
  55. attribute "firmware", "String"
  56.  
  57. command "setAssociationGroup", ["number", "enum", "number", "number"] // group number, nodes, action (0 - remove, 1 - add), multi-channel endpoint (optional)
  58.  
  59. fingerprint mfr: "0312", prod: "0118", model: "1E1C", deviceJoinName: "Inovelli Dimmer"
  60. fingerprint mfr: "015D", prod: "0118", model: "1E1C", deviceJoinName: "Inovelli Dimmer"
  61. fingerprint mfr: "015D", prod: "1F01", model: "1F01", deviceJoinName: "Inovelli Dimmer"
  62. fingerprint mfr: "0312", prod: "1F01", model: "1F01", deviceJoinName: "Inovelli Dimmer"
  63. fingerprint deviceId: "0x1101", inClusters: "0x5E,0x26,0x27,0x70,0x75,0x22,0x85,0x8E,0x59,0x55,0x86,0x72,0x5A,0x73,0x6C,0x7A"
  64. }
  65.  
  66. simulator {
  67. }
  68.  
  69. preferences {
  70. input "minimumLevel", "number", title: "Minimum Level\n\nMinimum dimming level for attached light\nRange: 1 to 40", description: "Tap to set", required: false, range: "1..40", defaultValue: "1"
  71. input "dimmingStep", "number", title: "Dimming Step Size\n\nPercentage of step when switch is dimming up or down\nRange: 0 to 99 (0 - Instant)", description: "Tap to set", required: false, range: "0..99", defaultValue: "3"
  72. 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", defaultValue: "0"
  73. input "ledIndicator", "enum", title: "LED Indicator\n\nTurn LED indicator on when light is: (Paddle Switch Only)", description: "Tap to set", required: false, options:[["1": "On"], ["0": "Off"], ["2": "Disable"], ["3": "Always On"]], defaultValue: "0"
  74. input "invert", "enum", title: "Invert Switch\n\nInvert on & off on the physical switch", description: "Tap to set", required: false, options:[["0": "No"], ["1": "Yes"]], defaultValue: "0"
  75. input "defaultLocal", "number", title: "Default Level (Local)\n\nDefault level when light is turned on at the switch\nRange: 0 to 99\nNote: 0 = Previous Level\n(Firmware 1.02+)", description: "Tap to set", required: false, range: "0..99", defaultValue: "0"
  76. input "defaultZWave", "number", title: "Default Level (Z-Wave)\n\nDefault level when light is turned on via Z-Wave command\nRange: 0 to 99\nNote: 0 = Previous Level\n(Firmware 1.02+)", description: "Tap to set", required: false, range: "0..99", defaultValue: "0"
  77. input "disableLocal", "enum", title: "Disable Local Control\n\nDisable ability to control switch from the wall\n(Firmware 1.03+)", description: "Tap to set", required: false, options:[["2": "Yes"], ["0": "No"]], defaultValue: "0"
  78. input "disableRemote", "enum", title: "Disable Remote Control\n\nDisable ability to control switch from inside SmartThings", description: "Tap to set", required: false, options:[["2": "Yes"], ["0": "No"]], defaultValue: "0"
  79. input "buttonOn", "enum", title: "Send Button Event On\n\nSend the button 1 pushed event when switch turned on from inside SmartThings", description: "Tap to set", required: false, options:[["1": "Yes"], ["0": "No"]], defaultValue: "0"
  80. input "buttonOff", "enum", title: "Send Button Event Off\n\nSend the button 1 held event when switch turned off from inside SmartThings", description: "Tap to set", required: false, options:[["1": "Yes"], ["0": "No"]], defaultValue: "0"
  81. input description: "Use the below options to enable child devices for the specified settings. This will allow you to adjust these settings using SmartApps such as Smart Lighting. If any of the options are enabled, make sure you have the appropriate child device handlers installed.\n(Firmware 1.02+)", title: "Child Devices", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  82. input "enableDefaultLocalChild", "bool", title: "Default Local Level", description: "", required: false, defaultValue: false
  83. input "enableDefaultZWaveChild", "bool", title: "Default Z-Wave Level", description: "", required: false, defaultValue: false
  84. input "enableDisableLocalChild", "bool", title: "Disable Local Control", description: "", required: false, defaultValue: false
  85. input description: "Use the \"Z-Wave Association Tool\" SmartApp to set device associations.\n(Firmware 1.02+)\n\nGroup 2: Sends on/off commands to associated devices when switch is pressed (BASIC_SET).\n\nGroup 3: Sends dim/brighten commands to associated devices when switch is pressed (SWITCH_MULTILEVEL_SET).", title: "Associations", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  86. input "group3Setting", "enum", title: "Association Group 3 Behavior\n\nChange how devices respond when associated in group 3", description: "Tap to set", required: false, options:[["1": "Keep in Sync"], ["0": "Dim up/down"]], defaultValue: "0"
  87. input description: "When should the switch send commands to associated devices?", title: "Association Behavior", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  88. input "group3local", "bool", title: "Send command on local action", description: "", required: false, defaultValue: true
  89. input "group3remote", "bool", title: "Send command on z-wave action", description: "", required: false, defaultValue: true
  90. input "group3way", "bool", title: "Send command on 3-way action", description: "", required: false, defaultValue: true
  91. input "group3timer", "bool", title: "Send command on auto off timer", description: "", required: false, defaultValue: true
  92. }
  93.  
  94. tiles {
  95. multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
  96. tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
  97. attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  98. attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  99. attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
  100. attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff"
  101. }
  102. tileAttribute ("device.level", key: "SLIDER_CONTROL") {
  103. attributeState "level", action:"switch level.setLevel"
  104. }
  105. tileAttribute("device.lastEvent", key: "SECONDARY_CONTROL") {
  106. attributeState("default", label:'${currentValue}')
  107. }
  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("firmware", "device.firmware", inactiveLabel: false, decoration: "flat", width: 2, height: 1) {
  114. state "default", label: 'fw: ${currentValue}', icon: ""
  115. }
  116.  
  117. valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 5, height: 1) {
  118. state "default", label: '', icon: "https://inovelli.com/wp-content/uploads/Device-Handler/Inovelli-Device-Handler-Logo.png"
  119. }
  120. standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 1, height: 1) {
  121. state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh"
  122. }
  123. }
  124. }
  125.  
  126. def installed() {
  127. log.debug "installed()"
  128. refresh()
  129. }
  130.  
  131. def configure() {
  132. log.debug "configure()"
  133. def cmds = initialize()
  134. commands(cmds)
  135. }
  136.  
  137. def updated() {
  138. if (!state.lastRan || now() >= state.lastRan + 2000) {
  139. log.debug "updated()"
  140. state.lastRan = now()
  141. def cmds = initialize()
  142. response(commands(cmds))
  143. } else {
  144. log.debug "updated() ran within the last 2 seconds. Skipping execution."
  145. }
  146. }
  147.  
  148. def initialize() {
  149. sendEvent(name: "checkInterval", value: 3 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
  150. if (enableDefaultLocalChild && !childExists("ep8")) {
  151. try {
  152. addChildDevice("Switch Level Child Device", "${device.deviceNetworkId}-ep8", null,
  153. [completedSetup: true, label: "${device.displayName} (Default Local Level)",
  154. isComponent: true, componentName: "ep8", componentLabel: "Default Local Level"])
  155. } catch (e) {
  156. runIn(3, "sendAlert", [data: [message: "Child device creation failed. Make sure the device handler for \"Switch Level Child Device\" is installed"]])
  157. }
  158. } else if (!enableDefaultLocalChild && childExists("ep8")) {
  159. log.debug "Trying to delete child device ep8. If this fails it is likely that there is a SmartApp using the child device in question."
  160. def children = childDevices
  161. def childDevice = children.find{it.deviceNetworkId.endsWith("ep8")}
  162. try {
  163. log.debug "SmartThings has issues trying to delete the child device when it is in use. Need to manually delete them."
  164. //if(childDevice) deleteChildDevice(childDevice.deviceNetworkId)
  165. } catch (e) {
  166. runIn(3, "sendAlert", [data: [message: "Failed to delete child device. Make sure the device is not in use by any SmartApp."]])
  167. }
  168. }
  169. if (enableDefaultZWaveChild && !childExists("ep9")) {
  170. try {
  171. addChildDevice("Switch Level Child Device", "${device.deviceNetworkId}-ep9", null,
  172. [completedSetup: true, label: "${device.displayName} (Default Z-Wave Level)",
  173. isComponent: true, componentName: "ep9", componentLabel: "Default Z-Wave Level"])
  174. } catch (e) {
  175. runIn(3, "sendAlert", [data: [message: "Child device creation failed. Make sure the device handler for \"Switch Level Child Device\" is installed"]])
  176. }
  177. } else if (!enableDefaultLocalChild && childExists("ep9")) {
  178. log.debug "Trying to delete child device ep9. If this fails it is likely that there is a SmartApp using the child device in question."
  179. def children = childDevices
  180. def childDevice = children.find{it.deviceNetworkId.endsWith("ep9")}
  181. try {
  182. log.debug "SmartThings has issues trying to delete the child device when it is in use. Need to manually delete them."
  183. //if(childDevice) deleteChildDevice(childDevice.deviceNetworkId)
  184. } catch (e) {
  185. runIn(3, "sendAlert", [data: [message: "Failed to delete child device. Make sure the device is not in use by any SmartApp."]])
  186. }
  187. }
  188. if (enableDisableLocalChild && !childExists("ep101")) {
  189. try {
  190. addChildDevice("Switch Level Child Device", "${device.deviceNetworkId}-ep101", null,
  191. [completedSetup: true, label: "${device.displayName} (Disable Local Control)",
  192. isComponent: true, componentName: "ep101", componentLabel: "Disable Local Control"])
  193. } catch (e) {
  194. runIn(3, "sendAlert", [data: [message: "Child device creation failed. Make sure the device handler for \"Switch Level Child Device\" is installed"]])
  195. }
  196. } else if (!enableDisableLocalChild && childExists("ep101")) {
  197. log.debug "Trying to delete child device ep101. If this fails it is likely that there is a SmartApp using the child device in question."
  198. def children = childDevices
  199. def childDevice = children.find{it.deviceNetworkId.endsWith("ep101")}
  200. try {
  201. log.debug "SmartThings has issues trying to delete the child device when it is in use. Need to manually delete them."
  202. //if(childDevice) deleteChildDevice(childDevice.deviceNetworkId)
  203. } catch (e) {
  204. runIn(3, "sendAlert", [data: [message: "Failed to delete child device. Make sure the device is not in use by any SmartApp."]])
  205. }
  206. }
  207. if (device.label != state.oldLabel) {
  208. def children = childDevices
  209. def childDevice = children.find{it.deviceNetworkId.endsWith("ep8")}
  210. if (childDevice)
  211. childDevice.setLabel("${device.displayName} (Default Local Level)")
  212. childDevice = children.find{it.deviceNetworkId.endsWith("ep9")}
  213. if (childDevice)
  214. childDevice.setLabel("${device.displayName} (Default Z-Wave Level)")
  215. childDevice = children.find{it.deviceNetworkId.endsWith("ep101")}
  216. if (childDevice)
  217. childDevice.setLabel("${device.displayName} (Disable Local Control)")
  218. state.oldLabel = device.label
  219. }
  220.  
  221. def cmds = processAssociations()
  222. cmds << zwave.versionV1.versionGet()
  223. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: dimmingStep!=null? dimmingStep.toInteger() : 1, parameterNumber: 1, size: 1)
  224. cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
  225. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: minimumLevel!=null? minimumLevel.toInteger() : 1, parameterNumber: 2, size: 1)
  226. cmds << zwave.configurationV1.configurationGet(parameterNumber: 2)
  227. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: ledIndicator!=null? ledIndicator.toInteger() : 0, parameterNumber: 3, size: 1)
  228. cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
  229. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: invert!=null? invert.toInteger() : 0, parameterNumber: 4, size: 1)
  230. cmds << zwave.configurationV1.configurationGet(parameterNumber: 4)
  231. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: autoOff!=null? autoOff.toInteger() : 0, parameterNumber: 5, size: 2)
  232. cmds << zwave.configurationV1.configurationGet(parameterNumber: 5)
  233. if (state.defaultLocal != settings.defaultLocal) {
  234. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: defaultLocal!=null? defaultLocal.toInteger() : 0, parameterNumber: 8, size: 1)
  235. cmds << zwave.configurationV1.configurationGet(parameterNumber: 8)
  236. }
  237. if (state.defaultZWave != settings.defaultZWave) {
  238. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: defaultZWave!=null? defaultZWave.toInteger() : 0, parameterNumber: 9, size: 1)
  239. cmds << zwave.configurationV1.configurationGet(parameterNumber: 9)
  240. }
  241. if (state.disableLocal != settings.disableLocal) {
  242. cmds << zwave.protectionV2.protectionSet(localProtectionState : disableLocal!=null? disableLocal.toInteger() : 0, rfProtectionState: 0)
  243. cmds << zwave.protectionV2.protectionGet()
  244. }
  245.  
  246. //Calculate group 3 configuration parameter
  247. def group3value = 0
  248. group3value += group3local? 1 : 0
  249. group3value += group3way? 2 : 0
  250. group3value += group3remote? 4 : 0
  251. group3value += group3timer? 8 : 0
  252.  
  253. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: group3value, parameterNumber: 6, size: 1)
  254. cmds << zwave.configurationV1.configurationGet(parameterNumber: 6)
  255. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: group3Setting!=null? group3Setting.toInteger() : 0, parameterNumber: 7, size: 1)
  256. cmds << zwave.configurationV1.configurationGet(parameterNumber: 7)
  257.  
  258. state.defaultLocal = settings.defaultLocal
  259. state.defaultZWave = settings.defaultZWave
  260. state.disableLocal = settings.disableLocal
  261. return cmds
  262. }
  263.  
  264. def parse(description) {
  265. def result = null
  266. if (description.startsWith("Err 106")) {
  267. state.sec = 0
  268. result = createEvent(descriptionText: description, isStateChange: true)
  269. } else if (description != "updated") {
  270. def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x70: 1, 0x98: 1])
  271. if (cmd) {
  272. result = zwaveEvent(cmd)
  273. log.debug("'$description' parsed to $result")
  274. } else {
  275. log.debug("Couldn't zwave.parse '$description'")
  276. }
  277. }
  278. def now
  279. if(location.timeZone)
  280. now = new Date().format("yyyy MMM dd EEE h:mm:ss a", location.timeZone)
  281. else
  282. now = new Date().format("yyyy MMM dd EEE h:mm:ss a")
  283. sendEvent(name: "lastActivity", value: now, displayed:false)
  284. result
  285. }
  286.  
  287. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
  288. // Since SmartThings isn't filtering duplicate events, we are skipping these
  289. // Switch is sending SwitchMultilevelReport as well (which we will use)
  290. //dimmerEvents(cmd)
  291. }
  292.  
  293. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
  294. dimmerEvents(cmd)
  295. }
  296.  
  297. def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  298. dimmerEvents(cmd)
  299. }
  300.  
  301. def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
  302. dimmerEvents(cmd)
  303. }
  304.  
  305. private dimmerEvents(physicalgraph.zwave.Command cmd) {
  306. def value = (cmd.value ? "on" : "off")
  307. if (state.lastGet == null) state.lastGet = now()
  308. def type = (now() - state.lastGet) > 3000? "physical" : "digital"
  309. def result = [createEvent(name: "switch", value: value, type: type)]
  310. if (cmd.value) {
  311. result << createEvent(name: "level", value: cmd.value, unit: "%", type: type)
  312. }
  313. return result
  314. }
  315.  
  316. def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
  317. log.debug "${device.displayName} parameter '${cmd.parameterNumber}' with a byte size of '${cmd.size}' is set to '${cmd2Integer(cmd.configurationValue)}'"
  318. def integerValue = cmd2Integer(cmd.configurationValue)
  319. switch (cmd.parameterNumber) {
  320. case 8:
  321. def children = childDevices
  322. def childDevice = children.find{it.deviceNetworkId.endsWith("ep8")}
  323. if (childDevice) {
  324. childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off")
  325. childDevice.sendEvent(name: "level", value: integerValue)
  326. }
  327. break
  328. case 9:
  329. def children = childDevices
  330. def childDevice = children.find{it.deviceNetworkId.endsWith("ep9")}
  331. if (childDevice) {
  332. childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off")
  333. childDevice.sendEvent(name: "level", value: integerValue)
  334. }
  335. break
  336. }
  337. }
  338.  
  339. def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
  340. def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x25: 1])
  341. if (encapsulatedCommand) {
  342. state.sec = 1
  343. zwaveEvent(encapsulatedCommand)
  344. }
  345. }
  346.  
  347. def zwaveEvent(physicalgraph.zwave.Command cmd) {
  348. log.debug "Unhandled: $cmd"
  349. null
  350. }
  351.  
  352. def on() {
  353. state.lastGet = now()
  354. if (buttonOn == "1") {
  355. sendEvent([name: "button", value: "pushed", data: [buttonNumber: 1], descriptionText: "$device.displayName button 1 was pushed", isStateChange: true, type: "digital"])
  356. }
  357. if (disableRemote != "2") {
  358. commands([
  359. zwave.basicV1.basicSet(value: 0xFF),
  360. zwave.switchMultilevelV1.switchMultilevelGet(),
  361. ])
  362. } else {
  363. commands([
  364. zwave.switchMultilevelV1.switchMultilevelGet()
  365. ])
  366. }
  367. }
  368.  
  369. def off() {
  370. state.lastGet = now()
  371. if (buttonOff == "1") {
  372. sendEvent([name: "button", value: "held", data: [buttonNumber: 1], descriptionText: "$device.displayName button 1 was held", isStateChange: true, type: "digital"])
  373. }
  374. if (disableRemote != "2") {
  375. commands([
  376. zwave.basicV1.basicSet(value: 0x00),
  377. zwave.switchMultilevelV1.switchMultilevelGet()
  378. ])
  379. } else {
  380. commands([
  381. zwave.switchMultilevelV1.switchMultilevelGet()
  382. ])
  383. }
  384. }
  385.  
  386. def setLevel(value) {
  387. state.lastGet = now()
  388. if (disableRemote != "2") {
  389. commands([
  390. zwave.basicV1.basicSet(value: value < 100 ? value : 99),
  391. zwave.switchMultilevelV1.switchMultilevelGet()
  392. ])
  393. } else {
  394. commands([
  395. zwave.switchMultilevelV1.switchMultilevelGet()
  396. ])
  397. }
  398. }
  399.  
  400. def setLevel(value, duration) {
  401. state.lastGet = now()
  402. if (disableRemote != "2") {
  403. def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
  404. commands([
  405. zwave.switchMultilevelV2.switchMultilevelSet(value: value < 100 ? value : 99, dimmingDuration: dimmingDuration),
  406. zwave.switchMultilevelV1.switchMultilevelGet()
  407. ])
  408. } else {
  409. commands([
  410. zwave.switchMultilevelV1.switchMultilevelGet()
  411. ])
  412. }
  413. }
  414.  
  415.  
  416. void childOn(String dni) {
  417. log.debug "childOn($dni)"
  418. childSetLevel(dni, 99)
  419. }
  420.  
  421. void childOff(String dni) {
  422. log.debug "childOff($dni)"
  423. childSetLevel(dni, 0)
  424. }
  425.  
  426. void childRefresh(String dni) {
  427. log.debug "childRefresh($dni)"
  428. }
  429.  
  430. void childSetLevel(String dni, value) {
  431. def valueaux = value as Integer
  432. def level = Math.max(Math.min(valueaux, 99), 0)
  433. def cmds = []
  434. switch (channelNumber(dni)) {
  435. case 8:
  436. cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1) ))
  437. cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni) )))
  438. break
  439. case 9:
  440. cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1) ))
  441. cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni) )))
  442. break
  443. case 101:
  444. cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionSet(localProtectionState : level > 0 ? 2 : 0, rfProtectionState: 0) ))
  445. cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionGet() ))
  446. break
  447. }
  448. sendHubCommand(cmds, 1000)
  449. }
  450.  
  451. def cmd2Integer(array) {
  452. switch(array.size()) {
  453. case 1:
  454. array[0]
  455. break
  456. case 2:
  457. ((array[0] & 0xFF) << 8) | (array[1] & 0xFF)
  458. break
  459. case 3:
  460. ((array[0] & 0xFF) << 16) | ((array[1] & 0xFF) << 8) | (array[2] & 0xFF)
  461. break
  462. case 4:
  463. ((array[0] & 0xFF) << 24) | ((array[1] & 0xFF) << 16) | ((array[2] & 0xFF) << 8) | (array[3] & 0xFF)
  464. break
  465. }
  466. }
  467.  
  468. private channelNumber(String dni) {
  469. dni.split("-ep")[-1] as Integer
  470. }
  471.  
  472. def childExists(ep) {
  473. def children = childDevices
  474. def childDevice = children.find{it.deviceNetworkId.endsWith(ep)}
  475. if (childDevice)
  476. return true
  477. else
  478. return false
  479. }
  480.  
  481. def ping() {
  482. log.debug "ping()"
  483. refresh()
  484. }
  485.  
  486. def poll() {
  487. log.debug "poll()"
  488. refresh()
  489. }
  490.  
  491. def refresh() {
  492. log.debug "refresh()"
  493. state.lastGet = now()
  494. commands([zwave.switchBinaryV1.switchBinaryGet(),
  495. zwave.switchMultilevelV1.switchMultilevelGet()
  496. ])
  497. }
  498.  
  499. private command(physicalgraph.zwave.Command cmd) {
  500. if (state.sec) {
  501. zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
  502. } else {
  503. cmd.format()
  504. }
  505. }
  506.  
  507. private commands(commands, delay=500) {
  508. delayBetween(commands.collect{ command(it) }, delay)
  509. }
  510.  
  511. def setDefaultAssociations() {
  512. def smartThingsHubID = (zwaveHubNodeId.toString().format( '%02x', zwaveHubNodeId )).toUpperCase()
  513. state.defaultG1 = [smartThingsHubID]
  514. state.defaultG2 = []
  515. state.defaultG3 = []
  516. }
  517.  
  518. def setAssociationGroup(group, nodes, action, endpoint = null){
  519. if (!state."desiredAssociation${group}") {
  520. state."desiredAssociation${group}" = nodes
  521. } else {
  522. switch (action) {
  523. case 0:
  524. state."desiredAssociation${group}" = state."desiredAssociation${group}" - nodes
  525. break
  526. case 1:
  527. state."desiredAssociation${group}" = state."desiredAssociation${group}" + nodes
  528. break
  529. }
  530. }
  531. }
  532.  
  533. def processAssociations(){
  534. def cmds = []
  535. setDefaultAssociations()
  536. def associationGroups = 5
  537. if (state.associationGroups) {
  538. associationGroups = state.associationGroups
  539. } else {
  540. log.debug "Getting supported association groups from device"
  541. cmds << zwave.associationV2.associationGroupingsGet()
  542. }
  543. for (int i = 1; i <= associationGroups; i++){
  544. if(state."actualAssociation${i}" != null){
  545. if(state."desiredAssociation${i}" != null || state."defaultG${i}") {
  546. def refreshGroup = false
  547. ((state."desiredAssociation${i}"? state."desiredAssociation${i}" : [] + state."defaultG${i}") - state."actualAssociation${i}").each {
  548. log.debug "Adding node $it to group $i"
  549. cmds << zwave.associationV2.associationSet(groupingIdentifier:i, nodeId:Integer.parseInt(it,16))
  550. refreshGroup = true
  551. }
  552. ((state."actualAssociation${i}" - state."defaultG${i}") - state."desiredAssociation${i}").each {
  553. log.debug "Removing node $it from group $i"
  554. cmds << zwave.associationV2.associationRemove(groupingIdentifier:i, nodeId:Integer.parseInt(it,16))
  555. refreshGroup = true
  556. }
  557. if (refreshGroup == true) cmds << zwave.associationV2.associationGet(groupingIdentifier:i)
  558. else log.debug "There are no association actions to complete for group $i"
  559. }
  560. } else {
  561. log.debug "Association info not known for group $i. Requesting info from device."
  562. cmds << zwave.associationV2.associationGet(groupingIdentifier:i)
  563. }
  564. }
  565. return cmds
  566. }
  567.  
  568. def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) {
  569. def temp = []
  570. if (cmd.nodeId != []) {
  571. cmd.nodeId.each {
  572. temp += it.toString().format( '%02x', it.toInteger() ).toUpperCase()
  573. }
  574. }
  575. state."actualAssociation${cmd.groupingIdentifier}" = temp
  576. log.debug "Associations for Group ${cmd.groupingIdentifier}: ${temp}"
  577. updateDataValue("associationGroup${cmd.groupingIdentifier}", "$temp")
  578. }
  579.  
  580. def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationGroupingsReport cmd) {
  581. sendEvent(name: "groups", value: cmd.supportedGroupings)
  582. log.debug "Supported association groups: ${cmd.supportedGroupings}"
  583. state.associationGroups = cmd.supportedGroupings
  584. }
  585.  
  586. def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
  587. log.debug cmd
  588. if(cmd.applicationVersion && cmd.applicationSubVersion) {
  589. def firmware = "${cmd.applicationVersion}.${cmd.applicationSubVersion.toString().padLeft(2,'0')}"
  590. state.needfwUpdate = "false"
  591. createEvent(name: "firmware", value: "${firmware}")
  592. }
  593. }
  594.  
  595. def zwaveEvent(physicalgraph.zwave.commands.protectionv2.ProtectionReport cmd) {
  596. log.debug cmd
  597. def integerValue = cmd.localProtectionState
  598. def children = childDevices
  599. def childDevice = children.find{it.deviceNetworkId.endsWith("ep101")}
  600. if (childDevice) {
  601. childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off")
  602. }
  603. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement