Zigbee attribute decoder for Xiaomi Aqara Cube

This commit is contained in:
Hadinger 2019-12-28 13:59:01 +01:00
parent dd50d72ea1
commit eabac5e466
2 changed files with 61 additions and 1 deletions

View File

@ -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

View File

@ -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;