From 6e991cef0c65118683555e0643dc7ab748b6593f Mon Sep 17 00:00:00 2001 From: "Bartlomiej Janusz/Home IoT Development (IoT) /SRPOL/Associate/Samsung Electronics" Date: Tue, 7 Jul 2020 13:55:04 +0200 Subject: [PATCH 1/3] Ignoring duplicated switch events --- .../zigbee-metering-plug.groovy | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy index 308273fe479..bebee739c5f 100755 --- a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy +++ b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy @@ -69,7 +69,7 @@ def parse(String description) { def powerDiv = 1 def energyDiv = 100 - if (event) { + if (event && event.name != "switch") { log.info "event enter:$event" if (event.name== "power") { event.value = event.value/powerDiv @@ -80,6 +80,15 @@ def parse(String description) { } log.info "event outer:$event" sendEvent(event) + } else if (event.name == "switch") { + log.info "event enter:$event" + if (isOnOffStateChanged(event)) { + log.info "event outer:$event" + sendEvent(event) + } else { + log.info "Ignoring duplicated event outer:$event" + [:] + } } else { List result = [] def descMap = zigbee.parseDescriptionAsMap(description) @@ -146,6 +155,7 @@ def refresh() { } def configure() { + state.someEvent = [:] // this device will send instantaneous demand and current summation delivered every 1 minute sendEvent(name: "checkInterval", value: 2 * 60 + 10 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]) log.debug "Configuring Reporting" @@ -154,3 +164,14 @@ def configure() { zigbee.configureReporting(zigbee.SIMPLE_METERING_CLUSTER, ATTRIBUTE_READING_INFO_SET, DataType.UINT48, 1, 600, 1) + zigbee.electricMeasurementPowerConfig(1, 600, 1) } + +def isOnOffStateChanged(Map event) { + if (state.someEvent.get(event.name) != event.value) { + // When the device reports new On/Off status then create event + state.someEvent = [(event.name) : (event.value)] + return true + } else if (state.someEvent.get(event.name) == event.value) { + // When state has not changed then ignore + return false + } +} From d33c902242f6d4ef2a450e2b620604dfea84436b Mon Sep 17 00:00:00 2001 From: "Bartlomiej Janusz/Home IoT Development (IoT) /SRPOL/Associate/Samsung Electronics" Date: Tue, 14 Jul 2020 15:39:12 +0200 Subject: [PATCH 2/3] Double events fixed by ignoring catchall desc --- .../zigbee-metering-plug.groovy | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy index bebee739c5f..8c4978da0bc 100755 --- a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy +++ b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy @@ -69,7 +69,10 @@ def parse(String description) { def powerDiv = 1 def energyDiv = 100 - if (event && event.name != "switch") { + if (event?.name == "switch" && description?.startsWith("catchall: ")) { + log.info "Ignoring default response with description $description" + return [:] + } else if (event) { log.info "event enter:$event" if (event.name== "power") { event.value = event.value/powerDiv @@ -80,15 +83,6 @@ def parse(String description) { } log.info "event outer:$event" sendEvent(event) - } else if (event.name == "switch") { - log.info "event enter:$event" - if (isOnOffStateChanged(event)) { - log.info "event outer:$event" - sendEvent(event) - } else { - log.info "Ignoring duplicated event outer:$event" - [:] - } } else { List result = [] def descMap = zigbee.parseDescriptionAsMap(description) @@ -155,7 +149,6 @@ def refresh() { } def configure() { - state.someEvent = [:] // this device will send instantaneous demand and current summation delivered every 1 minute sendEvent(name: "checkInterval", value: 2 * 60 + 10 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]) log.debug "Configuring Reporting" @@ -163,15 +156,4 @@ def configure() { zigbee.onOffConfig() + zigbee.configureReporting(zigbee.SIMPLE_METERING_CLUSTER, ATTRIBUTE_READING_INFO_SET, DataType.UINT48, 1, 600, 1) + zigbee.electricMeasurementPowerConfig(1, 600, 1) -} - -def isOnOffStateChanged(Map event) { - if (state.someEvent.get(event.name) != event.value) { - // When the device reports new On/Off status then create event - state.someEvent = [(event.name) : (event.value)] - return true - } else if (state.someEvent.get(event.name) == event.value) { - // When state has not changed then ignore - return false - } -} +} \ No newline at end of file From 645b922f05bbb87626000a69a9d2b5b697b2dcb1 Mon Sep 17 00:00:00 2001 From: "Bartlomiej Janusz/Home IoT Development (IoT) /SRPOL/Associate/Samsung Electronics" Date: Wed, 15 Jul 2020 11:20:09 +0200 Subject: [PATCH 3/3] Changed condition for ignoring duplicated event --- .../zigbee-metering-plug.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy index 8c4978da0bc..49c2eeb99cd 100755 --- a/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy +++ b/devicetypes/smartthings/zigbee-metering-plug.src/zigbee-metering-plug.groovy @@ -66,15 +66,16 @@ def getATTRIBUTE_HISTORICAL_CONSUMPTION() { 0x0400 } def parse(String description) { log.debug "description is $description" def event = zigbee.getEvent(description) + def descMap = zigbee.parseDescriptionAsMap(description) def powerDiv = 1 def energyDiv = 100 - if (event?.name == "switch" && description?.startsWith("catchall: ")) { - log.info "Ignoring default response with description $description" - return [:] - } else if (event) { + if (event) { log.info "event enter:$event" - if (event.name== "power") { + if (event.name == "switch" && !descMap.isClusterSpecific && descMap.commandInt == 0x0B) { + log.info "Ignoring default response with desc map: $descMap" + return [:] + } else if (event.name== "power") { event.value = event.value/powerDiv event.unit = "W" } else if (event.name== "energy") { @@ -85,7 +86,6 @@ def parse(String description) { sendEvent(event) } else { List result = [] - def descMap = zigbee.parseDescriptionAsMap(description) log.debug "Desc Map: $descMap" List attrData = [[clusterInt: descMap.clusterInt ,attrInt: descMap.attrInt, value: descMap.value]]