Skip to content

Commit

Permalink
WWST-7205 - Enbrighten Smart Dimmer / new generic DTH to support dimm…
Browse files Browse the repository at this point in the history
…ers that report both power [W] and energy [kWh] values. (SmartThingsCommunity#56598)

* WWST-7205 - new generic DTH to support dimmers that report both power [W] and energy [kWh] values.

* WWST-7205 - fixes indentations

* WWST-7205 - fixes spacing

* WWST-7205 - changes deviceJoinName

* WWST-7205 - switches this DTH to local execution

* WWST-7205 - adds minHubCoreVersion

* WWST-7205 - fixes handling power and energy reports, fixes indentations

* WWST-7205 - fixes handling power reports

* WWST-7205 - changes ocfDeviceType to oic.d.switch
  • Loading branch information
KKlimczukS authored Feb 8, 2021
1 parent 06c10c7 commit 62da13c
Showing 1 changed file with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* Copyright 2021 SmartThings
*
* 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.
*
*/
import physicalgraph.zigbee.zcl.DataType
metadata {
definition (name: "ZigBee Metering Dimmer", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.switch", mnmn: "SmartThings", vid:"generic-dimmer-power-energy", runLocally: true, executeCommandsLocally: true, genericHandler: "Zigbee", minHubCoreVersion: '000.019.00012') {

capability "Actuator"
capability "Configuration"
capability "Refresh"
capability "Power Meter"
capability "Energy Meter"
capability "Switch"
capability "Switch Level"
capability "Health Check"

// Enbrighten/Jasco
fingerprint manufacturer: "Jasco Products", model: "43082", deviceJoinName: "Enbrighten Dimmer Switch" //Enbrighten, in-Wall Smart Dimmer With Energy Monitoring 43082, Raw Description: 01 0104 0101 00 08 0000 0003 0004 0005 0006 0008 0702 0B05 02 000A 0019
}
}

def getATTRIBUTE_READING_INFO_SET() { 0x0000 }
def getATTRIBUTE_HISTORICAL_CONSUMPTION() { 0x0400 }

// Parse incoming device messages to generate events
def parse(String description) {
log.debug "description is $description"
List result = []

def event = zigbee.getEvent(description)
if (event) {
log.info event
if (event.name == "power") {
def powerDiv = device.getDataValue("divisor")
powerDiv = powerDiv ? (powerDiv as int) : 1
event.value = event.value/powerDiv
event.unit = "W"
} else if (event.name == "energy") {
def energyDiv = device.getDataValue("energyDivisor")
energyDiv = energyDiv ? (energyDiv as int) : 100
event.value = event.value/energyDiv
event.unit = "kWh"
}
log.info "event: $event"
result << event
} else {
def descMap = zigbee.parseDescriptionAsMap(description)
log.debug "descMap: $descMap"

List attrData = [[clusterInt: descMap.clusterInt ,attrInt: descMap.attrInt, value: descMap.value]]
descMap.additionalAttrs.each {
attrData << [clusterInt: descMap.clusterInt, attrInt: it.attrInt, value: it.value]
}

attrData.each {
def map = [:]
if (it.value && it.clusterInt == zigbee.SIMPLE_METERING_CLUSTER && it.attrInt == ATTRIBUTE_HISTORICAL_CONSUMPTION) {
log.debug "power"
map.name = "power"
def powerDiv = device.getDataValue("divisor")
powerDiv = powerDiv ? (powerDiv as int) : 1
map.value = zigbee.convertHexToInt(it.value)/powerDiv
map.unit = "W"
}
else if (it.value && it.clusterInt == zigbee.SIMPLE_METERING_CLUSTER && it.attrInt == ATTRIBUTE_READING_INFO_SET) {
log.debug "energy"
map.name = "energy"
def energyDiv = device.getDataValue("energyDivisor")
energyDiv = energyDiv ? (energyDiv as int) : 100
map.value = zigbee.convertHexToInt(it.value)/energyDiv
map.unit = "kWh"
}

if (map) {
result << createEvent(map)
}
}
}
log.debug "result: ${result}"
return result
}

def off() {
zigbee.off()
}

def on() {
zigbee.on()
}

def setLevel(value, rate = null) {
zigbee.setLevel(value) + (value?.toInteger() > 0 ? zigbee.on() : [])
}

/**
* PING is used by Device-Watch in attempt to reach the Device
* */
def ping() {
log.debug "ping"
return refresh()
}

def refresh() {
log.debug "refresh"
zigbee.onOffRefresh() +
zigbee.levelRefresh() +
zigbee.simpleMeteringPowerRefresh() +
zigbee.readAttribute(zigbee.SIMPLE_METERING_CLUSTER, ATTRIBUTE_READING_INFO_SET)
}

def configure() {
log.debug "Configuring Reporting and Bindings."

if (isJascoProducts()) {
device.updateDataValue("divisor", "10")
device.updateDataValue("energyDivisor", "10000")
} else {
device.updateDataValue("divisor", "1")
device.updateDataValue("energyDivisor", "100")
}

sendEvent(name: "checkInterval", value: 2 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
return refresh() +
zigbee.onOffConfig() +
zigbee.levelConfig() +
zigbee.simpleMeteringPowerConfig() +
zigbee.configureReporting(zigbee.SIMPLE_METERING_CLUSTER, ATTRIBUTE_READING_INFO_SET, DataType.UINT48, 1, 600, 1)
}

private boolean isJascoProducts() {
device.getDataValue("manufacturer") == "Jasco Products"
}

0 comments on commit 62da13c

Please sign in to comment.