Advertisement
erocm123

Inovelli Dimmer Red Series LZW31-SN (Calibrate Power)

Aug 5th, 2022
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.80 KB | None | 0 0
  1. /**
  2. * Inovelli Dimmer Red Series LZW31-SN (Calibrate Power)
  3. * Author: Eric Maycock (erocm123)
  4. * Date: 2022-05-04
  5. *
  6. * Copyright 2022 Eric Maycock / Inovelli
  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. * 2022-05-04: Fixing start level change problem.
  18. *
  19. * 2021-12-29: Fixing bug when LED color gets stuck on "custom value".
  20. *
  21. * 2021-11-30: Adding push & hold methods for Hubitat capability updates.
  22. *
  23. * 2021-11-24: Increase accuracy of digital vs phsyical detection.
  24. *
  25. * 2021-11-02: Fix and add support for Hubitat's change in componentSetColorTemperature (now supports level).
  26. *
  27. * 2021-06-30: Scene support for aux switch (up, down, held, released) to be used with Smart Bulb. (Firmware 1.54+)
  28. *
  29. * 2021-05-25: Updating method that is used to determine whether to send non-secure, S0, or S2.
  30. *
  31. * 2021-05-10: Adding "LED When Off" child device option.
  32. *
  33. * 2021-05-03: Adding ability to detect firmware target 1 version. firmware1 = target 1 & firmware0 = target 0.
  34. *
  35. * 2021-04-26: Adding options for parameter 52 (disabled, on/off only mode, smartbulb mode).
  36. *
  37. * 2021-04-09: Fix digital command methods "holdUp, holdDown, etc." for those that use them.
  38. *
  39. * 2021-03-10: Adding parameter numbers to preferences description. Also, adding new 7 held & 7 released scenes
  40. * for config button (firmware 1.52+).
  41. *
  42. * 2021-01-28: Adding parameter 50 which allows you to specify the button press delay.
  43. *
  44. * 2021-01-13: Adding white option to notification child devices.
  45. *
  46. * 2020-10-01: Adding custom command setConfigParameter(number, value, size) to be able to easily
  47. * set parameters from Rule Machine.
  48. *
  49. * 2020-09-16: Adding parameter 12 (Association Behavior).
  50. *
  51. * 2020-08-27: Cleaning up device fingerprint info.
  52. *
  53. * 2020-08-25: Fix for button events not getting sent correctly on C7.
  54. * Adding componentSetColorTemperature to allow LED child device to change LED color to white.
  55. * If you set the color of child device it changes it to the specified RGB color. If you
  56. * set the color temperature it will change the LED to white.
  57. * If you update the driver for an already included device you will need to change the
  58. * child device driver to Generic Component RGBW.
  59. *
  60. * 2020-08-12: Fixing on(), off(), & setLevel() commands to match device preference descriptions. Use a different method
  61. * to determine physical vs digital dimmer events.
  62. *
  63. * 2020-08-07: Fix for when setting the LED color via drop down to white the custom color field
  64. * gets populated without user realizing it.
  65. *
  66. * 2020-08-05: Adding S2 support for C-7 Hub.
  67. *
  68. * 2020-07-17: Added configuration parameter (51 & 51) for firmware 1.47+
  69. * 51 allows you to disable the 700ms delay when turing switch on/off from the wall.
  70. * 52 is to put the switch into a "smart bulb" mode to optimize the output for smart bulbs.
  71. *
  72. * 2020-06-02: Change setColor to leave indicator level alone if level is not specified with command.
  73. * LED Indicator child device now works with setLevel as well as setColor.
  74. *
  75. * 2020-05-19: Adding setIndicator command to match Hubitat built in driver.
  76. *
  77. * 2020-05-13: Removed ColorControl capability as it was conflicting with some in-built Hubitat apps.
  78. * Added LED Color child device that can be used in its place. Also fixed incorrect default level range.
  79. *
  80. * 2020-05-05: Adding ColorControl capability to allow changing the LED bar color easily with setColor.
  81. * Adding preferences to automatically disable logs after x minutes. Previously the informational
  82. * logging would disable after 30 minutes without an option for the user.
  83. *
  84. * 2020-05-01: Correctly distinguish between digital and physical on / off. Will not work when you set the level
  85. * with a duration.
  86. *
  87. * 2020-03-27: Adding additional duration options for Notifications. Also adding the commands
  88. * startNotification(value) and stopNotification() to be used in apps like
  89. * WebCoRE or Rule Machine to directly control notifications instead of through child Devices.
  90. * To determine "value": https://nathanfiscus.github.io/inovelli-notification-calc/
  91. *
  92. * 2020-02-25: Switch over to using Hubitat child device drivers. Should still be backwards compatible with
  93. * Inovelli child drivers.
  94. *
  95. * 2020-02-07: Update preferences when user changes parameter or disables relay from switch or from child device.
  96. *
  97. * 2020-02-06: Fix for remote control child device being created when it shouldn't be.
  98. *
  99. * 2020-02-05: Extra button event added for those that want to distinguish held vs pushed.
  100. * Button 8 pushed = Up button held. Button 8 held = Down button held.
  101. * Button 6 pushed = Up button released. Button 6 pushed = Down button released.
  102. *
  103. * 2020-01-28: Update VersionReport parsing because of Hubitat change. Removing unnecessary reports.
  104. *
  105. * 2019-12-03: Specify central scene command class version for upcoming Hubitat update.
  106. *
  107. * 2019-11-20: Fixed Association Group management.
  108. *
  109. * 2019-11-16: Ability to choose custom LED bar color. Child devices to control default level (local & z-wave),
  110. * local & remote protection. Ability to turn on / off info & debug logging. Additional logging added.
  111. * Prevent overwriting parameters that are configured at the switch. Bumping number of notifications to 5.
  112. * Added additional button events for "released" vs "held". Button 8 pushed (up released)
  113. * & button 8 released (down released). Other bug fixes and improvements.
  114. *
  115. * 2019-11-13: Bug fix for not being able to set default level back to 0
  116. * 2020-02-06: updated by bcopeland - added ChangeLevel capability and relevant commands
  117. */
  118.  
  119. import groovy.transform.Field
  120. import groovy.json.JsonOutput
  121.  
  122. @Field static List ledNotificationEndpoints = [16]
  123. @Field static Map ledColorEndpoints = [103:13]
  124. @Field static Map ledIntensityEndpoints = [103:14]
  125. @Field static Map ledIntensityOffEndpoints = [104:15]
  126.  
  127. metadata {
  128. definition (name: "Inovelli Dimmer Red Series LZW31-SN (Calibrate Power)", namespace: "InovelliUSA", author: "Eric Maycock", vid: "generic-dimmer", importUrl:"https://raw.githubusercontent.com/InovelliUSA/Hubitat/master/Drivers/inovelli-dimmer-red-series-lzw31-sn.src/inovelli-dimmer-red-series-lzw31-sn.groovy") {
  129. capability "Switch"
  130. capability "Refresh"
  131. capability "Polling"
  132. capability "Actuator"
  133. capability "Sensor"
  134. capability "PushableButton"
  135. capability "HoldableButton"
  136. capability "ReleasableButton"
  137. capability "Switch Level"
  138. capability "Configuration"
  139. capability "Energy Meter"
  140. capability "Power Meter"
  141. capability "ChangeLevel"
  142.  
  143.  
  144. attribute "lastActivity", "String"
  145. attribute "lastEvent", "String"
  146. attribute "firmware", "String"
  147. attribute "firmware0", "String"
  148. attribute "firmware1", "String"
  149. attribute "groups", "Number"
  150.  
  151. // Uncomment these lines if you would like to test your scenes with digital button presses.
  152. /*
  153. command "pressUpX1"
  154. command "pressDownX1"
  155. command "pressUpX2"
  156. command "pressDownX2"
  157. command "pressUpX3"
  158. command "pressDownX3"
  159. command "pressUpX4"
  160. command "pressDownX4"
  161. command "pressUpX5"
  162. command "pressDownX5"
  163. command "holdUp"
  164. command "holdDown"
  165. command "releaseUp"
  166. command "releaseDown"
  167. command "pressConfig"
  168. */
  169.  
  170. command "calibratePower", [[name: "Watts",type:"NUMBER", description: "Calibrate power readings with the sum of the W of the attached blubs."],
  171. [name: "Volts",type:"NUMBER", description: "Measured volts. Typically 110v-120v in US."]]
  172.  
  173. command "childOn", ["string"]
  174. command "childOff", ["string"]
  175. command "childSetLevel", ["string"]
  176. command "childRefresh", ["string"]
  177. command "componentOn"
  178. command "componentOff"
  179. command "componentSetLevel"
  180. command "componentRefresh"
  181. command "componentSetColor"
  182. command "componentSetColorTemperature"
  183. command "setIndicator", [[name: "Set Indicator*",type:"NUMBER", description: "For configuration values see: https://nathanfiscus.github.io/inovelli-notification-calc/"]]
  184.  
  185. command "reset"
  186.  
  187. command "startNotification", [[name: "Start Notification*",type:"NUMBER", description: "For configuration values see: https://nathanfiscus.github.io/inovelli-notification-calc/"],
  188. [name: "Endpoint",type:"NUMBER", description: "Optional. Only used on devices with multiple indicator bars."]]
  189. command "stopNotification", [[name: "Endpoint",type:"NUMBER", description: "Optional. Only used on devices with multiple indicator bars."]]
  190. command "setAssociationGroup", [[name: "Group Number*",type:"NUMBER", description: "Provide the association group number to edit"],
  191. [name: "Z-Wave Node*", type:"STRING", description: "Enter the node number (in hex) associated with the node"],
  192. [name: "Action*", type:"ENUM", constraints: ["Add", "Remove"]],
  193. [name:"Multi-channel Endpoint", type:"NUMBER", description: "Currently not implemented"]]
  194.  
  195. command "setConfigParameter", [[name: "Number*",type:"NUMBER", description: "Provide the parameter number to edit"],
  196. [name: "Value*", type:"NUMBER", description: "Enter the value you would like to set the parameter to"],
  197. [name: "Size*", type:"ENUM", constraints: ["1", "2", "4"]]]
  198.  
  199. fingerprint mfr: "031E", prod: "0001", deviceId: "0001", inClusters:"0x5E,0x26,0x70,0x85,0x59,0x55,0x86,0x72,0x5A,0x73,0x32,0x98,0x9F,0x5B,0x6C,0x75,0x22,0x7A"
  200. }
  201.  
  202. simulator {
  203. }
  204.  
  205. preferences {
  206. generate_preferences()
  207. }
  208.  
  209. }
  210.  
  211. private hex(value, width=2) {
  212. def s = new BigInteger(Math.round(value).toString()).toString(16)
  213. while (s.size() < width) {
  214. s = "0" + s
  215. }
  216. s
  217. }
  218.  
  219. def calibratePower(watts, volts = 110) {
  220. def wattage = hex(watts,4).toUpperCase()
  221. def voltage = hex(volts,4).toUpperCase()
  222. def cmds = []
  223. cmds << "70FEFEFD01${wattage}${voltage}"
  224. // "70FEFEFD0455011400770199005A"
  225. cmds << "delay 5000"
  226. cmds << "70FEFEFD03"
  227. //70 FE FE FD 03 with a reply that was short one byte. I received, FE FD 04 55 00 00 00 00 3B 00 55 and FE FD 04 55 00 00 00 00 3B 00 54. After the recalibration, issuing the 70 FE FE FD 03 returned the result: FE FD 04 55 01 BE 00 85 02 9B 02 9A.
  228. log.debug cmds
  229. //FE FD 04 55 01 14 00 77 01 99 00 5A
  230. //FE FD 04 FF 01 92 00 78
  231. return cmds
  232. }
  233.  
  234. def generate_preferences()
  235. {
  236. getParameterNumbers().each { i ->
  237.  
  238. switch(getParameterInfo(i, "type"))
  239. {
  240. case "number":
  241. input "parameter${i}", "number",
  242. title:"${i}. " + getParameterInfo(i, "name") + "\n" + getParameterInfo(i, "description") + "\nRange: " + getParameterInfo(i, "options") + "\nDefault: " + getParameterInfo(i, "default"),
  243. range: getParameterInfo(i, "options")
  244. //defaultValue: getParameterInfo(i, "default")
  245. //displayDuringSetup: "${it.@displayDuringSetup}"
  246. break
  247. case "enum":
  248. input "parameter${i}", "enum",
  249. title:"${i}. " + getParameterInfo(i, "name"), // + getParameterInfo(i, "description"),
  250. //defaultValue: getParameterInfo(i, "default"),
  251. //displayDuringSetup: "${it.@displayDuringSetup}",
  252. options: getParameterInfo(i, "options")
  253. break
  254. }
  255. if (i == 13){
  256. input "parameter13custom", "number",
  257. title: "Custom LED RGB Value",
  258. description: "\nInput a custom value in this field to override the above setting. The value should be between 0 - 360 and can be determined by using the typical hue color wheel.",
  259. required: false,
  260. range: "0..360"
  261. }
  262. }
  263.  
  264. input description: "When each notification set (Color, Level, Duration, Type) is configured, a switch child device is created that can be used in SmartApps to activate that notification.", title: "LED Notifications", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  265.  
  266. [1,2,3,4,5].each { i ->
  267. input "parameter16-${i}a", "enum", title: "LED Effect Color - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [
  268. 0:"Red",
  269. 21:"Orange",
  270. 42:"Yellow",
  271. 85:"Green",
  272. 127:"Cyan",
  273. 170:"Blue",
  274. 212:"Violet",
  275. 234:"Pink",
  276. 255:"White"]
  277. input "parameter16-${i}b", "enum", title: "LED Effect Level - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [
  278. 0:"0%",
  279. 1:"10%",
  280. 2:"20%",
  281. 3:"30%",
  282. 4:"40%",
  283. 5:"50%",
  284. 6:"60%",
  285. 7:"70%",
  286. 8:"80%",
  287. 9:"90%",
  288. 10:"100%"]
  289. input "parameter16-${i}c", "enum", title: "LED Effect Duration - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [
  290. 255:"Indefinitely",
  291. 1:"1 Second",
  292. 2:"2 Seconds",
  293. 3:"3 Seconds",
  294. 4:"4 Seconds",
  295. 5:"5 Seconds",
  296. 6:"6 Seconds",
  297. 7:"7 Seconds",
  298. 8:"8 Seconds",
  299. 9:"9 Seconds",
  300. 10:"10 Seconds",
  301. 11:"11 Seconds",
  302. 12:"12 Seconds",
  303. 13:"13 Seconds",
  304. 14:"14 Seconds",
  305. 15:"15 Seconds",
  306. 16:"16 Seconds",
  307. 17:"17 Seconds",
  308. 18:"18 Seconds",
  309. 19:"19 Seconds",
  310. 20:"20 Seconds",
  311. 21:"21 Seconds",
  312. 22:"22 Seconds",
  313. 23:"23 Seconds",
  314. 24:"24 Seconds",
  315. 25:"25 Seconds",
  316. 26:"26 Seconds",
  317. 27:"27 Seconds",
  318. 28:"28 Seconds",
  319. 29:"29 Seconds",
  320. 30:"30 Seconds",
  321. 31:"31 Seconds",
  322. 32:"32 Seconds",
  323. 33:"33 Seconds",
  324. 34:"34 Seconds",
  325. 35:"35 Seconds",
  326. 36:"36 Seconds",
  327. 37:"37 Seconds",
  328. 38:"38 Seconds",
  329. 39:"39 Seconds",
  330. 40:"40 Seconds",
  331. 41:"41 Seconds",
  332. 42:"42 Seconds",
  333. 43:"43 Seconds",
  334. 44:"44 Seconds",
  335. 45:"45 Seconds",
  336. 46:"46 Seconds",
  337. 47:"47 Seconds",
  338. 48:"48 Seconds",
  339. 49:"49 Seconds",
  340. 50:"50 Seconds",
  341. 51:"51 Seconds",
  342. 52:"52 Seconds",
  343. 53:"53 Seconds",
  344. 54:"54 Seconds",
  345. 55:"55 Seconds",
  346. 56:"56 Seconds",
  347. 57:"57 Seconds",
  348. 58:"58 Seconds",
  349. 59:"59 Seconds",
  350. 61:"1 Minute",
  351. 62:"2 Minutes",
  352. 63:"3 Minutes",
  353. 64:"4 Minutes",
  354. 65:"5 Minutes",
  355. 66:"6 Minutes",
  356. 67:"7 Minutes",
  357. 68:"8 Minutes",
  358. 69:"9 Minutes",
  359. 70:"10 Minutes",
  360. 71:"11 Minutes",
  361. 72:"12 Minutes",
  362. 73:"13 Minutes",
  363. 74:"14 Minutes",
  364. 75:"15 Minutes",
  365. 76:"16 Minutes",
  366. 77:"17 Minutes",
  367. 78:"18 Minutes",
  368. 79:"19 Minutes",
  369. 80:"20 Minutes",
  370. 81:"21 Minutes",
  371. 82:"22 Minutes",
  372. 83:"23 Minutes",
  373. 84:"24 Minutes",
  374. 85:"25 Minutes",
  375. 86:"26 Minutes",
  376. 87:"27 Minutes",
  377. 88:"28 Minutes",
  378. 89:"29 Minutes",
  379. 90:"30 Minutes",
  380. 91:"31 Minutes",
  381. 92:"32 Minutes",
  382. 93:"33 Minutes",
  383. 94:"34 Minutes",
  384. 95:"35 Minutes",
  385. 96:"36 Minutes",
  386. 97:"37 Minutes",
  387. 98:"38 Minutes",
  388. 99:"39 Minutes",
  389. 100:"40 Minutes",
  390. 101:"41 Minutes",
  391. 102:"42 Minutes",
  392. 103:"43 Minutes",
  393. 104:"44 Minutes",
  394. 105:"45 Minutes",
  395. 106:"46 Minutes",
  396. 107:"47 Minutes",
  397. 108:"48 Minutes",
  398. 109:"49 Minutes",
  399. 110:"50 Minutes",
  400. 111:"51 Minutes",
  401. 112:"52 Minutes",
  402. 113:"53 Minutes",
  403. 114:"54 Minutes",
  404. 115:"55 Minutes",
  405. 116:"56 Minutes",
  406. 117:"57 Minutes",
  407. 118:"58 Minutes",
  408. 119:"59 Minutes",
  409. 121:"1 Hour",
  410. 122:"2 Hours",
  411. 123:"3 Hours",
  412. 124:"4 Hours",
  413. 125:"5 Hours",
  414. 126:"6 Hours",
  415. 127:"7 Hours",
  416. 128:"8 Hours",
  417. 129:"9 Hours",
  418. 130:"10 Hours",
  419. 131:"11 Hours",
  420. 132:"12 Hours",
  421. 133:"13 Hours",
  422. 134:"14 Hours",
  423. 135:"15 Hours",
  424. 136:"16 Hours",
  425. 137:"17 Hours",
  426. 138:"18 Hours",
  427. 139:"19 Hours",
  428. 140:"20 Hours",
  429. 141:"21 Hours",
  430. 142:"22 Hours",
  431. 143:"23 Hours",
  432. 144:"24 Hours",
  433. 145:"25 Hours",
  434. 146:"26 Hours",
  435. 147:"27 Hours",
  436. 148:"28 Hours",
  437. 149:"29 Hours",
  438. 150:"30 Hours",
  439. 151:"31 Hours",
  440. 152:"32 Hours",
  441. 153:"33 Hours",
  442. 154:"34 Hours",
  443. 155:"35 Hours",
  444. 156:"36 Hours",
  445. 157:"37 Hours",
  446. 158:"38 Hours",
  447. 159:"39 Hours",
  448. 160:"40 Hours",
  449. 161:"41 Hours",
  450. 162:"42 Hours",
  451. 163:"43 Hours",
  452. 164:"44 Hours",
  453. 165:"45 Hours",
  454. 166:"46 Hours",
  455. 167:"47 Hours",
  456. 168:"48 Hours",
  457. 169:"49 Hours",
  458. 170:"50 Hours",
  459. 171:"51 Hours",
  460. 172:"52 Hours",
  461. 173:"53 Hours",
  462. 174:"54 Hours",
  463. 175:"55 Hours",
  464. 176:"56 Hours",
  465. 177:"57 Hours",
  466. 178:"58 Hours",
  467. 179:"59 Hours",
  468. 180:"60 Hours",
  469. 181:"61 Hours",
  470. 182:"62 Hours",
  471. 183:"63 Hours",
  472. 184:"64 Hours",
  473. 185:"65 Hours",
  474. 186:"66 Hours",
  475. 187:"67 Hours",
  476. 188:"68 Hours",
  477. 189:"69 Hours",
  478. 190:"70 Hours",
  479. 191:"71 Hours",
  480. 192:"72 Hours",
  481. 193:"73 Hours",
  482. 194:"74 Hours",
  483. 195:"75 Hours",
  484. 196:"76 Hours",
  485. 197:"77 Hours",
  486. 198:"78 Hours",
  487. 199:"79 Hours",
  488. 200:"80 Hours",
  489. 201:"81 Hours",
  490. 202:"82 Hours",
  491. 203:"83 Hours",
  492. 204:"84 Hours",
  493. 205:"85 Hours",
  494. 206:"86 Hours",
  495. 207:"87 Hours",
  496. 208:"88 Hours",
  497. 209:"89 Hours",
  498. 210:"90 Hours",
  499. 211:"91 Hours",
  500. 212:"92 Hours",
  501. 213:"93 Hours",
  502. 214:"94 Hours",
  503. 215:"95 Hours",
  504. 216:"96 Hours",
  505. 217:"97 Hours",
  506. 218:"98 Hours",
  507. 219:"99 Hours",
  508. 220:"100 Hours",
  509. 221:"101 Hours",
  510. 222:"102 Hours",
  511. 223:"103 Hours",
  512. 224:"104 Hours",
  513. 225:"105 Hours",
  514. 226:"106 Hours",
  515. 227:"107 Hours",
  516. 228:"108 Hours",
  517. 229:"109 Hours",
  518. 230:"110 Hours",
  519. 231:"111 Hours",
  520. 232:"112 Hours",
  521. 233:"113 Hours",
  522. 234:"114 Hours",
  523. 235:"115 Hours",
  524. 236:"116 Hours",
  525. 237:"117 Hours",
  526. 238:"118 Hours",
  527. 239:"119 Hours",
  528. 240:"120 Hours",
  529. 241:"121 Hours",
  530. 242:"122 Hours",
  531. 243:"123 Hours",
  532. 244:"124 Hours",
  533. 245:"125 Hours",
  534. 246:"126 Hours",
  535. 247:"127 Hours",
  536. 248:"128 Hours",
  537. 249:"129 Hours",
  538. 250:"130 Hours",
  539. 251:"131 Hours",
  540. 252:"132 Hours",
  541. 253:"133 Hours",
  542. 254:"134 Hours"]
  543. input "parameter16-${i}d", "enum", title: "LED Effect Type - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [
  544. 0:"Off",
  545. 1:"Solid",
  546. 2:"Chase",
  547. 3:"Fast Blink",
  548. 4:"Slow Blink",
  549. 5:"Pulse"]
  550.  
  551. }
  552. input "disableLocal", "enum", title: "Disable Local Control", description: "\nDisable ability to control switch from the wall", required: false, options:[["1": "Yes"], ["0": "No"]], defaultValue: "0"
  553. input "disableRemote", "enum", title: "Disable Remote Control", description: "\nDisable ability to control switch from inside Hubitat", required: false, options:[["1": "Yes"], ["0": "No"]], defaultValue: "0"
  554. input description: "Use the below options to enable child devices for the specified settings. This will allow you to adjust these settings using Apps such as Rule Machine.", title: "Child Devices", displayDuringSetup: false, type: "paragraph", element: "paragraph"
  555. input "enableLEDChild", "bool", title: "Create \"LED Color\" Child Device", description: "", required: false, defaultValue: true
  556. input "enableLED1OffChild", "bool", title: "Create \"LED When Off\" Child Device", description: "", required: false, defaultValue: false
  557. input "enableDisableLocalChild", "bool", title: "Create \"Disable Local Control\" Child Device", description: "", required: false, defaultValue: false
  558. input "enableDisableRemoteChild", "bool", title: "Create \"Disable Remote Control\" Child Device", description: "", required: false, defaultValue: false
  559. input "enableDefaultLocalChild", "bool", title: "Create \"Default Level (Local)\" Child Device", description: "", required: false, defaultValue: false
  560. input "enableDefaultZWaveChild", "bool", title: "Create \"Default Level (Z-Wave)\" Child Device", description: "", required: false, defaultValue: false
  561. input name: "debugEnable", type: "bool", title: "Enable Debug Logging", defaultValue: true
  562. input name: "infoEnable", type: "bool", title: "Enable Informational Logging", defaultValue: true
  563. input name: "disableDebugLogging", type: "number", title: "Disable Debug Logging", description: "Disable debug logging after this number of minutes (0=Do not disable)", defaultValue: 0
  564. input name: "disableInfoLogging", type: "number", title: "Disable Info Logging", description: "Disable info logging after this number of minutes (0=Do not disable)", defaultValue: 30
  565. }
  566.  
  567. private channelNumber(String dni) {
  568. dni.split("-ep")[-1] as Integer
  569. }
  570.  
  571. def debugLogsOff(){
  572. log.warn "${device.label?device.label:device.name}: Disabling debug logging after timeout"
  573. device.updateSetting("debugEnable",[value:"false",type:"bool"])
  574. }
  575.  
  576. def infoLogsOff(){
  577. log.warn "${device.label?device.label:device.name}: Disabling info logging after timeout"
  578. device.updateSetting("infoEnable",[value:"false",type:"bool"])
  579. }
  580.  
  581. private sendAlert(data) {
  582. if (infoEnable) log.info "${device.label?device.label:device.name}: Error while creating child device"
  583. sendEvent(
  584. descriptionText: data.message,
  585. eventType: "ALERT",
  586. name: "failedOperation",
  587. value: "failed",
  588. displayed: true,
  589. )
  590. }
  591.  
  592. private toggleTiles(number, value) {
  593. for (int i = 1; i <= 5; i++){
  594. if ("${i}" != number){
  595. def childDevice = childDevices.find{it.deviceNetworkId == "$device.deviceNetworkId-ep$i"}
  596. if (childDevice) {
  597. childDevice.sendEvent(name: "switch", value: "off")
  598. }
  599. } else {
  600. def childDevice = childDevices.find{it.deviceNetworkId == "$device.deviceNetworkId-ep$i"}
  601. if (childDevice) {
  602. childDevice.sendEvent(name: "switch", value: value)
  603. }
  604. }
  605. }
  606. }
  607.  
  608. def setIndicator(value){
  609. if (infoEnable) log.info "${device.label?device.label:device.name}: setIndicator($value)"
  610. return startNotification(value)
  611. }
  612.  
  613. def startNotification(value, ep = null){
  614. if (infoEnable) log.info "${device.label?device.label:device.name}: startNotification($value)"
  615. def parameterNumbers = [16]
  616. def cmds = []
  617. cmds << zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(value.toInteger(),4), parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1], size: 4)
  618. cmds << zwave.configurationV1.configurationGet(parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1])
  619. return commands(cmds)
  620. }
  621.  
  622. def stopNotification(ep = null){
  623. if (infoEnable) log.info "${device.label?device.label:device.name}: stopNotification()"
  624. def parameterNumbers = [16]
  625. def cmds = []
  626. cmds << zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(0,4), parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1], size: 4)
  627. cmds << zwave.configurationV1.configurationGet(parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1])
  628. return commands(cmds)
  629. }
  630.  
  631. def componentSetColor(cd,value) {
  632. if (infoEnable) log.info "${device.label?device.label:device.name}: componentSetColor($value)"
  633. if (value.hue == null || value.saturation == null) return
  634. def ledColor = Math.round(huePercentToZwaveValue(value.hue))
  635. if (infoEnable) log.info "${device.label?device.label:device.name}: Setting LED color value to $ledColor & LED intensity to $ledLevel"
  636. def cmds = []
  637. if (value.level != null) {
  638. def ledLevel = Math.round(value.level/10)
  639. cmds << setParameter(14, ledLevel, 1)
  640. cmds << getParameter(14)
  641. }
  642. cmds << setParameter(13, ledColor, 2)
  643. cmds << getParameter(13)
  644. return commands(cmds)
  645. }
  646.  
  647. def componentSetColorTemperature(cd, value, level = null, duration = null) {
  648. if (infoEnable != "false") log.info "${device.label?device.label:device.name}: cd, componentSetColorTemperature($value)"
  649. if (infoEnable) log.info "${device.label?device.label:device.name}: Setting LED color value to 255"
  650. state.colorTemperature = value
  651. def cmds = []
  652. if (level != null) {
  653. def ledLevel = Math.round(level/10)
  654. cmds << setParameter(14, ledLevel, 1)
  655. cmds << getParameter(14)
  656. }
  657. cmds << setParameter(13, 255, 2)
  658. cmds << getParameter(13)
  659. if(cmds) commands(cmds)
  660. }
  661.  
  662. private huePercentToValue(value){
  663. return value<=2?0:(value>=98?360:value/100*360)
  664. }
  665.  
  666. private hueValueToZwaveValue(value){
  667. return value<=2?0:(value>=356?255:value/360*255)
  668. }
  669.  
  670. private huePercentToZwaveValue(value){
  671. return value<=2?0:(value>=98?254:value/100*255)
  672. }
  673.  
  674. private zwaveValueToHueValue(value){
  675. return value<=2?0:(value>=254?360:value/255*360)
  676. }
  677.  
  678. private zwaveValueToHuePercent(value){
  679. return value<=2?0:(value>=254?100:value/255*100)
  680. }
  681.  
  682. def startLevelChange(direction) {
  683. def upDownVal = direction == "down" ? true : false
  684. if (infoEnable) log.debug "${device.label?device.label:device.name}: startLevelChange(${direction})"
  685. commands([zwave.switchMultilevelV3.switchMultilevelStartLevelChange(ignoreStartLevel: true, startLevel: device.currentValue("level"), upDown: upDownVal, incDec: 1, stepSize: 1, dimmingDuration: settings."parameter1"!=null? settings."parameter1":3)])
  686. }
  687.  
  688. def stopLevelChange() {
  689. if (infoEnable) log.debug "${device.label?device.label:device.name}: stopLevelChange()"
  690. commands([zwave.switchMultilevelV2.switchMultilevelStopLevelChange()])
  691. }
  692.  
  693. def childSetLevel(String dni, value) {
  694. if (infoEnable) log.info "${device.label?device.label:device.name}: childSetLevel($dni, $value)"
  695. state.lastRan = now()
  696. def valueaux = value as Integer
  697. def level = Math.max(Math.min(valueaux, 99), 0)
  698. def cmds = []
  699. switch (channelNumber(dni)) {
  700. case 9:
  701. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1)
  702. cmds << zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni))
  703. break
  704. case 10:
  705. cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1)
  706. cmds << zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni))
  707. break
  708. case 101:
  709. cmds << zwave.protectionV2.protectionSet(localProtectionState : level > 0 ? 1 : 0, rfProtectionState: state.rfProtectionState? state.rfProtectionState:0)
  710. cmds << zwave.protectionV2.protectionGet()
  711. break
  712. case 102:
  713. cmds << zwave.protectionV2.protectionSet(localProtectionState : state.localProtectionState? state.localProtectionState:0, rfProtectionState : level > 0 ? 1 : 0)
  714. cmds << zwave.protectionV2.protectionGet()
  715. break
  716. case 103:
  717. cmds << setParameter(14, Math.round(level/10), 1)
  718. cmds << getParameter(14)
  719. break
  720. case 104:
  721. cmds << setParameter(15, Math.round(level/10), 1)
  722. cmds << getParameter(15)
  723. break
  724. }
  725. return commands(cmds)
  726. }
  727.  
  728. def childOn(String dni) {
  729. if (infoEnable) log.info "${device.label?device.label:device.name}: childOn($dni)"
  730. state.lastRan = now()
  731. def cmds = []
  732. if(channelNumber(dni).toInteger() <= 5) {
  733. toggleTiles("${channelNumber(dni)}", "on")
  734. cmds << new hubitat.device.HubAction(command(setParameter(16, calculateParameter("16-${channelNumber(dni)}"), 4)), hubitat.device.Protocol.ZWAVE )
  735. return cmds
  736. } else {
  737. childSetLevel(dni, 99)
  738. }
  739. }
  740.  
  741. def childOff(String dni) {
  742. if (infoEnable) log.info "${device.label?device.label:device.name}: childOff($dni)"
  743. state.lastRan = now()
  744. def cmds = []
  745. if(channelNumber(dni).toInteger() <= 5) {
  746. toggleTiles("${channelNumber(dni)}", "off")
  747. cmds << new hubitat.device.HubAction(command(setParameter(16, 0, 4)), hubitat.device.Protocol.ZWAVE )
  748. return cmds
  749. } else {
  750. childSetLevel(dni, 0)
  751. }
  752. }
  753.  
  754. void childRefresh(String dni) {
  755. if (infoEnable) log.info "${device.label?device.label:device.name}: childRefresh($dni)"
  756. }
  757.  
  758. def componentSetLevel(cd,level,transitionTime = null) {
  759. if (infoEnable) log.info "${device.label?device.label:device.name}: componentSetLevel($cd, $value)"
  760. return childSetLevel(cd.deviceNetworkId,level)
  761. }
  762.  
  763. def componentOn(cd) {
  764. if (infoEnable) log.info "${device.label?device.label:device.name}: componentOn($cd)"
  765. return childOn(cd.deviceNetworkId)
  766. }
  767.  
  768. def componentOff(cd) {
  769. if (infoEnable) log.info "${device.label?device.label:device.name}: componentOff($cd)"
  770. return childOff(cd.deviceNetworkId)
  771. }
  772.  
  773. void componentRefresh(cd) {
  774. if (infoEnable) log.info "${device.label?device.label:device.name}: componentRefresh($cd)"
  775. }
  776.  
  777. def childExists(ep) {
  778. def children = childDevices
  779. def childDevice = children.find{it.deviceNetworkId.endsWith(ep)}
  780. if (childDevice)
  781. return true
  782. else
  783. return false
  784. }
  785.  
  786. def installed() {
  787. if (infoEnable) log.info "${device.label?device.label:device.name}: installed()"
  788. refresh()
  789. }
  790.  
  791. def configure() {
  792. if (infoEnable) log.info "${device.label?device.label:device.name}: configure()"
  793. def cmds = initialize()
  794. commands(cmds)
  795. }
  796.  
  797. def updated() {
  798. if (!state.lastRan || now() >= state.lastRan + 2000) {
  799. if (infoEnable) log.info "${device.label?device.label:device.name}: updated()"
  800. if (debugEnable && disableDebugLogging) runIn(disableDebugLogging*60,debugLogsOff)
  801. if (infoEnable && disableInfoLogging) runIn(disableInfoLogging*60,infoLogsOff)
  802. state.lastRan = now()
  803. def cmds = initialize()
  804. if (cmds != [])
  805. commands(cmds, 1000)
  806. else
  807. return null
  808. } else {
  809. if (infoEnable) log.info "${device.label?device.label:device.name}: updated() ran within the last 2 seconds. Skipping execution."
  810. }
  811. }
  812.  
  813. private addChild(id, label, namespace, driver, isComponent){
  814. if(!childExists(id)){
  815. try {
  816. def newChild = addChildDevice(namespace, driver, "${device.deviceNetworkId}-${id}",
  817. [completedSetup: true, label: "${device.displayName} (${label})",
  818. isComponent: isComponent, componentName: id, componentLabel: label])
  819. newChild.sendEvent(name:"switch", value:"off")
  820. } catch (e) {
  821. runIn(3, "sendAlert", [data: [message: "Child device creation failed. Make sure the driver for \"${driver}\" with a namespace of ${namespace} is installed"]])
  822. }
  823. }
  824. }
  825.  
  826. private deleteChild(id){
  827. if(childExists(id)){
  828. def childDevice = childDevices.find{it.deviceNetworkId.endsWith(id)}
  829. try {
  830. if(childDevice) deleteChildDevice(childDevice.deviceNetworkId)
  831. } catch (e) {
  832. if (infoEnable) log.info "Hubitat may have issues trying to delete the child device when it is in use. Need to manually delete them."
  833. runIn(3, "sendAlert", [data: [message: "Failed to delete child device. Make sure the device is not in use by any App."]])
  834. }
  835. }
  836. }
  837.  
  838. def initialize() {
  839. sendEvent(name: "numberOfButtons", value: 8, displayed: true)
  840.  
  841. if (enableDefaultLocalChild) addChild("ep9", "Default Local Level", "hubitat", "Generic Component Dimmer", false)
  842. else deleteChild("ep9")
  843. if (enableDefaultZWaveChild) addChild("ep10", "Default Z-Wave Level", "hubitat", "Generic Component Dimmer", false)
  844. else deleteChild("ep10")
  845. if (enableDisableLocalChild) addChild("ep101", "Disable Local Control", "hubitat", "Generic Component Switch", false)
  846. else deleteChild("ep101")
  847. if (enableDisableRemoteChild) addChild("ep102", "Disable Remote Control", "hubitat", "Generic Component Switch", false)
  848. else deleteChild("ep102")
  849. if (enableLEDChild) addChild("ep103", "LED Color", "hubitat", "Generic Component RGBW", false)
  850. else deleteChild("ep103")
  851. if (enableLED1OffChild) addChild("ep104", "LED - When Off", "hubitat", "Generic Component Dimmer", false)
  852. else deleteChild("ep104")
  853.  
  854. [1,2,3,4,5].each { i ->
  855. if ((settings."parameter16-${i}a"!=null && settings."parameter16-${i}b"!=null && settings."parameter16-${i}c"!=null && settings."parameter16-${i}d"!=null && settings."parameter16-${i}d"!="0") && !childExists("ep${i}")) {
  856. addChild("ep${i}", "Notification ${i}", "hubitat", "Generic Component Switch", false)
  857. } else if ((settings."parameter16-${i}a"==null || settings."parameter16-${i}b"==null || settings."parameter16-${i}c"==null || settings."parameter16-${i}d"==null || settings."parameter16-${i}d"=="0") && childExists("ep${i}")) {
  858. deleteChild("ep${i}")
  859. }
  860. }
  861.  
  862. if (device.label != state.oldLabel) {
  863. def children = childDevices
  864. def childDevice = children.find{it.deviceNetworkId.endsWith("ep1")}
  865. if (childDevice)
  866. childDevice.setLabel("${device.displayName} (Notification 1)")
  867. childDevice = children.find{it.deviceNetworkId.endsWith("ep2")}
  868. if (childDevice)
  869. childDevice.setLabel("${device.displayName} (Notification 2)")
  870. childDevice = children.find{it.deviceNetworkId.endsWith("ep3")}
  871. if (childDevice)
  872. childDevice.setLabel("${device.displayName} (Notification 3)")
  873. childDevice = children.find{it.deviceNetworkId.endsWith("ep4")}
  874. if (childDevice)
  875. childDevice.setLabel("${device.displayName} (Notification 4)")
  876. childDevice = children.find{it.deviceNetworkId.endsWith("ep5")}
  877. if (childDevice)
  878. childDevice.setLabel("${device.displayName} (Notification 5)")
  879. childDevice = children.find{it.deviceNetworkId.endsWith("ep9")}
  880. if (childDevice)
  881. childDevice.setLabel("${device.displayName} (Default Local Level)")
  882. childDevice = children.find{it.deviceNetworkId.endsWith("ep10")}
  883. if (childDevice)
  884. childDevice.setLabel("${device.displayName} (Default Z-Wave Level)")
  885. childDevice = children.find{it.deviceNetworkId.endsWith("ep101")}
  886. if (childDevice)
  887. childDevice.setLabel("${device.displayName} (Disable Local Control)")
  888. childDevice = children.find{it.deviceNetworkId.endsWith("ep102")}
  889. if (childDevice)
  890. childDevice.setLabel("${device.displayName} (Disable Remote Control)")
  891. }
  892. state.oldLabel = device.label
  893.  
  894. def cmds = processAssociations()
  895.  
  896. getParameterNumbers().each{ i ->
  897. if ((state."parameter${i}value" != ((settings."parameter${i}"!=null||calculateParameter(i)!=null)? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger()))){
  898. //if (infoEnable) log.info "Parameter $i is not set correctly. Setting it to ${settings."parameter${i}"!=null? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger()}."
  899. cmds << setParameter(i, (settings."parameter${i}"!=null||calculateParameter(i)!=null)? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger(), getParameterInfo(i, "size").toInteger())
  900. cmds << getParameter(i)
  901. }
  902. else {
  903. //if (infoEnable) log.info "${device.label?device.label:device.name}: Parameter $i already set"
  904. }
  905. }
  906.  
  907. cmds << zwave.versionV1.versionGet()
  908.  
  909. if (state.localProtectionState?.toInteger() != settings.disableLocal?.toInteger() || state.rfProtectionState?.toInteger() != settings.disableRemote?.toInteger()) {
  910. if (infoEnable) log.info "${device.label?device.label:device.name}: Protection command class settings need to be updated"
  911. cmds << zwave.protectionV2.protectionSet(localProtectionState : disableLocal!=null? disableLocal.toInteger() : 0, rfProtectionState: disableRemote!=null? disableRemote.toInteger() : 0)
  912. cmds << zwave.protectionV2.protectionGet()
  913. } else {
  914. if (infoEnable) log.info "${device.label?device.label:device.name}: No Protection command class settings to update"
  915. }
  916.  
  917. if (cmds != []) return cmds else return []
  918. }
  919.  
  920. def calculateParameter(number) {
  921. def value = 0
  922. switch (number){
  923. case "13":
  924. if (settings.parameter13) value = settings."parameter${number}"
  925. else if (settings.parameter13custom =~ /^([0-9]{1}|[0-9]{2}|[0-9]{3})$/) value = hueValueToZwaveValue(settings.parameter13custom.toInteger())
  926. else value = settings."parameter${number}"
  927. break
  928. case "16-1":
  929. case "16-2":
  930. case "16-3":
  931. case "16-4":
  932. case "16-5":
  933. value += settings."parameter${number}a"!=null ? settings."parameter${number}a".toInteger() * 1 : 0
  934. value += settings."parameter${number}b"!=null ? settings."parameter${number}b".toInteger() * 256 : 0
  935. value += settings."parameter${number}c"!=null ? settings."parameter${number}c".toInteger() * 65536 : 0
  936. value += settings."parameter${number}d"!=null ? settings."parameter${number}d".toInteger() * 16777216 : 0
  937. break
  938. default:
  939. value = settings."parameter${number}"
  940. break
  941. }
  942. return value
  943. }
  944.  
  945. def setConfigParameter(number, value, size) {
  946. return command(setParameter(number, value, size.toInteger()))
  947. }
  948.  
  949. def setParameter(number, value, size) {
  950. if (infoEnable) log.info "${device.label?device.label:device.name}: Setting parameter $number with a size of $size bytes to $value"
  951. return zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(value.toInteger(),size), parameterNumber: number, size: size)
  952. }
  953.  
  954. def getParameter(number) {
  955. if (infoEnable) log.info "${device.label?device.label:device.name}: Retreiving value of parameter $number"
  956. return zwave.configurationV1.configurationGet(parameterNumber: number)
  957. }
  958.  
  959. def getParameterNumbers(){
  960. return [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,50,51,52]
  961. }
  962.  
  963. def getParameterInfo(number, value){
  964. def parameter = [:]
  965.  
  966. parameter.parameter1default=3
  967. parameter.parameter2default=101
  968. parameter.parameter3default=101
  969. parameter.parameter4default=101
  970. parameter.parameter5default=1
  971. parameter.parameter6default=99
  972. parameter.parameter7default=0
  973. parameter.parameter8default=0
  974. parameter.parameter9default=0
  975. parameter.parameter10default=0
  976. parameter.parameter11default=0
  977. parameter.parameter12default=15
  978. parameter.parameter13default=170
  979. parameter.parameter14default=5
  980. parameter.parameter15default=1
  981. parameter.parameter16default=0
  982. parameter.parameter17default=3
  983. parameter.parameter18default=10
  984. parameter.parameter19default=3600
  985. parameter.parameter20default=10
  986. parameter.parameter21default=1
  987. parameter.parameter22default=0
  988. parameter.parameter50default=5
  989. parameter.parameter51default=1
  990. parameter.parameter52default=0
  991.  
  992. parameter.parameter1type="number"
  993. parameter.parameter2type="number"
  994. parameter.parameter3type="number"
  995. parameter.parameter4type="number"
  996. parameter.parameter5type="number"
  997. parameter.parameter6type="number"
  998. parameter.parameter7type="enum"
  999. parameter.parameter8type="number"
  1000. parameter.parameter9type="number"
  1001. parameter.parameter10type="number"
  1002. parameter.parameter11type="number"
  1003. parameter.parameter12type="number"
  1004. parameter.parameter13type="enum"
  1005. parameter.parameter14type="enum"
  1006. parameter.parameter15type="enum"
  1007. parameter.parameter16type="enum"
  1008. parameter.parameter17type="enum"
  1009. parameter.parameter18type="number"
  1010. parameter.parameter19type="number"
  1011. parameter.parameter20type="number"
  1012. parameter.parameter21type="enum"
  1013. parameter.parameter22type="enum"
  1014. parameter.parameter50type="enum"
  1015. parameter.parameter51type="enum"
  1016. parameter.parameter52type="enum"
  1017.  
  1018. parameter.parameter1size=1
  1019. parameter.parameter2size=1
  1020. parameter.parameter3size=1
  1021. parameter.parameter4size=1
  1022. parameter.parameter5size=1
  1023. parameter.parameter6size=1
  1024. parameter.parameter7size=1
  1025. parameter.parameter8size=2
  1026. parameter.parameter9size=1
  1027. parameter.parameter10size=1
  1028. parameter.parameter11size=1
  1029. parameter.parameter12size=1
  1030. parameter.parameter13size=2
  1031. parameter.parameter14size=1
  1032. parameter.parameter15size=1
  1033. parameter.parameter16size=4
  1034. parameter.parameter17size=1
  1035. parameter.parameter18size=1
  1036. parameter.parameter19size=2
  1037. parameter.parameter20size=1
  1038. parameter.parameter21size=1
  1039. parameter.parameter22size=1
  1040. parameter.parameter50size=1
  1041. parameter.parameter51size=1
  1042. parameter.parameter52size=1
  1043.  
  1044. parameter.parameter1options="0..100"
  1045. parameter.parameter2options="0..101"
  1046. parameter.parameter3options="0..101"
  1047. parameter.parameter4options="0..101"
  1048. parameter.parameter5options="1..98"
  1049. parameter.parameter6options="2..99"
  1050. parameter.parameter7options=["1":"Yes", "0":"No"]
  1051. parameter.parameter8options="0..32767"
  1052. parameter.parameter9options="0..99"
  1053. parameter.parameter10options="0..99"
  1054. parameter.parameter11options="0..100"
  1055. parameter.parameter12options="0..15"
  1056. parameter.parameter13options=["0":"Red","21":"Orange","42":"Yellow","85":"Green","127":"Cyan","170":"Blue","212":"Violet","234":"Pink","255":"White (Firmware 1.45+)"]
  1057. parameter.parameter14options=["0":"0%","1":"10%","2":"20%","3":"30%","4":"40%","5":"50%","6":"60%","7":"70%","8":"80%","9":"90%","10":"100%"]
  1058. parameter.parameter15options=["0":"0%","1":"10%","2":"20%","3":"30%","4":"40%","5":"50%","6":"60%","7":"70%","8":"80%","9":"90%","10":"100%"]
  1059. parameter.parameter16options=["1":"Yes", "2":"No"]
  1060. parameter.parameter17options=["0":"Stay Off","1":"1 Second","2":"2 Seconds","3":"3 Seconds","4":"4 Seconds","5":"5 Seconds","6":"6 Seconds","7":"7 Seconds","8":"8 Seconds","9":"9 Seconds","10":"10 Seconds"]
  1061. parameter.parameter18options="0..100"
  1062. parameter.parameter19options="0..32767"
  1063. parameter.parameter20options="0..100"
  1064. parameter.parameter21options=["0":"Non Neutral", "1":"Neutral"]
  1065. parameter.parameter22options=["0":"Load Only", "1":"3-way Toggle", "2":"3-way Momentary"]
  1066. parameter.parameter50options=["1":"100ms", "2":"200ms", "3":"300ms","4":"400ms", "5":"500ms", "6":"600ms","7":"700ms", "8":"800ms", "9":"900ms"]
  1067. parameter.parameter51options=["1":"No (Default)", "0":"Yes"]
  1068. parameter.parameter52options=["0":"Disabled", "1":"On / Off Only", "2":"Smart Bulb"]
  1069.  
  1070. parameter.parameter1name="Dimming Speed"
  1071. parameter.parameter2name="Dimming Speed (From Switch)"
  1072. parameter.parameter3name="Ramp Rate"
  1073. parameter.parameter4name="Ramp Rate (From Switch)"
  1074. parameter.parameter5name="Minimum Level"
  1075. parameter.parameter6name="Maximum Level"
  1076. parameter.parameter7name="Invert Switch"
  1077. parameter.parameter8name="Auto Off Timer"
  1078. parameter.parameter9name="Default Level (Local)"
  1079. parameter.parameter10name="Default Level (Z-Wave)"
  1080. parameter.parameter11name="State After Power Restored"
  1081. parameter.parameter12name="Association Behavior"
  1082. parameter.parameter13name="LED Strip Color"
  1083. parameter.parameter14name="LED Strip Intensity"
  1084. parameter.parameter15name="LED Strip Intensity (When OFF)"
  1085. parameter.parameter16name="LED Strip Effect"
  1086. parameter.parameter17name="LED Strip Timeout"
  1087. parameter.parameter18name="Active Power Reports"
  1088. parameter.parameter19name="Periodic Power & Energy Reports"
  1089. parameter.parameter20name="Energy Reports"
  1090. parameter.parameter21name="AC Power Type"
  1091. parameter.parameter22name="Switch Type"
  1092. parameter.parameter50name="Button Press Delay"
  1093. parameter.parameter51name="Disable Physical On/Off Delay"
  1094. parameter.parameter52name="Smart Bulb Mode"
  1095.  
  1096. parameter.parameter1description="This changes the speed in which the attached light dims up or down. A setting of 0 should turn the light immediately on or off (almost like an on/off switch). Increasing the value should slow down the transition speed."
  1097. parameter.parameter2description="This changes the speed in which the attached light dims up or down when controlled from the physical switch. A setting of 0 should turn the light immediately on or off (almost like an on/off switch). Increasing the value should slow down the transition speed. A setting of 101 should keep this in sync with parameter 1."
  1098. parameter.parameter3description="This changes the speed in which the attached light turns on or off. For example, when a user sends the switch a basicSet(value: 0xFF) or basicSet(value: 0x00), this is the speed in which those actions take place. A setting of 0 should turn the light immediately on or off (almost like an on/off switch). Increasing the value should slow down the transition speed. A setting of 101 should keep this in sync with parameter 1."
  1099. parameter.parameter4description="This changes the speed in which the attached light turns on or off from the physical switch. For example, when a user presses the up or down button, this is the speed in which those actions take place. A setting of 0 should turn the light immediately on or off (almost like an on/off switch). Increasing the value should slow down the transition speed. A setting of 101 should keep this in sync with parameter 1."
  1100. parameter.parameter5description="The minimum level that the dimmer allows the bulb to be dimmed to. Useful when the user has an LED bulb that does not turn on or flickers at a lower level."
  1101. parameter.parameter6description="The maximum level that the dimmer allows the bulb to be dimmed to. Useful when the user has an LED bulb that reaches its maximum level before the dimmer value of 99."
  1102. parameter.parameter7description="Inverts the orientation of the switch. Useful when the switch is installed upside down. Essentially up becomes down and down becomes up."
  1103. parameter.parameter8description="Automatically turns the switch off after this many seconds. When the switch is turned on a timer is started that is the duration of this setting. When the timer expires, the switch is turned off."
  1104. parameter.parameter9description="Default level for the dimmer when it is powered on from the local switch. A setting of 0 means that the switch will return to the level that it was on before it was turned off."
  1105. parameter.parameter10description="Default level for the dimmer when it is powered on from a Z-Wave command. A setting of 0 means that the switch will return to the level that it was on before it was turned off."
  1106. parameter.parameter11description="The state the switch should return to once power is restored after power failure. 0 = off, 1-99 = level, 100=previous."
  1107. parameter.parameter12description="When should the switch send commands to associated devices?\n\n01 - local\n02 - 3way\n03 - 3way & local\n04 - z-wave hub\n05 - z-wave hub & local\n06 - z-wave hub & 3-way\n07 - z-wave hub & local & 3way\n08 - timer\n09 - timer & local\n10 - timer & 3-way\n11 - timer & 3-way & local\n12 - timer & z-wave hub\n13 - timer & z-wave hub & local\n14 - timer & z-wave hub & 3-way\n15 - all"
  1108. parameter.parameter13description="This is the color of the LED strip."
  1109. parameter.parameter14description="This is the intensity of the LED strip."
  1110. parameter.parameter15description="This is the intensity of the LED strip when the switch is off. This is useful for users to see the light switch location when the lights are off."
  1111. parameter.parameter16description="LED Strip Effect"
  1112. parameter.parameter17description="When the LED strip is disabled (LED Strip Intensity is set to 0), this setting allows the LED strip to turn on temporarily while being adjusted."
  1113. parameter.parameter18description="The power level change that will result in a new power report being sent. The value is a percentage of the previous report. 0 = disabled."
  1114. parameter.parameter19description="Time period between consecutive power & energy reports being sent (in seconds). The timer is reset after each report is sent."
  1115. parameter.parameter20description="The energy level change that will result in a new energy report being sent. The value is a percentage of the previous report."
  1116. parameter.parameter21description="Configure the switch to use a neutral wire."
  1117. parameter.parameter22description="Configure the type of 3-way switch connected to the dimmer."
  1118. parameter.parameter50description="This will set the button press delay if parameter 51 is set to 1. For this parameter 1 = 100ms, 2 = 200ms, 3 = 300ms, etc. up to 900ms (firmware 1.52+)"
  1119. parameter.parameter51description="The 700ms delay that occurs after pressing the physical button to turn the switch on/off is removed. Consequently this also removes the following scenes: 2x, 3x, 4x, 5x tap. 1x tap and config button scenes still work. (firmware 1.47+)"
  1120. parameter.parameter52description="Change the working mode of the dimmer. Choose either on / off only which makes the device work like an on / off switch. Or choose smart bulb mode which optimized the device for interaction with smart bulbs. (firmware 1.54+)"
  1121.  
  1122. return parameter."parameter${number}${value}"
  1123. }
  1124.  
  1125. def zwaveEvent(hubitat.zwave.commands.meterv3.MeterReport cmd) {
  1126. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1127. def event
  1128. if (cmd.scale == 0) {
  1129. if (cmd.meterType == 161) {
  1130. event = createEvent(name: "voltage", value: cmd.scaledMeterValue, unit: "V")
  1131. if (infoEnable) log.info "${device.label?device.label:device.name}: Voltage report received with value of ${cmd.scaledMeterValue} V"
  1132. } else if (cmd.meterType == 1) {
  1133. event = createEvent(name: "energy", value: cmd.scaledMeterValue, unit: "kWh")
  1134. if (infoEnable) log.info "${device.label?device.label:device.name}: Energy report received with value of ${cmd.scaledMeterValue} kWh"
  1135. }
  1136. } else if (cmd.scale == 1) {
  1137. event = createEvent(name: "amperage", value: cmd.scaledMeterValue, unit: "A")
  1138. if (infoEnable) log.info "${device.label?device.label:device.name}: Amperage report received with value of ${cmd.scaledMeterValue} A"
  1139. } else if (cmd.scale == 2) {
  1140. event = createEvent(name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W")
  1141. if (infoEnable) log.info "${device.label?device.label:device.name}: Power report received with value of ${cmd.scaledMeterValue} W"
  1142. }
  1143.  
  1144. return event
  1145. }
  1146.  
  1147. def zwaveEvent(hubitat.zwave.commands.configurationv1.ConfigurationReport cmd) {
  1148. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1149. if (infoEnable) log.info "${device.label?device.label:device.name}: parameter '${cmd.parameterNumber}' with a byte size of '${cmd.size}' is set to '${cmd2Integer(cmd.configurationValue)}'"
  1150. def integerValue = cmd2Integer(cmd.configurationValue)
  1151. state."parameter${cmd.parameterNumber}value" = integerValue
  1152. switch (cmd.parameterNumber) {
  1153. case 9:
  1154. device.updateSetting("parameter${cmd.parameterNumber}",[value:integerValue,type:"number"])
  1155. def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep9")}
  1156. if (childDevice) {
  1157. childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off")
  1158. childDevice.sendEvent(name: "level", value: integerValue)
  1159. }
  1160. break
  1161. case 10:
  1162. device.updateSetting("parameter${cmd.parameterNumber}",[value:integerValue,type:"number"])
  1163. def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep10")}
  1164. if (childDevice) {
  1165. childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off")
  1166. childDevice.sendEvent(name: "level", value: integerValue)
  1167. }
  1168. break
  1169. case 13:
  1170. if(integerValue==0||integerValue==21||integerValue==42||integerValue==85||integerValue==127||integerValue==170||integerValue==212||integerValue==234||integerValue==255){
  1171. device.updateSetting("parameter${cmd.parameterNumber}",[value:"${integerValue}",type:"number"])
  1172. device.removeSetting("parameter${cmd.parameterNumber}custom")
  1173. } else {
  1174. device.removeSetting("parameter${cmd.parameterNumber}")
  1175. device.updateSetting("parameter${cmd.parameterNumber}custom",[value:Math.round(zwaveValueToHueValue(integerValue)),type:"number"])
  1176. }
  1177. def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep103")}
  1178. if (childDevice) {
  1179. childDevice.sendEvent(name:"hue", value:"${Math.round(zwaveValueToHuePercent(integerValue))}")
  1180. childDevice.sendEvent(name:"saturation", value:"100")
  1181. }
  1182. break
  1183. case 14:
  1184. device.updateSetting("parameter${cmd.parameterNumber}",[value:"${integerValue}",type:"enum"])
  1185. def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep103")}
  1186. if (childDevice) {
  1187. childDevice.sendEvent(name:"level", value:"${integerValue*10}")
  1188. childDevice.sendEvent(name:"switch", value:"${integerValue==0?"off":"on"}")
  1189. }
  1190. break
  1191. }
  1192. }
  1193.  
  1194. def cmd2Integer(array) {
  1195. switch(array.size()) {
  1196. case 1:
  1197. array[0]
  1198. break
  1199. case 2:
  1200. ((array[0] & 0xFF) << 8) | (array[1] & 0xFF)
  1201. break
  1202. case 3:
  1203. ((array[0] & 0xFF) << 16) | ((array[1] & 0xFF) << 8) | (array[2] & 0xFF)
  1204. break
  1205. case 4:
  1206. ((array[0] & 0xFF) << 24) | ((array[1] & 0xFF) << 16) | ((array[2] & 0xFF) << 8) | (array[3] & 0xFF)
  1207. break
  1208. }
  1209. }
  1210.  
  1211. def integer2Cmd(value, size) {
  1212. try{
  1213. switch(size) {
  1214. case 1:
  1215. [value]
  1216. break
  1217. case 2:
  1218. def short value1 = value & 0xFF
  1219. def short value2 = (value >> 8) & 0xFF
  1220. [value2, value1]
  1221. break
  1222. case 3:
  1223. def short value1 = value & 0xFF
  1224. def short value2 = (value >> 8) & 0xFF
  1225. def short value3 = (value >> 16) & 0xFF
  1226. [value3, value2, value1]
  1227. break
  1228. case 4:
  1229. def short value1 = value & 0xFF
  1230. def short value2 = (value >> 8) & 0xFF
  1231. def short value3 = (value >> 16) & 0xFF
  1232. def short value4 = (value >> 24) & 0xFF
  1233. [value4, value3, value2, value1]
  1234. break
  1235. }
  1236. } catch (e) {
  1237. if (debugEnable) log.debug "Error: integer2Cmd $e Value: $value"
  1238. }
  1239. }
  1240.  
  1241. private getCommandClassVersions() {
  1242. [0x20: 1, 0x25: 1, 0x70: 1, 0x98: 1, 0x32: 3, 0x5B: 1]
  1243. }
  1244.  
  1245. def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
  1246. def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions)
  1247. if (encapsulatedCommand) {
  1248. state.sec = 1
  1249. zwaveEvent(encapsulatedCommand)
  1250. }
  1251. }
  1252.  
  1253. def parse(description) {
  1254. def result = null
  1255. if (description.startsWith("Err 106")) {
  1256. state.sec = 0
  1257. result = createEvent(descriptionText: description, isStateChange: true)
  1258. } else if (description != "updated") {
  1259. def cmd = zwave.parse(description, commandClassVersions)
  1260. if (cmd) {
  1261. result = zwaveEvent(cmd)
  1262. //log.debug("'$cmd' parsed to $result")
  1263. } else {
  1264. if (debugEnable) log.debug "Couldn't zwave.parse '$description'"
  1265. }
  1266. }
  1267. def now
  1268. if(location.timeZone)
  1269. now = new Date().format("yyyy MMM dd EEE h:mm:ss a", location.timeZone)
  1270. else
  1271. now = new Date().format("yyyy MMM dd EEE h:mm:ss a")
  1272. sendEvent(name: "lastActivity", value: now, displayed:false)
  1273. result
  1274. }
  1275.  
  1276. def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
  1277. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1278. if (infoEnable) log.info "${device.label?device.label:device.name}: Basic report received with value of ${cmd.value ? "on" : "off"} ($cmd.value)"
  1279. dimmerEvents(cmd, (!state.lastRan || now() <= state.lastRan + 5000)?"digital":"physical")
  1280. }
  1281.  
  1282. def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
  1283. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1284. if (infoEnable) log.info "${device.label?device.label:device.name}: Basic set received with value of ${cmd.value ? "on" : "off"}"
  1285. dimmerEvents(cmd)
  1286. }
  1287.  
  1288. def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  1289. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1290. if (infoEnable) log.info "${device.label?device.label:device.name}: Switch Binary report received with value of ${cmd.value ? "on" : "off"}"
  1291. dimmerEvents(cmd)
  1292. }
  1293.  
  1294. def zwaveEvent(hubitat.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
  1295. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1296. if (infoEnable) log.info "${device.label?device.label:device.name}: Switch Multilevel report received with value of ${cmd.value ? "on" : "off"} ($cmd.value)"
  1297. dimmerEvents(cmd, (!state.lastRan || now() <= state.lastRan + 5000)?"digital":"physical")
  1298. }
  1299.  
  1300. private dimmerEvents(hubitat.zwave.Command cmd, type="physical") {
  1301. def value = (cmd.value ? "on" : "off")
  1302. def result = [createEvent(name: "switch", value: value, type: type)]
  1303. if (cmd.value) {
  1304. result << createEvent(name: "level", value: cmd.value, unit: "%", type: type)
  1305. }
  1306. return result
  1307. }
  1308.  
  1309. void zwaveEvent(hubitat.zwave.commands.centralscenev1.CentralSceneNotification cmd) {
  1310. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1311. switch (cmd.keyAttributes) {
  1312. case 0:
  1313. if (cmd.sceneNumber == 3) buttonEvent(7, "pushed", "physical")
  1314. else buttonEvent(cmd.keyAttributes + 1, (cmd.sceneNumber == 2 || cmd.sceneNumber == 4? "pushed" : "held"), "physical")
  1315. break
  1316. case 1:
  1317. if (cmd.sceneNumber == 3) buttonEvent(7, "released", "physical")
  1318. else buttonEvent(6, (cmd.sceneNumber == 2 || cmd.sceneNumber == 4? "pushed" : "held"), "physical")
  1319. break
  1320. case 2:
  1321. if (cmd.sceneNumber == 3) buttonEvent(7, "held", "physical")
  1322. else buttonEvent(8, (cmd.sceneNumber == 2 || cmd.sceneNumber == 4? "pushed" : "held"), "physical")
  1323. break
  1324. default:
  1325. if (cmd.sceneNumber == 3) buttonEvent(7, "held", "physical")
  1326. else buttonEvent(cmd.keyAttributes - 1, (cmd.sceneNumber == 2 || cmd.sceneNumber == 4? "pushed" : "held"), "physical")
  1327. break
  1328. }
  1329. }
  1330.  
  1331. void buttonEvent(button, value, type = "digital") {
  1332. switch (button) {
  1333. case 1:
  1334. case 2:
  1335. case 3:
  1336. case 4:
  1337. case 5:
  1338. sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Tap '.padRight(button+5, '▼'):' Tap '.padRight(button+5, '▲')}", displayed:false)
  1339. break
  1340. case 6:
  1341. sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Released ▼':' Released ▲'}", displayed:false)
  1342. break
  1343. case 8:
  1344. sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Hold ▼':' Hold ▲'}", displayed:false)
  1345. break
  1346. }
  1347.  
  1348. if (infoEnable) log.info "${device.label?device.label:device.name}: Button ${button} was ${value}"
  1349.  
  1350. sendEvent(name: value, value: button, isStateChange:true)
  1351. }
  1352.  
  1353. def zwaveEvent(hubitat.zwave.Command cmd) {
  1354. if (debugEnable) log.debug "${device.label?device.label:device.name}: Unhandled: $cmd"
  1355. null
  1356. }
  1357.  
  1358. def reset() {
  1359. if (infoEnable) log.info "${device.label?device.label:device.name}: Resetting energy statistics"
  1360. def cmds = []
  1361. cmds << zwave.meterV2.meterReset()
  1362. cmds << zwave.meterV2.meterGet(scale: 0)
  1363. cmds << zwave.meterV2.meterGet(scale: 2)
  1364. commands(cmds, 1000)
  1365. }
  1366.  
  1367. def on() {
  1368. if (infoEnable) log.info "${device.label?device.label:device.name}: on()"
  1369. state.lastRan = now()
  1370. commands([
  1371. zwave.basicV1.basicSet(value: 0xFF)
  1372. //zwave.switchMultilevelV2.switchMultilevelSet(value: 99)
  1373. ])
  1374. }
  1375.  
  1376. def off() {
  1377. if (infoEnable) log.info "${device.label?device.label:device.name}: off()"
  1378. state.lastRan = now()
  1379. commands([
  1380. zwave.basicV1.basicSet(value: 0x00)
  1381. //zwave.switchMultilevelV2.switchMultilevelSet(value: 0)
  1382. ])
  1383. }
  1384.  
  1385. def setLevel(value) {
  1386. if (infoEnable) log.info "${device.label?device.label:device.name}: setLevel($value)"
  1387. state.lastRan = now()
  1388. commands([
  1389. zwave.switchMultilevelV2.switchMultilevelSet(value: value < 100 ? value : 99)
  1390. ])
  1391. }
  1392.  
  1393. def setLevel(value, duration) {
  1394. if (infoEnable) log.info "${device.label?device.label:device.name}: setLevel($value, $duration)"
  1395. state.lastRan = now()
  1396. def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
  1397. commands([
  1398. zwave.switchMultilevelV2.switchMultilevelSet(value: value < 100 ? value : 99, dimmingDuration: dimmingDuration)
  1399. ])
  1400. }
  1401.  
  1402. def ping() {
  1403. if (debugEnable) log.debug "ping()"
  1404. refresh()
  1405. }
  1406.  
  1407. def poll() {
  1408. if (debugEnable) log.debug "poll()"
  1409. refresh()
  1410. }
  1411.  
  1412. def refresh() {
  1413. if (debugEnable) log.debug "refresh()"
  1414. def cmds = []
  1415. cmds << zwave.switchMultilevelV1.switchMultilevelGet()
  1416. cmds << zwave.meterV3.meterGet(scale: 0)
  1417. cmds << zwave.meterV3.meterGet(scale: 2)
  1418. return commands(cmds)
  1419. }
  1420.  
  1421. private command(hubitat.zwave.Command cmd) {
  1422. return zwaveSecureEncap(cmd)
  1423. }
  1424.  
  1425. void zwaveEvent(hubitat.zwave.commands.supervisionv1.SupervisionGet cmd){
  1426. hubitat.zwave.Command encapCmd = cmd.encapsulatedCommand(commandClassVersions)
  1427. if (encapCmd) {
  1428. zwaveEvent(encapCmd)
  1429. }
  1430. sendHubCommand(new hubitat.device.HubAction(command(zwave.supervisionV1.supervisionReport(sessionID: cmd.sessionID, reserved: 0, moreStatusUpdates: false, status: 0xFF, duration: 0)), hubitat.device.Protocol.ZWAVE))
  1431. }
  1432.  
  1433. private commands(commands, delay=1000) {
  1434. delayBetween(commands.collect{ command(it) }, delay)
  1435. }
  1436.  
  1437. def pressUpX1() {
  1438. buttonEvent(1, "pushed")
  1439. }
  1440.  
  1441. def pressDownX1() {
  1442. buttonEvent(1, "held")
  1443. }
  1444.  
  1445. def pressUpX2() {
  1446. buttonEvent(2, "pushed")
  1447. }
  1448.  
  1449. def pressDownX2() {
  1450. buttonEvent(2, "held")
  1451. }
  1452.  
  1453. def pressUpX3() {
  1454. buttonEvent(3, "pushed")
  1455. }
  1456.  
  1457. def pressDownX3() {
  1458. buttonEvent(3, "held")
  1459. }
  1460.  
  1461. def pressUpX4() {
  1462. buttonEvent(4, "pushed")
  1463. }
  1464.  
  1465. def pressDownX4() {
  1466. buttonEvent(4, "held")
  1467. }
  1468.  
  1469. def pressUpX5() {
  1470. buttonEvent(5, "pushed")
  1471. }
  1472.  
  1473. def pressDownX5() {
  1474. buttonEvent(5, "held")
  1475. }
  1476.  
  1477. def holdUp() {
  1478. buttonEvent(8, "pushed")
  1479. }
  1480.  
  1481. def holdDown() {
  1482. buttonEvent(8, "held")
  1483. }
  1484.  
  1485. def releaseUp() {
  1486. buttonEvent(6, "pushed")
  1487. }
  1488.  
  1489. def releaseDown() {
  1490. buttonEvent(6, "held")
  1491. }
  1492.  
  1493. def pressConfig() {
  1494. buttonEvent(7, "pushed")
  1495. }
  1496.  
  1497.  
  1498. void push(button) {
  1499. sendEvent(name: "pushed", value: button, isStateChange: true, type: "digital")
  1500. }
  1501.  
  1502. void hold(button) {
  1503. sendEvent(name: "held", value: button, isStateChange: true, type: "digital")
  1504. }
  1505.  
  1506. def setDefaultAssociations() {
  1507. def smartThingsHubID = String.format('%02x', zwaveHubNodeId).toUpperCase()
  1508. state.defaultG1 = [smartThingsHubID]
  1509. state.defaultG2 = []
  1510. state.defaultG3 = []
  1511. }
  1512.  
  1513. def setAssociationGroup(group, nodes, action, endpoint = null){
  1514. // Normalize the arguments to be backwards compatible with the old method
  1515. action = "${action}" == "1" ? "Add" : "${action}" == "0" ? "Remove" : "${action}" // convert 1/0 to Add/Remove
  1516. group = "${group}" =~ /\d+/ ? (group as int) : group // convert group to int (if possible)
  1517. nodes = [] + nodes ?: [nodes] // convert to collection if not already a collection
  1518.  
  1519. if (! nodes.every { it =~ /[0-9A-F]+/ }) {
  1520. log.error "${device.label?device.label:device.name}: invalid Nodes ${nodes}"
  1521. return
  1522. }
  1523.  
  1524. if (group < 1 || group > maxAssociationGroup()) {
  1525. log.error "${device.label?device.label:device.name}: Association group is invalid 1 <= ${group} <= ${maxAssociationGroup()}"
  1526. return
  1527. }
  1528.  
  1529. def associations = state."desiredAssociation${group}"?:[]
  1530. nodes.each {
  1531. node = "${it}"
  1532. switch (action) {
  1533. case "Remove":
  1534. if (infoEnable) log.info "${device.label?device.label:device.name}: Removing node ${node} from association group ${group}"
  1535. associations = associations - node
  1536. break
  1537. case "Add":
  1538. if (infoEnable) log.info "${device.label?device.label:device.name}: Adding node ${node} to association group ${group}"
  1539. associations << node
  1540. break
  1541. }
  1542. }
  1543. state."desiredAssociation${group}" = associations.unique()
  1544. return
  1545. }
  1546.  
  1547. def maxAssociationGroup(){
  1548. if (!state.associationGroups) {
  1549. if (infoEnable) log.info "${device.label?device.label:device.name}: Getting supported association groups from device"
  1550. sendHubCommand(new hubitat.device.HubAction(command(zwave.associationV2.associationGroupingsGet()), hubitat.device.Protocol.ZWAVE )) // execute the update immediately
  1551. }
  1552. (state.associationGroups?: 5) as int
  1553. }
  1554.  
  1555. def processAssociations(){
  1556. def cmds = []
  1557. setDefaultAssociations()
  1558. def associationGroups = maxAssociationGroup()
  1559. for (int i = 1; i <= associationGroups; i++){
  1560. if(state."actualAssociation${i}" != null){
  1561. if(state."desiredAssociation${i}" != null || state."defaultG${i}") {
  1562. def refreshGroup = false
  1563. ((state."desiredAssociation${i}"? state."desiredAssociation${i}" : [] + state."defaultG${i}") - state."actualAssociation${i}").each {
  1564. if (it){
  1565. if (infoEnable) log.info "${device.label?device.label:device.name}: Adding node $it to group $i"
  1566. cmds << zwave.associationV2.associationSet(groupingIdentifier:i, nodeId:hubitat.helper.HexUtils.hexStringToInt(it))
  1567. refreshGroup = true
  1568. }
  1569. }
  1570. ((state."actualAssociation${i}" - state."defaultG${i}") - state."desiredAssociation${i}").each {
  1571. if (it){
  1572. if (infoEnable) log.info "${device.label?device.label:device.name}: Removing node $it from group $i"
  1573. cmds << zwave.associationV2.associationRemove(groupingIdentifier:i, nodeId:hubitat.helper.HexUtils.hexStringToInt(it))
  1574. refreshGroup = true
  1575. }
  1576. }
  1577. if (refreshGroup == true) cmds << zwave.associationV2.associationGet(groupingIdentifier:i)
  1578. else if (infoEnable) log.info "${device.label?device.label:device.name}: There are no association actions to complete for group $i"
  1579. }
  1580. } else {
  1581. if (infoEnable) log.info "${device.label?device.label:device.name}: Association info not known for group $i. Requesting info from device."
  1582. cmds << zwave.associationV2.associationGet(groupingIdentifier:i)
  1583. }
  1584. }
  1585. return cmds
  1586. }
  1587.  
  1588. def zwaveEvent(hubitat.zwave.commands.associationv2.AssociationReport cmd) {
  1589. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1590. def temp = []
  1591. if (cmd.nodeId != []) {
  1592. cmd.nodeId.each {
  1593. temp += it.toString().format( '%02x', it.toInteger() ).toUpperCase()
  1594. }
  1595. }
  1596. state."actualAssociation${cmd.groupingIdentifier}" = temp
  1597. if (infoEnable) log.info "${device.label?device.label:device.name}: Associations for Group ${cmd.groupingIdentifier}: ${temp}"
  1598. updateDataValue("associationGroup${cmd.groupingIdentifier}", "$temp")
  1599. }
  1600.  
  1601. def zwaveEvent(hubitat.zwave.commands.associationv2.AssociationGroupingsReport cmd) {
  1602. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1603. sendEvent(name: "groups", value: cmd.supportedGroupings)
  1604. if (infoEnable) log.info "${device.label?device.label:device.name}: Supported association groups: ${cmd.supportedGroupings}"
  1605. state.associationGroups = cmd.supportedGroupings
  1606. }
  1607.  
  1608. void zwaveEvent(hubitat.zwave.commands.versionv1.VersionReport cmd) {
  1609. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
  1610. if(cmd.applicationVersion != null && cmd.applicationSubVersion != null) {
  1611. def firmware = "${cmd.applicationVersion}.${cmd.applicationSubVersion.toString().padLeft(2,'0')}"
  1612. if (infoEnable) log.info "${device.label?device.label:device.name}: Firmware report received: ${firmware}"
  1613. state.needfwUpdate = "false"
  1614. sendEvent(name: "firmware", value: "${firmware}")
  1615. } else if(cmd.firmware0Version != null && cmd.firmware0SubVersion != null) {
  1616. def firmware0 = "${cmd.firmware0Version}.${cmd.firmware0SubVersion.toString().padLeft(2,'0')}"
  1617. if (infoEnable != false) log.info "${device.label?device.label:device.name}: Firmware report received: ${firmware0}"
  1618. state.needfwUpdate = "false"
  1619. sendEvent(name: "firmware", value: "${firmware0}")
  1620. sendEvent(name: "firmware0", value: "${firmware0}")
  1621. }
  1622. cmd.targetVersions.each { i ->
  1623. def firmware = "${i.version}.${i.subVersion.toString().padLeft(2,'0')}"
  1624. if (infoEnable != false) log.info "${device.label?device.label:device.name}: Firmware Target ${i.target} report received: firmware ${firmware}"
  1625. sendEvent(name: "firmware${i.target}", value: firmware)
  1626. }
  1627. }
  1628.  
  1629. def zwaveEvent(hubitat.zwave.commands.protectionv2.ProtectionReport cmd) {
  1630. if (debugEnable) log.debug "${device.label?device.label:device.name}: ${device.label?device.label:device.name}: ${cmd}"
  1631. if (infoEnable) log.info "${device.label?device.label:device.name}: Protection report received: Local protection is ${cmd.localProtectionState > 0 ? "on" : "off"} & Remote protection is ${cmd.rfProtectionState > 0 ? "on" : "off"}"
  1632. state.localProtectionState = cmd.localProtectionState
  1633. state.rfProtectionState = cmd.rfProtectionState
  1634. device.updateSetting("disableLocal",[value:cmd.localProtectionState?"1":"0",type:"enum"])
  1635. device.updateSetting("disableRemote",[value:cmd.rfProtectionState?"1":"0",type:"enum"])
  1636. def children = childDevices
  1637. def childDevice = children.find{it.deviceNetworkId.endsWith("ep101")}
  1638. if (childDevice) {
  1639. childDevice.sendEvent(name: "switch", value: cmd.localProtectionState > 0 ? "on" : "off")
  1640. }
  1641. childDevice = children.find{it.deviceNetworkId.endsWith("ep102")}
  1642. if (childDevice) {
  1643. childDevice.sendEvent(name: "switch", value: cmd.rfProtectionState > 0 ? "on" : "off")
  1644. }
  1645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement