From 6f1f8a124cf59fd3faacc87a012637ac3f86993f Mon Sep 17 00:00:00 2001 From: "k.klimczuk2" Date: Wed, 18 Sep 2019 12:45:43 +0200 Subject: [PATCH 1/2] ICP-10949 - Added support for capability: "Battery " for IKEA roller blinds (KADRILJ, FYRTUR). --- .../zigbee-window-shade.groovy | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy b/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy index 0d586d918e3..b8dca80a739 100755 --- a/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy +++ b/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy @@ -16,6 +16,7 @@ import physicalgraph.zigbee.zcl.DataType metadata { definition(name: "ZigBee Window Shade", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.blind", mnmn: "SmartThings", vid: "generic-shade") { capability "Actuator" + capability "Battery" capability "Configuration" capability "Refresh" capability "Window Shade" @@ -28,8 +29,8 @@ metadata { fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0102", outClusters: "000A", manufacturer: "Feibit Co.Ltd", model: "FTB56-ZT218AK1.6", deviceJoinName: "Wistar Curtain Motor(CMJ)" fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0102", outClusters: "000A", manufacturer: "Feibit Co.Ltd", model: "FTB56-ZT218AK1.8", deviceJoinName: "Wistar Curtain Motor(CMJ)" fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0102", outClusters: "0003", manufacturer: "REXENSE", model: "DY0010", deviceJoinName: "Smart Curtain Motor(DT82TV)" - fingerprint manufacturer: "IKEA of Sweden", model: "KADRILJ roller blind", deviceJoinName: "IKEA KADRILJ Blinds" // raw description 01 0104 0202 00 09 0000 0001 0003 0004 0005 0020 0102 1000 FC7C 02 0019 1000 - fingerprint manufacturer: "IKEA of Sweden", model: "FYRTUR block-out roller blind", deviceJoinName: "IKEA FYRTUR Blinds" // raw description 01 0104 0202 01 09 0000 0001 0003 0004 0005 0020 0102 1000 FC7C 02 0019 1000 + fingerprint manufacturer: "IKEA of Sweden", model: "KADRILJ roller blind", deviceJoinName: "IKEA KADRILJ Blinds", vid: "generic-shade-2" // raw description 01 0104 0202 00 09 0000 0001 0003 0004 0005 0020 0102 1000 FC7C 02 0019 1000 + fingerprint manufacturer: "IKEA of Sweden", model: "FYRTUR block-out roller blind", deviceJoinName: "IKEA FYRTUR Blinds", vid: "generic-shade-2" // raw description 01 0104 0202 01 09 0000 0001 0003 0004 0005 0020 0102 1000 FC7C 02 0019 1000 } tiles(scale: 2) { @@ -68,6 +69,7 @@ private getCOMMAND_GOTO_LIFT_PERCENTAGE() { 0x05 } private getATTRIBUTE_POSITION_LIFT() { 0x0008 } private getATTRIBUTE_CURRENT_LEVEL() { 0x0000 } private getCOMMAND_MOVE_LEVEL_ONOFF() { 0x04 } +private getBATTERY_PERCENTAGE_REMAINING() { 0x0021 } private List collectAttributes(Map descMap) { List descMaps = new ArrayList() @@ -104,6 +106,9 @@ def parse(String description) { def valueInt = Math.round((zigbee.convertHexToInt(descMap.value)) / 255 * 100) levelEventHandler(valueInt) + } else if (reportsBatteryPercentage() && descMap?.clusterInt == zigbee.POWER_CONFIGURATION_CLUSTER && zigbee.convertHexToInt(descMap?.attrId) == BATTERY_PERCENTAGE_REMAINING && descMap.value) { + def batteryLevel = zigbee.convertHexToInt(descMap.value) + batteryPercentageEventHandler(batteryLevel) } } } @@ -136,6 +141,13 @@ def updateFinalState() { } } +def batteryPercentageEventHandler(batteryLevel) { + if (batteryLevel != null) { + batteryLevel = Math.min(100, Math.max(0, batteryLevel)) + sendEvent([name: "battery", value: batteryLevel, unit: "%", descriptionText: "{{ device.displayName }} battery was {{ value }}%", isStateChange: true]) + } +} + def supportsLiftPercentage() { device.getDataValue("manufacturer") != "Feibit Co.Ltd" } @@ -206,6 +218,10 @@ def configure() { cmds += readDeviceBindingTable() } + if (reportsBatteryPercentage()) { + cmds += zigbee.configureReporting(zigbee.POWER_CONFIGURATION_CLUSTER, BATTERY_PERCENTAGE_REMAINING, DataType.UINT8, 30, 720, 0x01) + } + return refresh() + cmds } @@ -241,6 +257,10 @@ def shouldInvertLiftPercentage() { return isIkeaKadrilj() || isIkeaFyrtur() } +def reportsBatteryPercentage() { + return isIkeaKadrilj() || isIkeaFyrtur() +} + def isIkeaKadrilj() { device.getDataValue("model") == "KADRILJ roller blind" } From b98ddbce1024e77f7fe9f97527d69ad620a5502f Mon Sep 17 00:00:00 2001 From: "k.klimczuk2" Date: Wed, 18 Sep 2019 16:53:26 +0200 Subject: [PATCH 2/2] ICP-10949 - code refactoring --- .../zigbee-window-shade.src/zigbee-window-shade.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy b/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy index b8dca80a739..b3331d7945b 100755 --- a/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy +++ b/devicetypes/smartthings/zigbee-window-shade.src/zigbee-window-shade.groovy @@ -16,7 +16,7 @@ import physicalgraph.zigbee.zcl.DataType metadata { definition(name: "ZigBee Window Shade", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.blind", mnmn: "SmartThings", vid: "generic-shade") { capability "Actuator" - capability "Battery" + capability "Battery" capability "Configuration" capability "Refresh" capability "Window Shade" @@ -144,7 +144,7 @@ def updateFinalState() { def batteryPercentageEventHandler(batteryLevel) { if (batteryLevel != null) { batteryLevel = Math.min(100, Math.max(0, batteryLevel)) - sendEvent([name: "battery", value: batteryLevel, unit: "%", descriptionText: "{{ device.displayName }} battery was {{ value }}%", isStateChange: true]) + sendEvent([name: "battery", value: batteryLevel, unit: "%", descriptionText: "{{ device.displayName }} battery was {{ value }}%"]) } } @@ -219,7 +219,7 @@ def configure() { } if (reportsBatteryPercentage()) { - cmds += zigbee.configureReporting(zigbee.POWER_CONFIGURATION_CLUSTER, BATTERY_PERCENTAGE_REMAINING, DataType.UINT8, 30, 720, 0x01) + cmds += zigbee.configureReporting(zigbee.POWER_CONFIGURATION_CLUSTER, BATTERY_PERCENTAGE_REMAINING, DataType.UINT8, 30, 21600, 0x01) } return refresh() + cmds