/** * Inovelli Dimmer Red Series LZW31-SN * Author: Eric Maycock (erocm123) * Date: 2021-11-24 * * ****************************************************************************************************** * * OPTIONAL CHILD DEVICE HANDLERS: * LED Bar: In the device settings you can enable up an RGBW child devices that can be used to change the color and intesity of the LED bar. * Configuration Options: Some configuration options such as Default level also uses the Switch Level Child Device. * https://raw.githubusercontent.com/InovelliUSA/SmartThingsInovelli/master/devicetypes/inovelliusa/switch-level-child-device.src/switch-level-child-device.groovy * https://raw.githubusercontent.com/InovelliUSA/SmartThingsInovelli/master/devicetypes/inovelliusa/rgbw-child-device.src/rgbw-child-device.groovy * * ****************************************************************************************************** * * Copyright 2021 Eric Maycock / Inovelli * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * * 2021-11-24: Increasing accuracy of physical vs digital detection. * * 2021-11-03: Work around for association reports not being parsed. * * 2021-06-03: Updating button event parsing for aux switch (firmware 1.56+). * * 2021-04-26: Adding options for parameter 52 (disabled, on/off only mode, smartbulb mode). * * 2021-04-05: Rearrange capabilities for Home Bridge problem. * * 2021-01-28: Adding configuration parameter (50) for firmware 1.52+ * 50 allows you to configure the delay when turning switch on/off from wall * * 2020-11-13: Adding option to create child devices for LED Color & Intensity when on and Intensity when off. * This will allow you to control those configuration options easily in other apps. This requires * child device handlers to be installed that are listed above. * * 2020-09-21: Changing how child devices are created for better compatibility with new app. * * 2020-09-16: Adding parameter 12 (Association Behavior). * * 2020-08-14: Fix for SmartLighting app not working with recent change in new SmartThings app. * Device needs to receive a report after the device handler is updated for this to start working. * User can force a report by turning the device on or off, refreshing, etc. * * 2020-08-12: Fixing on(), off(), & setLevel() commands to match device preference descriptions. Use a different method * to determine physical vs digital dimmer events. * * 2020-07-17: Added configuration parameter (51 & 51) for firmware 1.47+ * 51 allows you to disable the 700ms delay when turning switch on/off from the wall. * 52 is to put the switch into a "smart bulb" mode to optimize the output for smart bulbs. * * 2020-07-01: Fix for bool settings not showing correctly in SmartThings app. * Adding white LED color options for firmware 1.45+ * * 2020-05-05: Adding ColorControl capability to allow changing the LED bar color easily with setColor. * Adding preferences to automatically disable logs after x minutes. Previously the informational * logging would disable after 30 minutes without an option for the user. * * 2020-05-01: Correctly distinguish between digital and physical on / off. Will not work when you set the level * with a duration. * * 2020-03-27: Adding additional duration options for Notifications. Also adding the commands * startNotification(value) and stopNotification() to be used in apps like * WebCoRE or Rule Machine to directly control notifications instead of through child Devices. * To determine "value": https://nathanfiscus.github.io/inovelli-notification-calc/ * * 2020-02-26: Switch over to using SmartThings child device handler for notifications. * * 2020-02-06: Fix for remote control child device being created when it shouldn't be. * * 2020-02-05: Extra button event added for those that want to distinguish held vs pushed. * Button 8 pushed = Up button held. Button 8 held = Down button held. * Button 6 pushed = Up button released. Button 6 pushed = Down button released. * * 2019-11-16: Ability to choose custom LED bar color. Child devices to control default level (local & z-wave), * local & remote protection. Ability to turn on / off info & debug logging. Additional logging added. * Prevent overwriting parameters that are configured at the switch. Bumping number of notifications to 5. * Added additional button events for "released" vs "held". Button 8 pushed (up released) * & button 8 released (down released). Other bug fixes and improvements. * * 2019-11-13: Bug fix for not being able to set default level back to 0 */ import groovy.transform.Field import groovy.json.JsonOutput @Field static List ledNotificationEndpoints = [16] @Field static Map ledColorEndpoints = [103:13] @Field static Map ledIntensityEndpoints = [103:14] @Field static Map ledIntensityOffEndpoints = [104:15] metadata { definition (name: "Inovelli Dimmer Red Series LZW31-SN", namespace: "InovelliUSA", author: "Eric Maycock", vid: "generic-dimmer-power-energy") { capability "Switch" capability "Switch Level" capability "Refresh" capability "Actuator" capability "Sensor" //capability "Health Check" capability "Button" capability "Holdable Button" capability "Configuration" capability "Energy Meter" capability "Power Meter" attribute "lastActivity", "String" attribute "lastEvent", "String" attribute "firmware", "String" attribute "groups", "Number" command "pressUpX1" command "pressDownX1" command "pressUpX2" command "pressDownX2" command "pressUpX3" command "pressDownX3" command "pressUpX4" command "pressDownX4" command "pressUpX5" command "pressDownX5" command "holdUp" command "holdDown" command "startNotification" command "stopNotification" command "reset" command "setAssociationGroup", ["number", "enum", "number", "number"] // group number, nodes, action (0 - remove, 1 - add), multi-channel endpoint (optional) fingerprint mfr: "031E", prod: "0001", model: "0001", deviceJoinName: "Inovelli Dimmer Red Series" fingerprint deviceId: "0x1101", inClusters: "0x5E,0x55,0x98,0x9F,0x6C,0x22,0x26,0x70,0x85,0x59,0x86,0x32,0x72,0x5A,0x5B,0x73,0x75,0x7A" // Red Series fingerprint deviceId: "0x1101", inClusters: "0x5E,0x26,0x70,0x85,0x59,0x55,0x86,0x72,0x5A,0x73,0x32,0x98,0x9F,0x5B,0x6C,0x75,0x22,0x7A" // Red Series } simulator { } preferences { generate_preferences() } tiles { multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) { tileAttribute("device.switch", key: "PRIMARY_CONTROL") { attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn" attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff" attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn" attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc", nextState: "turningOff" } tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel" } tileAttribute ("device.color", key: "COLOR_CONTROL") { attributeState "color", action:"color control.setColor" } tileAttribute("device.lastEvent", key: "SECONDARY_CONTROL") { attributeState("default", label:'${currentValue}',icon: "st.unknown.zwave.remote-controller") } } valueTile("lastActivity", "device.lastActivity", inactiveLabel: false, decoration: "flat", width: 4, height: 1) { state "default", label: 'Last Activity: ${currentValue}',icon: "st.Health & Wellness.health9" } valueTile("firmware", "device.firmware", inactiveLabel: false, decoration: "flat", width: 2, height: 1) { state "default", label: 'fw: ${currentValue}', icon: "" } valueTile("power", "device.power", decoration: "flat", width: 2, height: 2) { state "default", label:'${currentValue} W' } valueTile("energy", "device.energy", decoration: "flat", width: 2, height: 2) { state "default", label:'${currentValue} kWh' } /* valueTile("info", "device.info", inactiveLabel: false, decoration: "flat", width: 3, height: 1) { state "default", label: 'Tap on the buttons below to test scenes (ie: Tap ▲ 1x, ▲▲ 2x, etc depending on the button)' } */ standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "default", label:'reset kWh', action:"reset" } childDeviceTiles("all") valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 4, height: 1) { state "default", label: '', icon: "https://inovelli.com/wp-content/uploads/Device-Handler/Inovelli-Device-Handler-Logo.png" } standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 2, height: 1) { state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh" } /* standardTile("pressUpX1", "device.pressUpX1", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressUpX1" } standardTile("pressUpX2", "device.pressUpX2", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressUpX2" } standardTile("pressUpX3", "device.pressUpX3", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressUpX3" } standardTile("pressDownX1", "device.pressDownX1", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressDownX1" } standardTile("pressDownX2", "device.pressDownX2", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressDownX2" } standardTile("pressDownX3", "device.pressDownX3", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressDownX3" } standardTile("pressUpX4", "device.pressUpX4", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressUpX4" } standardTile("pressUpX5", "device.pressUpX5", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressUpX5" } standardTile("holdUp", "device.holdUp", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "holdUp" } standardTile("pressDownX4", "device.pressDownX4", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressDownX4" } standardTile("pressDownX5", "device.pressDownX5", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "pressDownX5" } standardTile("holdDown", "device.holdDown", width: 2, height: 1, decoration: "flat") { state "default", label: '${currentValue}', backgroundColor: "#ffffff", action: "holdDown" } */ } } def generate_preferences() { getParameterNumbers().each { i -> switch(getParameterInfo(i, "type")) { case "number": input "parameter${i}", "number", title:getParameterInfo(i, "name") + "\n" + getParameterInfo(i, "description") + "\nRange: " + getParameterInfo(i, "options") + "\nDefault: " + getParameterInfo(i, "default"), range: getParameterInfo(i, "options") //defaultValue: getParameterInfo(i, "default") //displayDuringSetup: "${it.@displayDuringSetup}" break case "enum": input "parameter${i}", "enum", title:getParameterInfo(i, "name"), // + getParameterInfo(i, "description"), //defaultValue: getParameterInfo(i, "default"), //displayDuringSetup: "${it.@displayDuringSetup}", options: getParameterInfo(i, "options") break } if (i == 13){ input "parameter13custom", "number", title: "Custom LED RGB Value", 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.", required: false, range: "0..360" } } 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" [1,2,3,4,5].each { i -> input "parameter16-${i}a", "enum", title: "LED Effect Color - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [ 0:"Red", 21:"Orange", 42:"Yellow", 85:"Green", 127:"Cyan", 170:"Blue", 212:"Violet", 234:"Pink", 255:"White (Firmware 1.45+)"] input "parameter16-${i}b", "enum", title: "LED Effect Level - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [ 0:"0%", 1:"10%", 2:"20%", 3:"30%", 4:"40%", 5:"50%", 6:"60%", 7:"70%", 8:"80%", 9:"90%", 10:"100%"] input "parameter16-${i}c", "enum", title: "LED Effect Duration - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [ 255:"Indefinitely", 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", 11:"11 Seconds", 12:"12 Seconds", 13:"13 Seconds", 14:"14 Seconds", 15:"15 Seconds", 16:"16 Seconds", 17:"17 Seconds", 18:"18 Seconds", 19:"19 Seconds", 20:"20 Seconds", 21:"21 Seconds", 22:"22 Seconds", 23:"23 Seconds", 24:"24 Seconds", 25:"25 Seconds", 26:"26 Seconds", 27:"27 Seconds", 28:"28 Seconds", 29:"29 Seconds", 30:"30 Seconds", 31:"31 Seconds", 32:"32 Seconds", 33:"33 Seconds", 34:"34 Seconds", 35:"35 Seconds", 36:"36 Seconds", 37:"37 Seconds", 38:"38 Seconds", 39:"39 Seconds", 40:"40 Seconds", 41:"41 Seconds", 42:"42 Seconds", 43:"43 Seconds", 44:"44 Seconds", 45:"45 Seconds", 46:"46 Seconds", 47:"47 Seconds", 48:"48 Seconds", 49:"49 Seconds", 50:"50 Seconds", 51:"51 Seconds", 52:"52 Seconds", 53:"53 Seconds", 54:"54 Seconds", 55:"55 Seconds", 56:"56 Seconds", 57:"57 Seconds", 58:"58 Seconds", 59:"59 Seconds", 61:"1 Minute", 62:"2 Minutes", 63:"3 Minutes", 64:"4 Minutes", 65:"5 Minutes", 66:"6 Minutes", 67:"7 Minutes", 68:"8 Minutes", 69:"9 Minutes", 70:"10 Minutes", 71:"11 Minutes", 72:"12 Minutes", 73:"13 Minutes", 74:"14 Minutes", 75:"15 Minutes", 76:"16 Minutes", 77:"17 Minutes", 78:"18 Minutes", 79:"19 Minutes", 80:"20 Minutes", 81:"21 Minutes", 82:"22 Minutes", 83:"23 Minutes", 84:"24 Minutes", 85:"25 Minutes", 86:"26 Minutes", 87:"27 Minutes", 88:"28 Minutes", 89:"29 Minutes", 90:"30 Minutes", 91:"31 Minutes", 92:"32 Minutes", 93:"33 Minutes", 94:"34 Minutes", 95:"35 Minutes", 96:"36 Minutes", 97:"37 Minutes", 98:"38 Minutes", 99:"39 Minutes", 100:"40 Minutes", 101:"41 Minutes", 102:"42 Minutes", 103:"43 Minutes", 104:"44 Minutes", 105:"45 Minutes", 106:"46 Minutes", 107:"47 Minutes", 108:"48 Minutes", 109:"49 Minutes", 110:"50 Minutes", 111:"51 Minutes", 112:"52 Minutes", 113:"53 Minutes", 114:"54 Minutes", 115:"55 Minutes", 116:"56 Minutes", 117:"57 Minutes", 118:"58 Minutes", 119:"59 Minutes", 121:"1 Hour", 122:"2 Hours", 123:"3 Hours", 124:"4 Hours", 125:"5 Hours", 126:"6 Hours", 127:"7 Hours", 128:"8 Hours", 129:"9 Hours", 130:"10 Hours", 131:"11 Hours", 132:"12 Hours", 133:"13 Hours", 134:"14 Hours", 135:"15 Hours", 136:"16 Hours", 137:"17 Hours", 138:"18 Hours", 139:"19 Hours", 140:"20 Hours", 141:"21 Hours", 142:"22 Hours", 143:"23 Hours", 144:"24 Hours", 145:"25 Hours", 146:"26 Hours", 147:"27 Hours", 148:"28 Hours", 149:"29 Hours", 150:"30 Hours", 151:"31 Hours", 152:"32 Hours", 153:"33 Hours", 154:"34 Hours", 155:"35 Hours", 156:"36 Hours", 157:"37 Hours", 158:"38 Hours", 159:"39 Hours", 160:"40 Hours", 161:"41 Hours", 162:"42 Hours", 163:"43 Hours", 164:"44 Hours", 165:"45 Hours", 166:"46 Hours", 167:"47 Hours", 168:"48 Hours", 169:"49 Hours", 170:"50 Hours", 171:"51 Hours", 172:"52 Hours", 173:"53 Hours", 174:"54 Hours", 175:"55 Hours", 176:"56 Hours", 177:"57 Hours", 178:"58 Hours", 179:"59 Hours", 180:"60 Hours", 181:"61 Hours", 182:"62 Hours", 183:"63 Hours", 184:"64 Hours", 185:"65 Hours", 186:"66 Hours", 187:"67 Hours", 188:"68 Hours", 189:"69 Hours", 190:"70 Hours", 191:"71 Hours", 192:"72 Hours", 193:"73 Hours", 194:"74 Hours", 195:"75 Hours", 196:"76 Hours", 197:"77 Hours", 198:"78 Hours", 199:"79 Hours", 200:"80 Hours", 201:"81 Hours", 202:"82 Hours", 203:"83 Hours", 204:"84 Hours", 205:"85 Hours", 206:"86 Hours", 207:"87 Hours", 208:"88 Hours", 209:"89 Hours", 210:"90 Hours", 211:"91 Hours", 212:"92 Hours", 213:"93 Hours", 214:"94 Hours", 215:"95 Hours", 216:"96 Hours", 217:"97 Hours", 218:"98 Hours", 219:"99 Hours", 220:"100 Hours", 221:"101 Hours", 222:"102 Hours", 223:"103 Hours", 224:"104 Hours", 225:"105 Hours", 226:"106 Hours", 227:"107 Hours", 228:"108 Hours", 229:"109 Hours", 230:"110 Hours", 231:"111 Hours", 232:"112 Hours", 233:"113 Hours", 234:"114 Hours", 235:"115 Hours", 236:"116 Hours", 237:"117 Hours", 238:"118 Hours", 239:"119 Hours", 240:"120 Hours", 241:"121 Hours", 242:"122 Hours", 243:"123 Hours", 244:"124 Hours", 245:"125 Hours", 246:"126 Hours", 247:"127 Hours", 248:"128 Hours", 249:"129 Hours", 250:"130 Hours", 251:"131 Hours", 252:"132 Hours", 253:"133 Hours", 254:"134 Hours"] input "parameter16-${i}d", "enum", title: "LED Effect Type - Notification $i", description: "Tap to set", displayDuringSetup: false, required: false, options: [ 0:"Off", 1:"Solid", 2:"Chase", 3:"Fast Blink", 4:"Slow Blink", 5:"Pulse"] } 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" input "disableRemote", "enum", title: "Disable Remote Control", description: "\nDisable ability to control switch from inside SmartThings", required: false, options:["1": "Yes", "0": "No"], defaultValue: "0" 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" input "enableDisableLocalChild", "boolean", title: "Create \"Disable Local Control\" Child Device", description: "", required: false, defaultValue: "false" input "enableDisableRemoteChild", "boolean", title: "Create \"Disable Remote Control\" Child Device", description: "", required: false, defaultValue: "false" input "enableDefaultLocalChild", "boolean", title: "Create \"Default Level (Local)\" Child Device", description: "", required: false, defaultValue: "false" input "enableDefaultZWaveChild", "boolean", title: "Create \"Default Level (Z-Wave)\" Child Device", description: "", required: false, defaultValue: "false" input "enableLED1Child", "boolean", title: "Create \"Light LED\" Child Device", description: "", required: false, defaultValue: "false" input "enableLED1OffChild", "boolean", title: "Create \"Light LED When Off\" Child Device", description: "", required: false, defaultValue: "false" input name: "debugEnable", type: "boolean", title: "Enable Debug Logging", defaultValue: "true" input name: "infoEnable", type: "boolean", title: "Enable Informational Logging", defaultValue: "true" } private channelNumber(String dni) { dni.split("-ep")[-1] as Integer } def logsOff(){ log.warn "${device.label?device.label:device.name}: Disabling logging after timeout" //device.updateSetting("debugEnable",[value:"false",type:"boolean"]) //device.updateSetting("infoEnable",[value:"false",type:"boolean"]) } private sendAlert(data) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Error while creating child device" sendEvent( descriptionText: data.message, eventType: "ALERT", name: "failedOperation", value: "failed", displayed: true, ) } private toggleTiles(number, value) { for (int i = 1; i <= 5; i++){ if ("${i}" != number){ def childDevice = childDevices.find{it.deviceNetworkId == "$device.deviceNetworkId-ep$i"} if (childDevice) { childDevice.sendEvent(name: "switch", value: "off") } } else { def childDevice = childDevices.find{it.deviceNetworkId == "$device.deviceNetworkId-ep$i"} if (childDevice) { childDevice.sendEvent(name: "switch", value: value) } } } } def startNotification(value, ep = null){ if (infoEnable != "false") log.info "${device.label?device.label:device.name}: startNotification($value)" def parameterNumbers = [16] def cmds = [] cmds << zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(value.toInteger(),4), parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1], size: 4) cmds << zwave.configurationV1.configurationGet(parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1]) return commands(cmds) } def stopNotification(ep = null){ if (infoEnable != "false") log.info "${device.label?device.label:device.name}: stopNotification()" def parameterNumbers = [16] def cmds = [] cmds << zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(0,4), parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1], size: 4) cmds << zwave.configurationV1.configurationGet(parameterNumber: parameterNumbers[(ep == null)? 0:ep?.toInteger()-1]) return commands(cmds) } def setColor(value) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: setColor($value)" if (value.hue == null || value.saturation == null) return def ledColor = Math.round(huePercentToZwaveValue(value.hue)) if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Setting LED color value to $ledColor & LED intensity to $ledLevel" def cmds = [] if (value.level != null) { def ledLevel = Math.round(value.level/10) cmds << setParameter(14, ledLevel, 1) cmds << getParameter(14) } cmds << setParameter(13, ledColor, 2) cmds << getParameter(13) return commands(cmds) } private huePercentToValue(value){ return value<=2?0:(value>=98?360:value/100*360) } private hueValueToZwaveValue(value){ return value<=2?0:(value>=356?255:value/360*255) } private huePercentToZwaveValue(value){ return value<=2?0:(value>=98?255:value/100*255) } private zwaveValueToHueValue(value){ return value<=2?0:(value>=254?360:value/255*360) } private zwaveValueToHuePercent(value){ return value<=2?0:(value>=254?100:value/255*100) } def childSetLevel(String dni, value) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: childSetLevel($dni, $value)" state.lastRan = now() def valueaux = value as Integer def level = Math.max(Math.min(valueaux, 99), 0) def cmds = [] switch (channelNumber(dni)) { case 9: cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1) )) cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni) ))) break case 10: cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationSet(scaledConfigurationValue: value, parameterNumber: channelNumber(dni), size: 1) )) cmds << new physicalgraph.device.HubAction(command(zwave.configurationV1.configurationGet(parameterNumber: channelNumber(dni) ))) break case 101: cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionSet(localProtectionState : level > 0 ? 1 : 0, rfProtectionState: state.rfProtectionState? state.rfProtectionState:0) )) cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionGet() )) break case 102: cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionSet(localProtectionState : state.localProtectionState? state.localProtectionState:0, rfProtectionState : level > 0 ? 1 : 0) )) cmds << new physicalgraph.device.HubAction(command(zwave.protectionV2.protectionGet() )) break case 103: cmds << setParameter(ledIntensityEndpoints[channelNumber(dni)], Math.round(level/10), 1) cmds << getParameter(ledIntensityEndpoints[channelNumber(dni)]) break case 104: cmds << setParameter(ledIntensityOffEndpoints[channelNumber(dni)], Math.round(level/10), 1) cmds << getParameter(ledIntensityOffEndpoints[channelNumber(dni)]) break } sendHubCommand(cmds, 1000) } def childOn(String dni) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: childOn($dni)" state.lastRan = now() def cmds = [] if(channelNumber(dni).toInteger() <= 5) { toggleTiles("${channelNumber(dni)}", "on") cmds << new physicalgraph.device.HubAction(command(setParameter(16, calculateParameter("16-${channelNumber(dni)}"), 4))) sendHubCommand(cmds, 1000) } else { childSetLevel(dni, 99) } } def childOff(String dni) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: childOff($dni)" state.lastRan = now() def cmds = [] if(channelNumber(dni).toInteger() <= 5) { toggleTiles("${channelNumber(dni)}", "off") cmds << new physicalgraph.device.HubAction(command(setParameter(16, 0, 4))) sendHubCommand(cmds, 1000) } else { childSetLevel(dni, 0) } } void childRefresh(String dni) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: childRefresh($dni)" } def childExists(ep) { def children = childDevices def childDevice = children.find{it.deviceNetworkId.endsWith(ep)} if (childDevice) return true else return false } void componentSetColor(dni, value) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: dni, componentSetColor($value)" if (value.hue == null || value.saturation == null) return def ledColor = Math.round(huePercentToZwaveValue(value.hue)) state.lastRan = now() if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Setting LED color value to $ledColor & LED intensity to $ledLevel" def cmds = [] if (value.level != null) { def ledLevel = Math.round(value.level/10) cmds << setParameter(ledIntensityEndpoints[channelNumber(dni)], ledLevel, 1) cmds << getParameter(ledIntensityEndpoints[channelNumber(dni)]) } cmds << setParameter(ledColorEndpoints[channelNumber(dni)], ledColor, 2) cmds << getParameter(ledColorEndpoints[channelNumber(dni)]) if(cmds) sendHubCommand(commands(cmds)) } void componentSetColorTemperature(dni, value) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: dni, componentSetColorTemperature($value)" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Setting LED color value to 255" state.lastRan = now() state.colorTemperature = value def cmds = [] cmds << setParameter(ledColorEndpoints[channelNumber(dni)], 255, 2) cmds << getParameter(ledColorEndpoints[channelNumber(dni)]) if(cmds) sendHubCommand(commands(cmds)) } def installed() { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: installed()" refresh() } def configure() { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: configure()" def cmds = initialize() commands(cmds) } def updated() { if (!state.lastRan || now() >= state.lastRan + 2000) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: updated()" if (debugEnable || infoEnable) runIn(1800,logsOff) state.lastRan = now() def cmds = initialize() if (cmds != []) response(commands(cmds, 1000)) else return null } else { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: updated() ran within the last 2 seconds. Skipping execution." } } private addChild(id, label, namespace, driver, isComponent){ if(!childExists(id)){ try { def newChild = addChildDevice(namespace, driver, "${device.deviceNetworkId}-${id}", null, [completedSetup: true, label: "${device.displayName} (${label})", isComponent: isComponent]) newChild.sendEvent(name:"switch", value:"off") } catch (e) { runIn(3, "sendAlert", [data: [message: "Child device creation failed. Make sure the device handler for \"${driver}\" with a namespace of ${namespace} is installed"]]) } } } private deleteChild(id){ if(childExists(id)){ def childDevice = childDevices.find{it.deviceNetworkId.endsWith(id)} try { if(childDevice) deleteChildDevice(childDevice.deviceNetworkId) } catch (e) { if (infoEnable != "false") log.info "SmartThings may have issues trying to delete the child device when it is in use. Need to manually delete them." runIn(3, "sendAlert", [data: [message: "Failed to delete child device. Make sure the device is not in use by any SmartApp."]]) } } } def initialize() { sendEvent(name: "checkInterval", value: 3 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"]) sendEvent(name: "numberOfButtons", value: 8, displayed: true) if (!device.currentValue("supportedButtonValues")) { sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false) } if (enableDefaultLocalChild == "true") addChild("ep9", "Default Local Level", "InovelliUSA", "Switch Level Child Device", false) else deleteChild("ep9") if (enableDefaultZWaveChild == "true") addChild("ep10", "Default Z-Wave Level", "InovelliUSA", "Switch Level Child Device", false) else deleteChild("ep10") if (enableDisableLocalChild == "true") addChild("ep101", "Disable Local Control", "smartthings", "Child Switch", false) else deleteChild("ep101") if (enableDisableRemoteChild == "true") addChild("ep102", "Disable Remote Control", "smartthings", "Child Switch", false) else deleteChild("ep102") if (enableLED1Child == "true") addChild("ep103", "Light LED", "InovelliUSA", "RGBW Child Device", false) else deleteChild("ep103") if (enableLED1OffChild == "true") addChild("ep104", "Light LED - When Off", "InovelliUSA", "Switch Level Child Device", false) else deleteChild("ep104") [1,2,3,4,5].each { i -> 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}")) { addChild("ep${i}", "Notification ${i}", "smartthings", "Child Switch", false) } 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}")) { deleteChild("ep${i}") } } if (device.label != state.oldLabel) { def children = childDevices def childDevice = children.find{it.deviceNetworkId.endsWith("ep1")} if (childDevice) childDevice.setLabel("${device.displayName} (Notification 1)") childDevice = children.find{it.deviceNetworkId.endsWith("ep2")} if (childDevice) childDevice.setLabel("${device.displayName} (Notification 2)") childDevice = children.find{it.deviceNetworkId.endsWith("ep3")} if (childDevice) childDevice.setLabel("${device.displayName} (Notification 3)") childDevice = children.find{it.deviceNetworkId.endsWith("ep4")} if (childDevice) childDevice.setLabel("${device.displayName} (Notification 4)") childDevice = children.find{it.deviceNetworkId.endsWith("ep5")} if (childDevice) childDevice.setLabel("${device.displayName} (Notification 5)") childDevice = children.find{it.deviceNetworkId.endsWith("ep9")} if (childDevice) childDevice.setLabel("${device.displayName} (Default Local Level)") childDevice = children.find{it.deviceNetworkId.endsWith("ep10")} if (childDevice) childDevice.setLabel("${device.displayName} (Default Z-Wave Level)") childDevice = children.find{it.deviceNetworkId.endsWith("ep101")} if (childDevice) childDevice.setLabel("${device.displayName} (Disable Local Control)") childDevice = children.find{it.deviceNetworkId.endsWith("ep102")} if (childDevice) childDevice.setLabel("${device.displayName} (Disable Remote Control)") } state.oldLabel = device.label /* sendEvent([name:"pressUpX1", value:pressUpX1Label? "${pressUpX1Label} ▲" : "Tap ▲", displayed: false]) sendEvent([name:"pressDownX1", value:pressDownX1Label? "${pressDownX1Label} ▼" : "Tap ▼", displayed: false]) sendEvent([name:"pressUpX2", value:pressUpX2Label? "${pressUpX2Label} ▲▲" : "Tap ▲▲", displayed: false]) sendEvent([name:"pressDownX2", value:pressDownX2Label? "${pressDownX2Label} ▼▼" : "Tap ▼▼", displayed: false]) sendEvent([name:"pressUpX3", value:pressUpX3Label? "${pressUpX3Label} ▲▲▲" : "Tap ▲▲▲", displayed: false]) sendEvent([name:"pressDownX3", value:pressDownX3Label? "${pressDownX3Label} ▼▼▼" : "Tap ▼▼▼", displayed: false]) sendEvent([name:"pressUpX4", value:pressUpX4Label? "${pressUpX4Label} ▲▲▲▲" : "Tap ▲▲▲▲", displayed: false]) sendEvent([name:"pressDownX4", value:pressDownX4Label? "${pressDownX4Label} ▼▼▼▼" : "Tap ▼▼▼▼", displayed: false]) sendEvent([name:"pressUpX5", value:pressUpX5Label? "${pressUpX5Label} ▲▲▲▲▲" : "Tap ▲▲▲▲▲", displayed: false]) sendEvent([name:"pressDownX5", value:pressDownX5Label? "${pressDownX5Label} ▼▼▼▼▼" : "Tap ▼▼▼▼▼", displayed: false]) sendEvent([name:"holdUp", value:pressHoldUpLabel? "${pressHoldUpLabel} ▲" : "Hold ▲", displayed: false]) sendEvent([name:"holdDown", value:pressHoldDownLabel? "${pressHoldDownLabel} ▼" : "Hold ▼", displayed: false]) */ def cmds = processAssociations() getParameterNumbers().each{ i -> if ((state."parameter${i}value" != ((settings."parameter${i}"!=null||calculateParameter(i)!=null)? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger()))){ //if (infoEnable != "false") log.info "Parameter $i is not set correctly. Setting it to ${settings."parameter${i}"!=null? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger()}." cmds << setParameter(i, (settings."parameter${i}"!=null||calculateParameter(i)!=null)? calculateParameter(i).toInteger() : getParameterInfo(i, "default").toInteger(), getParameterInfo(i, "size").toInteger()) cmds << getParameter(i) } else { //if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Parameter $i already set" } } cmds << zwave.versionV1.versionGet() if (state.localProtectionState?.toInteger() != settings.disableLocal?.toInteger() || state.rfProtectionState?.toInteger() != settings.disableRemote?.toInteger()) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Protection command class settings need to be updated" cmds << zwave.protectionV2.protectionSet(localProtectionState : disableLocal!=null? disableLocal.toInteger() : 0, rfProtectionState: disableRemote!=null? disableRemote.toInteger() : 0) cmds << zwave.protectionV2.protectionGet() } else { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: No Protection command class settings to update" } if (cmds != []) return cmds else return [] } def calculateParameter(number) { def value = 0 switch (number){ case "13": if (settings.parameter13custom =~ /^([0-9]{1}|[0-9]{2}|[0-9]{3})$/) value = hueValueToZwaveValue(settings.parameter13custom.toInteger()) else value = settings."parameter${number}" break case "16-1": case "16-2": case "16-3": case "16-4": case "16-5": value += settings."parameter${number}a"!=null ? settings."parameter${number}a".toInteger() * 1 : 0 value += settings."parameter${number}b"!=null ? settings."parameter${number}b".toInteger() * 256 : 0 value += settings."parameter${number}c"!=null ? settings."parameter${number}c".toInteger() * 65536 : 0 value += settings."parameter${number}d"!=null ? settings."parameter${number}d".toInteger() * 16777216 : 0 break default: value = settings."parameter${number}" break } return value } def setParameter(number, value, size) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Setting parameter $number with a size of $size bytes to $value" return zwave.configurationV1.configurationSet(configurationValue: integer2Cmd(value.toInteger(),size), parameterNumber: number, size: size) } def getParameter(number) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Retreiving value of parameter $number" return zwave.configurationV1.configurationGet(parameterNumber: number) } def getParameterNumbers(){ 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] } def getParameterInfo(number, value){ def parameter = [:] parameter.parameter1default=3 parameter.parameter2default=101 parameter.parameter3default=101 parameter.parameter4default=101 parameter.parameter5default=10 parameter.parameter6default=99 parameter.parameter7default=0 parameter.parameter8default=0 parameter.parameter9default=0 parameter.parameter10default=0 parameter.parameter11default=100 parameter.parameter12default=15 parameter.parameter13default=170 parameter.parameter14default=5 parameter.parameter15default=1 parameter.parameter16default=0 parameter.parameter17default=3 parameter.parameter18default=10 parameter.parameter19default=3600 parameter.parameter20default=10 parameter.parameter21default=1 parameter.parameter22default=0 parameter.parameter50default=7 parameter.parameter51default=1 parameter.parameter52default=0 parameter.parameter1type="number" parameter.parameter2type="number" parameter.parameter3type="number" parameter.parameter4type="number" parameter.parameter5type="number" parameter.parameter6type="number" parameter.parameter7type="enum" parameter.parameter8type="number" parameter.parameter9type="number" parameter.parameter10type="number" parameter.parameter11type="number" parameter.parameter12type="number" parameter.parameter13type="enum" parameter.parameter14type="enum" parameter.parameter15type="enum" parameter.parameter16type="enum" parameter.parameter17type="enum" parameter.parameter18type="number" parameter.parameter19type="number" parameter.parameter20type="number" parameter.parameter21type="enum" parameter.parameter22type="enum" parameter.parameter50type="enum" parameter.parameter51type="enum" parameter.parameter52type="enum" parameter.parameter1size=1 parameter.parameter2size=1 parameter.parameter3size=1 parameter.parameter4size=1 parameter.parameter5size=1 parameter.parameter6size=1 parameter.parameter7size=1 parameter.parameter8size=2 parameter.parameter9size=1 parameter.parameter10size=1 parameter.parameter11size=1 parameter.parameter12size=1 parameter.parameter13size=2 parameter.parameter14size=1 parameter.parameter15size=1 parameter.parameter16size=4 parameter.parameter17size=1 parameter.parameter18size=1 parameter.parameter19size=2 parameter.parameter20size=1 parameter.parameter21size=1 parameter.parameter22size=1 parameter.parameter50size=1 parameter.parameter51size=1 parameter.parameter52size=1 parameter.parameter1options="0..100" parameter.parameter2options="0..101" parameter.parameter3options="0..101" parameter.parameter4options="0..101" parameter.parameter5options="1..45" parameter.parameter6options="55..99" parameter.parameter7options=["1":"Yes", "0":"No"] parameter.parameter8options="0..32767" parameter.parameter9options="0..99" parameter.parameter10options="0..99" parameter.parameter11options="0..100" parameter.parameter12options="0..15" parameter.parameter13options=["0":"Red","21":"Orange","42":"Yellow","85":"Green","127":"Cyan","170":"Blue","212":"Violet","234":"Pink","255":"White (Firmware 1.45+)"] parameter.parameter14options=["0":"0%","1":"10%","2":"20%","3":"30%","4":"40%","5":"50%","6":"60%","7":"70%","8":"80%","9":"90%","10":"100%"] parameter.parameter15options=["0":"0%","1":"10%","2":"20%","3":"30%","4":"40%","5":"50%","6":"60%","7":"70%","8":"80%","9":"90%","10":"100%"] parameter.parameter16options=["1":"Yes", "2":"No"] 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"] parameter.parameter18options="0..100" parameter.parameter19options="0..32767" parameter.parameter20options="0..100" parameter.parameter21options=["0":"Non Neutral", "1":"Neutral"] parameter.parameter22options=["0":"Load Only", "1":"3-way Toggle", "2":"3-way Momentary"] parameter.parameter50options=["1":"100ms", "2":"200ms", "3":"300ms", "4":"400ms", "5":"500ms", "6":"600ms", "7":"700ms", "8":"800ms", "9":"900ms"] parameter.parameter51options=["1":"No (Default)", "0":"Yes"] parameter.parameter52options=["0":"Disabled", "1":"On / Off Only", "2":"Smart Bulb"] parameter.parameter1name="Dimming Speed" parameter.parameter2name="Dimming Speed (From Switch)" parameter.parameter3name="Ramp Rate" parameter.parameter4name="Ramp Rate (From Switch)" parameter.parameter5name="Minimum Level" parameter.parameter6name="Maximum Level" parameter.parameter7name="Invert Switch" parameter.parameter8name="Auto Off Timer" parameter.parameter9name="Default Level (Local)" parameter.parameter10name="Default Level (Z-Wave)" parameter.parameter11name="State After Power Restored" parameter.parameter12name="Association Behavior" parameter.parameter13name="LED Strip Color" parameter.parameter14name="LED Strip Intensity" parameter.parameter15name="LED Strip Intensity (When OFF)" parameter.parameter16name="LED Strip Effect" parameter.parameter17name="LED Strip Timeout" parameter.parameter18name="Active Power Reports" parameter.parameter19name="Periodic Power & Energy Reports" parameter.parameter20name="Energy Reports" parameter.parameter21name="AC Power Type" parameter.parameter22name="Switch Type" parameter.parameter50name="Configure Physical On/Off Delay" parameter.parameter51name="Disable Physical On/Off Delay" parameter.parameter52name="Smart Bulb Mode" 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." 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." 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." 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." 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." 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." parameter.parameter7description="Inverts the orientation of the switch. Useful when the switch is installed upside down. Essentially up becomes down and down becomes up." 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." 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." 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." parameter.parameter11description="The state the switch should return to once power is restored after power failure. 0 = off, 1-99 = level, 100=previous." 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" parameter.parameter13description="This is the color of the LED strip." parameter.parameter14description="This is the intensity of the LED strip." 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." parameter.parameter16description="LED Strip Effect" 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." 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." parameter.parameter19description="Time period between consecutive power & energy reports being sent (in seconds). The timer is reset after each report is sent." 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." parameter.parameter21description="Configure the switch to use a neutral wire." parameter.parameter22description="Configure the type of 3-way switch connected to the dimmer." parameter.parameter50description="Configure delay that occurs after pressing physical button" 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+)" 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+)" return parameter."parameter${number}${value}" } def zwaveEvent(physicalgraph.zwave.commands.meterv3.MeterReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" def event if (cmd.scale == 0) { if (cmd.meterType == 161) { event = createEvent(name: "voltage", value: cmd.scaledMeterValue, unit: "V") if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Voltage report received with value of ${cmd.scaledMeterValue} V" } else if (cmd.meterType == 1) { event = createEvent(name: "energy", value: cmd.scaledMeterValue, unit: "kWh") if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Energy report received with value of ${cmd.scaledMeterValue} kWh" } } else if (cmd.scale == 1) { event = createEvent(name: "amperage", value: cmd.scaledMeterValue, unit: "A") if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Amperage report received with value of ${cmd.scaledMeterValue} A" } else if (cmd.scale == 2) { event = createEvent(name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W") if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Power report received with value of ${cmd.scaledMeterValue} W" } return event } def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: parameter '${cmd.parameterNumber}' with a byte size of '${cmd.size}' is set to '${cmd2Integer(cmd.configurationValue)}'" if (!state.lastRan || now() <= state.lastRan + 60000) { state."parameter${cmd.parameterNumber}value" = cmd2Integer(cmd.configurationValue) } else { if (infoEnable != "false") log.debug "${device.label?device.label:device.name}: Configuration report received more than 60 seconds after running updated(). Possible configuration made at switch" } def integerValue = cmd2Integer(cmd.configurationValue) switch (cmd.parameterNumber) { case 9: def children = childDevices def childDevice = children.find{it.deviceNetworkId.endsWith("ep9")} if (childDevice) { childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off") childDevice.sendEvent(name: "level", value: integerValue) } break case 10: def children = childDevices def childDevice = children.find{it.deviceNetworkId.endsWith("ep10")} if (childDevice) { childDevice.sendEvent(name: "switch", value: integerValue > 0 ? "on" : "off") childDevice.sendEvent(name: "level", value: integerValue) } break case 12: def childDevice = childDevices.find{it.deviceNetworkId == "$device.deviceNetworkId-ep1${cmd.parameterNumber}"} if(childDevice) { childDevice.sendEvent(name:"switch", value:cmd.scaledConfigurationValue? "on":"off") childDevice.sendEvent(name:"level", value:cmd.scaledConfigurationValue) } break case 13: def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep${ledColorEndpoints.find { it.value == cmd.parameterNumber }?.key}")} if (childDevice) { if (integerValue == 255) { childDevice.sendEvent(name: "colorTemperature", value: state.colorTemperature?state.colorTemperature:0) childDevice.sendEvent(name: "colorMode", value: "CT", descriptionText: "${device.getDisplayName()} color mode is CT") } else { childDevice.sendEvent(name:"hue", value:"${Math.round(zwaveValueToHuePercent(integerValue))}") childDevice.sendEvent(name:"saturation", value:"100") childDevice.sendEvent(name: "colorMode", value: "RGB", descriptionText: "${device.getDisplayName()} color mode is RGB") } } break case 14: def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep${ledIntensityEndpoints.find { it.value == cmd.parameterNumber }?.key}")} if (childDevice) { childDevice.sendEvent(name:"level", value:"${integerValue*10}") childDevice.sendEvent(name:"switch", value:"${integerValue==0?"off":"on"}") } break case 15: def childDevice = childDevices.find{it.deviceNetworkId.endsWith("ep${ledIntensityOffEndpoints.find { it.value == cmd.parameterNumber }?.key}")} if (childDevice) { childDevice.sendEvent(name:"level", value:"${integerValue*10}") childDevice.sendEvent(name:"switch", value:"${integerValue==0?"off":"on"}") } break } } def cmd2Integer(array) { switch(array.size()) { case 1: array[0] break case 2: ((array[0] & 0xFF) << 8) | (array[1] & 0xFF) break case 3: ((array[0] & 0xFF) << 16) | ((array[1] & 0xFF) << 8) | (array[2] & 0xFF) break case 4: ((array[0] & 0xFF) << 24) | ((array[1] & 0xFF) << 16) | ((array[2] & 0xFF) << 8) | (array[3] & 0xFF) break } } def integer2Cmd(value, size) { try{ switch(size) { case 1: [value] break case 2: def short value1 = value & 0xFF def short value2 = (value >> 8) & 0xFF [value2, value1] break case 3: def short value1 = value & 0xFF def short value2 = (value >> 8) & 0xFF def short value3 = (value >> 16) & 0xFF [value3, value2, value1] break case 4: def short value1 = value & 0xFF def short value2 = (value >> 8) & 0xFF def short value3 = (value >> 16) & 0xFF def short value4 = (value >> 24) & 0xFF [value4, value3, value2, value1] break } } catch (e) { if (debugEnable != "false") log.debug "Error: integer2Cmd $e Value: $value" } } private getCommandClassVersions() { [0x20: 1, 0x25: 1, 0x70: 1, 0x98: 1, 0x32: 3, 0x5B: 1] } def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) { def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions) if (encapsulatedCommand) { state.sec = 1 zwaveEvent(encapsulatedCommand) } } def parse(description) { def result = null if (description.startsWith("Err 106")) { state.sec = 0 result = createEvent(descriptionText: description, isStateChange: true) } else if (description != "updated") { def cmd = zwave.parse(description, commandClassVersions) if (cmd) { result = zwaveEvent(cmd) //log.debug("'$cmd' parsed to $result") } else { if (debugEnable != "false") log.debug "Couldn't zwave.parse '$description'" } } def now if(location.timeZone) now = new Date().format("yyyy MMM dd EEE h:mm:ss a", location.timeZone) else now = new Date().format("yyyy MMM dd EEE h:mm:ss a") sendEvent(name: "lastActivity", value: now, displayed:false) if (!device.currentValue("supportedButtonValues")) { sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false) } result } def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Basic report received with value of ${cmd.value ? "on" : "off"} ($cmd.value)" dimmerEvents(cmd, (!state.lastRan || now() <= state.lastRan + 5000)?"digital":"physical") } def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Basic set received with value of ${cmd.value ? "on" : "off"}" dimmerEvents(cmd) } def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Switch Binary report received with value of ${cmd.value ? "on" : "off"}" dimmerEvents(cmd) } def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Switch Multilevel report received with value of ${cmd.value ? "on" : "off"} ($cmd.value)" dimmerEvents(cmd, (!state.lastRan || now() <= state.lastRan + 5000)?"digital":"physical") } private dimmerEvents(physicalgraph.zwave.Command cmd, type="physical") { def value = (cmd.value ? "on" : "off") def result = [createEvent(name: "switch", value: value, type: type)] if (cmd.value) { result << createEvent(name: "level", value: cmd.value, unit: "%", type: type) } return result } def zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" switch (cmd.keyAttributes) { case 0: if (cmd.sceneNumber == 3) buttonEvent(7, "pushed", "physical") else buttonEvent(cmd.keyAttributes + 1, (cmd.sceneNumber == 2? "pushed" : "held"), "physical") break case 1: if (cmd.sceneNumber == 3) buttonEvent(7, "released", "physical") else buttonEvent(6, (cmd.sceneNumber == 2? "pushed" : "held"), "physical") break case 2: if (cmd.sceneNumber == 3) buttonEvent(7, "held", "physical") else buttonEvent(8, (cmd.sceneNumber == 2? "pushed" : "held"), "physical") break default: if (cmd.sceneNumber == 3) buttonEvent(7, "held", "physical") else buttonEvent(cmd.keyAttributes - 1, (cmd.sceneNumber == 2? "pushed" : "held"), "physical") break } } def buttonEvent(button, value, type = "digital") { switch (button) { case 1: case 2: case 3: case 4: case 5: sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Tap '.padRight(button+5, '▼'):' Tap '.padRight(button+5, '▲')}", displayed:false) break case 6: sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Released ▼':' Released ▲'}", displayed:false) break case 8: sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Hold ▼':' Hold ▲'}", displayed:false) break } if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Button ${button} was ${value}" [name: "button", value: value, data: [buttonNumber: button], descriptionText: "$device.displayName button $button was $value", isStateChange: true, type: type] } def zwaveEvent(physicalgraph.zwave.Command cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: Unhandled: $cmd" null } def reset() { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Resetting energy statistics" def cmds = [] cmds << zwave.meterV2.meterReset() cmds << zwave.meterV2.meterGet(scale: 0) cmds << zwave.meterV2.meterGet(scale: 2) commands(cmds, 1000) } def on() { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: on()" state.lastRan = now() commands([ zwave.basicV1.basicSet(value: 0xFF) ]) } def off() { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: off()" state.lastRan = now() commands([ zwave.basicV1.basicSet(value: 0x00) ]) } def setLevel(value) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: setLevel($value)" state.lastRan = now() commands([ zwave.switchMultilevelV2.switchMultilevelSet(value: value < 100 ? value : 99) ]) } def setLevel(value, duration) { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: setLevel($value, $duration)" state.lastRan = now() def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60) commands([ zwave.switchMultilevelV2.switchMultilevelSet(value: value < 100 ? value : 99, dimmingDuration: dimmingDuration) ]) } def ping() { if (debugEnable != "false") log.debug "ping()" refresh() } def poll() { if (debugEnable != "false") log.debug "poll()" refresh() } def refresh() { if (debugEnable != "false") log.debug "refresh()" def cmds = [] cmds << zwave.switchMultilevelV1.switchMultilevelGet() cmds << zwave.meterV3.meterGet(scale: 0) cmds << zwave.meterV3.meterGet(scale: 2) return commands(cmds) } private command(physicalgraph.zwave.Command cmd) { if (getZwaveInfo()?.zw?.contains("s")) { zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format() } else { cmd.format() } } private commands(commands, delay=1000) { delayBetween(commands.collect{ command(it) }, delay) } def pressUpX1() { sendEvent(buttonEvent(1, "pushed")) } def pressDownX1() { sendEvent(buttonEvent(1, "held")) } def pressUpX2() { sendEvent(buttonEvent(2, "pushed")) } def pressDownX2() { sendEvent(buttonEvent(2, "held")) } def pressUpX3() { sendEvent(buttonEvent(3, "pushed")) } def pressDownX3() { sendEvent(buttonEvent(3, "held")) } def pressUpX4() { sendEvent(buttonEvent(4, "pushed")) } def pressDownX4() { sendEvent(buttonEvent(4, "held")) } def pressUpX5() { sendEvent(buttonEvent(5, "pushed")) } def pressDownX5() { sendEvent(buttonEvent(5, "held")) } def holdUp() { sendEvent(buttonEvent(6, "pushed")) } def holdDown() { sendEvent(buttonEvent(6, "held")) } def pressConfig() { sendEvent(buttonEvent(7, "pushed")) } def setDefaultAssociations() { def smartThingsHubID = (zwaveHubNodeId.toString().format( '%02x', zwaveHubNodeId )).toUpperCase() state.defaultG1 = [smartThingsHubID] state.defaultG2 = [] state.defaultG3 = [] } def setAssociationGroup(group, nodes, action, endpoint = null){ if (state."desiredAssociation${group}" == null) { state."desiredAssociation${group}" = nodes } else { switch (action) { case 0: state."desiredAssociation${group}" = state."desiredAssociation${group}" - nodes if (state."deleteAssociation${group}" == null) { state."deleteAssociation${group}" = nodes } else { state."deleteAssociation${group}" = state."deleteAssociation${group}" + nodes } break case 1: state."desiredAssociation${group}" = state."desiredAssociation${group}" + nodes state."deleteAssociation${group}" = state."deleteAssociation${group}" - nodes break } } } def processAssociations(){ def cmds = [] setDefaultAssociations() def associationGroups = 5 if (state.associationGroups) { associationGroups = state.associationGroups } else { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Getting supported association groups from device" cmds << zwave.associationV2.associationGroupingsGet() } for (int i = 1; i <= associationGroups; i++){ state."desiredAssociation${i}".each { cmds << zwave.associationV2.associationSet(groupingIdentifier:i, nodeId:Integer.parseInt(it,16)) cmds << zwave.associationV2.associationGet(groupingIdentifier:i) } state."deleteAssociation${i}".each { cmds << zwave.associationV2.associationRemove(groupingIdentifier:i, nodeId:Integer.parseInt(it,16)) cmds << zwave.associationV2.associationGet(groupingIdentifier:i) } /*if(state."actualAssociation${i}" != null){ if(state."desiredAssociation${i}" != null || state."defaultG${i}") { def refreshGroup = false ((state."desiredAssociation${i}"? state."desiredAssociation${i}" : [] + state."defaultG${i}") - state."actualAssociation${i}").each { if (it != null){ if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Adding node $it to group $i" cmds << zwave.associationV2.associationSet(groupingIdentifier:i, nodeId:Integer.parseInt(it,16)) refreshGroup = true } } ((state."actualAssociation${i}" - state."defaultG${i}") - state."desiredAssociation${i}").each { if (it != null){ if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Removing node $it from group $i" cmds << zwave.associationV2.associationRemove(groupingIdentifier:i, nodeId:Integer.parseInt(it,16)) refreshGroup = true } } if (refreshGroup == true) cmds << zwave.associationV2.associationGet(groupingIdentifier:i) else if (infoEnable != "false") log.info "${device.label?device.label:device.name}: There are no association actions to complete for group $i" } } else { if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Association info not known for group $i. Requesting info from device." cmds << zwave.associationV2.associationGet(groupingIdentifier:i) }*/ } return cmds } def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" def temp = [] if (cmd.nodeId != []) { cmd.nodeId.each { temp += it.toString().format( '%02x', it.toInteger() ).toUpperCase() } } state."actualAssociation${cmd.groupingIdentifier}" = temp if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Associations for Group ${cmd.groupingIdentifier}: ${temp}" updateDataValue("associationGroup${cmd.groupingIdentifier}", "$temp") } def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationGroupingsReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" sendEvent(name: "groups", value: cmd.supportedGroupings) if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Supported association groups: ${cmd.supportedGroupings}" state.associationGroups = cmd.supportedGroupings } def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${cmd}" if(cmd.applicationVersion != null && cmd.applicationSubVersion != null) { def firmware = "${cmd.applicationVersion}.${cmd.applicationSubVersion.toString().padLeft(2,'0')}" if (infoEnable != "false") log.info "${device.label?device.label:device.name}: Firmware report received: ${firmware}" state.needfwUpdate = "false" createEvent(name: "firmware", value: "${firmware}") } else if(cmd.firmware0Version != null && cmd.firmware0SubVersion != null) { def firmware = "${cmd.firmware0Version}.${cmd.firmware0SubVersion.toString().padLeft(2,'0')}" if (infoEnable != false) log.info "${device.label?device.label:device.name}: Firmware report received: ${firmware}" state.needfwUpdate = "false" createEvent(name: "firmware", value: "${firmware}") } } def zwaveEvent(physicalgraph.zwave.commands.protectionv2.ProtectionReport cmd) { if (debugEnable != "false") log.debug "${device.label?device.label:device.name}: ${device.label?device.label:device.name}: ${cmd}" if (infoEnable != "false") 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"}" if (!state.lastRan || now() <= state.lastRan + 60000) { state.localProtectionState = cmd.localProtectionState state.rfProtectionState = cmd.rfProtectionState } else { if (infoEnable != "false") log.debug "${device.label?device.label:device.name}: Protection report received more than 60 seconds after running updated(). Possible configuration made at switch" } //device.updateSetting("disableLocal",[value:cmd.localProtectionState?cmd.localProtectionState:0,type:"enum"]) //device.updateSetting("disableRemote",[value:cmd.rfProtectionState?cmd.rfProtectionState:0,type:"enum"]) def children = childDevices def childDevice = children.find{it.deviceNetworkId.endsWith("ep101")} if (childDevice) { childDevice.sendEvent(name: "switch", value: cmd.localProtectionState > 0 ? "on" : "off") } childDevice = children.find{it.deviceNetworkId.endsWith("ep102")} if (childDevice) { childDevice.sendEvent(name: "switch", value: cmd.rfProtectionState > 0 ? "on" : "off") } }