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..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,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 }}%"]) + } +} + 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, 21600, 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" }