/* groovylint-disable CompileStatic, CouldBeSwitchStatement, DuplicateListLiteral, DuplicateNumberLiteral, DuplicateStringLiteral, ImplicitClosureParameter, ImplicitReturnStatement, Instanceof, LineLength, MethodCount, MethodSize, NoDouble, NoFloat, NoWildcardImports, ParameterCount, ParameterName, UnnecessaryElseStatement, UnnecessaryGetter, UnnecessaryPublicModifier, UnnecessarySetter, UnusedImport */ library( base: 'driver', author: 'Krassimir Kossev', category: 'zigbee', description: 'Zigbee Reporting Config Library', name: 'reportingLib', namespace: 'kkossev', importUrl: 'https://raw.githubusercontent.com/kkossev/Hubitat/refs/heads/development/Libraries/reportingLib.groovy', documentationLink: 'https://github.com/kkossev/Hubitat/wiki/libraries-reportingLib', version: '3.2.1' ) /* * Zigbee Reporting Config Library * * Licensed Virtual 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. * * ver. 3.2.0 2024-05-25 kkossev - added reportingLib.groovy * ver. 3.2.1 2025-03-09 kkossev - configureReportingInt() integer parameters overload; importUrl and documentationLink updated; * * TODO: add bindCluster() and unbindCluster() methods */ static String reportingLibVersion() { '3.2.1' } static String reportingLibStamp() { '2025/03/23 7:31 PM' } metadata { // no capabilities // no attributes // no commands preferences { // no prefrences } } @Field static final String ONOFF = 'Switch' @Field static final String POWER = 'Power' @Field static final String INST_POWER = 'InstPower' @Field static final String ENERGY = 'Energy' @Field static final String VOLTAGE = 'Voltage' @Field static final String AMPERAGE = 'Amperage' @Field static final String FREQUENCY = 'Frequency' @Field static final String POWER_FACTOR = 'PowerFactor' List configureReportingInt(String operation, String measurement, int minTime=0, int maxTime=0, int delta=0, boolean sendNow=true ) { configureReporting(operation, measurement, minTime.toString(), maxTime.toString(), delta.toString(), sendNow) } List configureReporting(String operation, String measurement, String minTime='0', String maxTime='0', String delta='0', boolean sendNow=true ) { int intMinTime = safeToInt(minTime) int intMaxTime = safeToInt(maxTime) int intDelta = safeToInt(delta) String epString = state.destinationEP int ep = safeToInt(epString) if (ep == null || ep == 0) { ep = 1 epString = '01' } logDebug "configureReporting operation=${operation}, measurement=${measurement}, minTime=${intMinTime}, maxTime=${intMaxTime}, delta=${intDelta} )" List cmds = [] switch (measurement) { case ONOFF : if (operation == 'Write') { cmds += ["zdo bind 0x${device.deviceNetworkId} 0x${epString} 0x01 0x0006 {${device.zigbeeId}} {}", 'delay 251', ] cmds += ["he cr 0x${device.deviceNetworkId} 0x${epString} 6 0 16 ${intMinTime} ${intMaxTime} {}", 'delay 251', ] } else if (operation == 'Disable') { cmds += ["he cr 0x${device.deviceNetworkId} 0x${epString} 6 0 16 65535 65535 {}", 'delay 251', ] // disable Plug automatic reporting } cmds += zigbee.reportingConfiguration(0x0006, 0x0000, [destEndpoint :ep], 251) // read it back break case ENERGY : // default delta = 1 Wh (0.001 kWh) if (operation == 'Write') { cmds += zigbee.configureReporting(0x0702, 0x0000, DataType.UINT48, intMinTime, intMaxTime, (intDelta * getEnergyDiv() as int)) } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0702, 0x0000, DataType.UINT48, 0xFFFF, 0xFFFF, 0x0000) // disable energy automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0702, 0x0000, [destEndpoint :ep], 252) break case INST_POWER : // 0x702:0x400 if (operation == 'Write') { cmds += zigbee.configureReporting(0x0702, 0x0400, DataType.INT16, intMinTime, intMaxTime, (intDelta * getPowerDiv() as int)) } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0702, 0x0400, DataType.INT16, 0xFFFF, 0xFFFF, 0x0000) // disable power automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0702, 0x0400, [destEndpoint :ep], 253) break case POWER : // Active power default delta = 1 if (operation == 'Write') { cmds += zigbee.configureReporting(0x0B04, 0x050B, DataType.INT16, intMinTime, intMaxTime, (intDelta * getPowerDiv() as int) ) // bug fixes in ver 1.6.0 - thanks @guyee } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0B04, 0x050B, DataType.INT16, 0xFFFF, 0xFFFF, 0x8000) // disable power automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0B04, 0x050B, [destEndpoint :ep], 254) break case VOLTAGE : // RMS Voltage default delta = 1 if (operation == 'Write') { cmds += zigbee.configureReporting(0x0B04, 0x0505, DataType.UINT16, intMinTime, intMaxTime, (intDelta * getVoltageDiv() as int)) } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0B04, 0x0505, DataType.UINT16, 0xFFFF, 0xFFFF, 0xFFFF) // disable voltage automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0B04, 0x0505, [destEndpoint :ep], 255) break case AMPERAGE : // RMS Current default delta = 100 mA = 0.1 A if (operation == 'Write') { cmds += zigbee.configureReporting(0x0B04, 0x0508, DataType.UINT16, intMinTime, intMaxTime, (intDelta * getCurrentDiv() as int)) } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0B04, 0x0508, DataType.UINT16, 0xFFFF, 0xFFFF, 0xFFFF) // disable amperage automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0B04, 0x0508, [destEndpoint :ep], 256) break case FREQUENCY : // added 03/27/2023 if (operation == 'Write') { cmds += zigbee.configureReporting(0x0B04, 0x0300, DataType.UINT16, intMinTime, intMaxTime, (intDelta * getFrequencyDiv() as int)) } else if (operation == 'Disable') { cmds += zigbee.configureReporting(0x0B04, 0x0300, DataType.UINT16, 0xFFFF, 0xFFFF, 0xFFFF) // disable frequency automatic reporting - tested with Frient } cmds += zigbee.reportingConfiguration(0x0B04, 0x0300, [destEndpoint :ep], 257) break case POWER_FACTOR : // added 03/27/2023 if (operation == 'Write') { cmds += zigbee.configureReporting(0x0B04, 0x0510, DataType.UINT16, intMinTime, intMaxTime, (intDelta * getPowerFactorDiv() as int)) } cmds += zigbee.reportingConfiguration(0x0B04, 0x0510, [destEndpoint :ep], 258) break default : break } if (cmds != null) { if (sendNow == true) { sendZigbeeCommands(cmds) } else { return cmds } } }