From eabac5e466027f9df1e616a97419e6ffd6f75fd5 Mon Sep 17 00:00:00 2001 From: Hadinger Date: Sat, 28 Dec 2019 13:59:01 +0100 Subject: [PATCH] Zigbee attribute decoder for Xiaomi Aqara Cube --- tasmota/CHANGELOG.md | 1 + tasmota/xdrv_23_zigbee_5_converters.ino | 61 ++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 530b8c198..3abb0db81 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -8,6 +8,7 @@ - Add SerialConfig to ``Status 1`` - Add WifiPower to ``Status 5`` - Add support for DS1624, DS1621 Temperature sensor by Leonid Myravjev +- Add Zigbee attribute decoder for Xiaomi Aqara Cube ## Released diff --git a/tasmota/xdrv_23_zigbee_5_converters.ino b/tasmota/xdrv_23_zigbee_5_converters.ino index 1423c53f1..94853d629 100644 --- a/tasmota/xdrv_23_zigbee_5_converters.ino +++ b/tasmota/xdrv_23_zigbee_5_converters.ino @@ -601,7 +601,7 @@ const Z_AttributeConverter Z_PostProcess[] PROGMEM = { { 0x0012, 0x001C, "Description", &Z_Copy }, { 0x0012, 0x004A, "NumberOfStates", &Z_Copy }, { 0x0012, 0x0051, "OutOfService", &Z_Copy }, - { 0x0012, 0x0055, "PresentValue", &Z_Copy }, + { 0x0012, 0x0055, "PresentValue", &Z_AqaraCube }, { 0x0012, 0x0067, "Reliability", &Z_Copy }, { 0x0012, 0x006F, "StatusFlags", &Z_Copy }, { 0x0012, 0x0100, "ApplicationType", &Z_Copy }, @@ -836,6 +836,65 @@ int32_t Z_OccupancyCallback(uint16_t shortaddr, uint16_t cluster, uint16_t endpo XdrvRulesProcess(); } +// Aqara Cube +int32_t Z_AqaraCube(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObject& json, const char *name, JsonVariant& value, const String &new_name, uint16_t cluster, uint16_t attr) { + json[new_name] = value; // copy the original value + int32_t val = value; + const __FlashStringHelper *aqara_cube = F("AqaraCube"); + const __FlashStringHelper *aqara_cube_side = F("AqaraCubeSide"); + const __FlashStringHelper *aqara_cube_from_side = F("AqaraCubeFromSide"); + + switch (val) { + case 0: + json[aqara_cube] = F("shake"); + break; + case 2: + json[aqara_cube] = F("wakeup"); + break; + case 3: + json[aqara_cube] = F("fall"); + break; + case 64 ... 127: + json[aqara_cube] = F("flip90"); + json[aqara_cube_side] = val % 8; + json[aqara_cube_from_side] = (val - 64) / 8; + break; + case 128 ... 132: + json[aqara_cube] = F("flip180"); + json[aqara_cube_side] = val - 128; + break; + case 256 ... 261: + json[aqara_cube] = F("slide"); + json[aqara_cube_side] = val - 256; + break; + case 512 ... 517: + json[aqara_cube] = F("tap"); + json[aqara_cube_side] = val - 512; + break; + } + + // Source: https://github.com/kirovilya/ioBroker.zigbee + // +---+ + // | 2 | + // +---+---+---+ + // | 4 | 0 | 1 | + // +---+---+---+ + // |M5I| + // +---+ + // | 3 | + // +---+ + // Side 5 is with the MI logo, side 3 contains the battery door. + // presentValue = 0 = shake + // presentValue = 2 = wakeup + // presentValue = 3 = fly/fall + // presentValue = y + x * 8 + 64 = 90º Flip from side x on top to side y on top + // presentValue = x + 128 = 180º flip to side x on top + // presentValue = x + 256 = push/slide cube while side x is on top + // presentValue = x + 512 = double tap while side x is on top + + return 1; +} + // Aqara Vibration Sensor - special proprietary attributes int32_t Z_AqaraVibration(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObject& json, const char *name, JsonVariant& value, const String &new_name, uint16_t cluster, uint16_t attr) { //json[new_name] = value;