/** * Inovelli 2-Channel Smart Plug NZW37 w/Scene * Author: Eric Maycock (erocm123) * Date: 2018-06-13 * * Copyright 2018 Eric Maycock * * 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. * * 2018-06-13: Modified tile layout. Update firmware version reporting. * */ metadata { definition(name: "Inovelli 2-Channel Smart Plug NZW37 w/Scene", namespace: "InovelliUSA", author: "Eric Maycock", vid: "generic-switch") { capability "Actuator" capability "Sensor" capability "Switch" capability "Polling" capability "Refresh" //capability "Health Check" capability "Button" attribute "lastActivity", "String" attribute "lastEvent", "String" attribute "firmware", "String" command "pressUpX2" fingerprint manufacturer: "015D", prod: "2500", model: "2500", deviceJoinName: "Inovelli 2-Channel Smart Plug" fingerprint manufacturer: "0312", prod: "2500", model: "2500", deviceJoinName: "Inovelli 2-Channel Smart Plug" } simulator {} preferences { input "autoOff1", "number", title: "Auto Off Channel 1\n\nAutomatically turn switch off after this number of seconds\nRange: 0 to 32767", description: "Tap to set", required: false, range: "0..32767" input "autoOff2", "number", title: "Auto Off Channel 2\n\nAutomatically turn switch off after this number of seconds\nRange: 0 to 32767", description: "Tap to set", required: false, range: "0..32767" input "ledIndicator", "enum", title: "LED Indicator\n\nTurn LED indicator on when switch is:\n", description: "Tap to set", required: false, options:[["0": "On"], ["1": "Off"], ["2": "Disable"]], defaultValue: "0" input description: "1 pushed - Button 2x click", title: "Button Mappings", displayDuringSetup: false, type: "paragraph", element: "paragraph" } 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" } } childDeviceTiles("all") 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("info", "device.info", inactiveLabel: false, decoration: "flat", width: 3, height: 1) { state "default", label: 'Tap on the ▲▲ button below to test your scene' } valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 2, 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: 1, height: 1) { state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh" } standardTile("pressUpX2", "device.button", width: 6, height: 1, decoration: "flat") { state "default", label: "Tap ▲▲", backgroundColor: "#ffffff", action: "pressUpX2" } } } def parse(String description) { def result = [] def cmd = zwave.parse(description) if (cmd) { result += zwaveEvent(cmd) log.debug "Parsed ${cmd} to ${result.inspect()}" } else { log.debug "Non-parsed event: ${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) return result } def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, ep = null) { log.debug "BasicReport ${cmd} - ep ${ep}" if (ep) { def event childDevices.each { childDevice -> if (childDevice.deviceNetworkId == "$device.deviceNetworkId-ep$ep") { childDevice.sendEvent(name: "switch", value: cmd.value ? "on" : "off") } } if (cmd.value) { event = [createEvent([name: "switch", value: "on"])] } else { def allOff = true childDevices.each { n -> if (n.deviceNetworkId != "$device.deviceNetworkId-ep$ep" && n.currentState("switch").value != "off") allOff = false } if (allOff) { event = [createEvent([name: "switch", value: "off"])] } else { event = [createEvent([name: "switch", value: "on"])] } } return event } } def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) { log.debug "BasicSet ${cmd}" def result = createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital") def cmds = [] cmds << encap(zwave.switchBinaryV1.switchBinaryGet(), 1) cmds << encap(zwave.switchBinaryV1.switchBinaryGet(), 2) return [result, response(commands(cmds))] // returns the result of reponse() } def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd, ep = null) { log.debug "SwitchBinaryReport ${cmd} - ep ${ep}" if (ep) { def event def childDevice = childDevices.find { it.deviceNetworkId == "$device.deviceNetworkId-ep$ep" } if (childDevice) childDevice.sendEvent(name: "switch", value: cmd.value ? "on" : "off") if (cmd.value) { event = [createEvent([name: "switch", value: "on"])] } else { def allOff = true childDevices.each { n-> if (n.currentState("switch").value != "off") allOff = false } if (allOff) { event = [createEvent([name: "switch", value: "off"])] } else { event = [createEvent([name: "switch", value: "on"])] } } return event } else { def result = createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital") def cmds = [] cmds << encap(zwave.switchBinaryV1.switchBinaryGet(), 1) cmds << encap(zwave.switchBinaryV1.switchBinaryGet(), 2) return [result, response(commands(cmds))] // returns the result of reponse() } } def zwaveEvent(physicalgraph.zwave.commands.multichannelv3.MultiChannelCmdEncap cmd) { log.debug "MultiChannelCmdEncap ${cmd}" def encapsulatedCommand = cmd.encapsulatedCommand([0x32: 3, 0x25: 1, 0x20: 1]) if (encapsulatedCommand) { zwaveEvent(encapsulatedCommand, cmd.sourceEndPoint as Integer) } } def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) { log.debug "ManufacturerSpecificReport ${cmd}" def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId) log.debug "msr: $msr" updateDataValue("MSR", msr) } def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) { log.debug cmd if(cmd.applicationVersion && cmd.applicationSubVersion) { def firmware = "${cmd.applicationVersion}.${cmd.applicationSubVersion.toString().padLeft(2,'0')}" state.needfwUpdate = "false" createEvent(name: "firmware", value: "${firmware}") } } def zwaveEvent(physicalgraph.zwave.Command cmd) { // This will capture any commands not handled by other instances of zwaveEvent // and is recommended for development so you can see every command the device sends log.debug "Unhandled Event: ${cmd}" } def on() { log.debug "on()" commands([ zwave.switchAllV1.switchAllOn(), encap(zwave.switchBinaryV1.switchBinaryGet(), 1), encap(zwave.switchBinaryV1.switchBinaryGet(), 2) ]) } def off() { log.debug "off()" commands([ zwave.switchAllV1.switchAllOff(), encap(zwave.switchBinaryV1.switchBinaryGet(), 1), encap(zwave.switchBinaryV1.switchBinaryGet(), 2) ]) } void childOn(String dni) { log.debug "childOn($dni)" def cmds = [] cmds << new physicalgraph.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), channelNumber(dni)))) cmds << new physicalgraph.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), channelNumber(dni)))) sendHubCommand(cmds, 1000) } void childOff(String dni) { log.debug "childOff($dni)" def cmds = [] cmds << new physicalgraph.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0x00), channelNumber(dni)))) cmds << new physicalgraph.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), channelNumber(dni)))) sendHubCommand(cmds, 1000) } void childRefresh(String dni) { log.debug "childRefresh($dni)" def cmds = [] cmds << new physicalgraph.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), channelNumber(dni)))) sendHubCommand(cmds, 1000) } def poll() { log.debug "poll()" commands([ encap(zwave.switchBinaryV1.switchBinaryGet(), 1), encap(zwave.switchBinaryV1.switchBinaryGet(), 2), ]) } def refresh() { log.debug "refresh()" commands([ encap(zwave.switchBinaryV1.switchBinaryGet(), 1), encap(zwave.switchBinaryV1.switchBinaryGet(), 2), ]) } def ping() { log.debug "ping()" refresh() } def installed() { log.debug "installed()" command(zwave.manufacturerSpecificV1.manufacturerSpecificGet()) createChildDevices() } def updated() { log.debug "updated()" if (!childDevices) { createChildDevices() } else if (device.label != state.oldLabel) { childDevices.each { if (it.label == "${state.oldLabel} (CH${channelNumber(it.deviceNetworkId)})") { def newLabel = "${device.displayName} (CH${channelNumber(it.deviceNetworkId)})" it.setLabel(newLabel) } } state.oldLabel = device.label } sendEvent(name: "checkInterval", value: 3 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"]) sendEvent(name: "numberOfButtons", value: 1, displayed: true) def cmds = [] cmds << zwave.versionV1.versionGet() cmds << zwave.associationV2.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId) cmds << zwave.associationV2.associationGet(groupingIdentifier:1) cmds << zwave.configurationV1.configurationSet(configurationValue: [ledIndicator? ledIndicator.toInteger() : 0], parameterNumber: 1, size: 1) cmds << zwave.configurationV1.configurationGet(parameterNumber: 1) cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: autoOff1? autoOff1.toInteger() : 0, parameterNumber: 2, size: 2) cmds << zwave.configurationV1.configurationGet(parameterNumber: 2) cmds << zwave.configurationV1.configurationSet(scaledConfigurationValue: autoOff2? autoOff2.toInteger() : 0, parameterNumber: 3, size: 2) cmds << zwave.configurationV1.configurationGet(parameterNumber: 3) response(commands(cmds)) } def zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd) { createEvent(buttonEvent(cmd.sceneNumber, (cmd.sceneNumber == 2? "held" : "pushed"), "physical")) } def buttonEvent(button, value, type = "digital") { sendEvent(name:"lastEvent", value: "${value != 'pushed'?' Tap '.padRight(button+1+5, '▼'):' Tap '.padRight(button+1+5, '▲')}", displayed:false) [name: "button", value: value, data: [buttonNumber: button], descriptionText: "$device.displayName button $button was $value", isStateChange: true, type: type] } def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationReport cmd) { log.debug "${device.displayName} parameter '${cmd.parameterNumber}' with a byte size of '${cmd.size}' is set to '${cmd.configurationValue}'" } private encap(cmd, endpoint) { if (endpoint) { zwave.multiChannelV3.multiChannelCmdEncap(destinationEndPoint: endpoint).encapsulate(cmd) } else { cmd } } private command(physicalgraph.zwave.Command cmd) { if (state.sec) { zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format() } else { cmd.format() } } private commands(commands, delay = 1000) { delayBetween(commands.collect { command(it) }, delay) } private channelNumber(String dni) { dni.split("-ep")[-1] as Integer } private void createChildDevices() { state.oldLabel = device.label for (i in 1..2) { addChildDevice("Switch Child Device", "${device.deviceNetworkId}-ep${i}", null, [completedSetup: true, label: "${device.displayName} (CH${i})", isComponent: false ]) } } def pressUpX2() { sendEvent(buttonEvent(1, "pushed")) }