1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 15:12:06 +00:00

Add Xiaomi Cleargrass Temperature and Humidity Sensor (#735)

* Add Xiaomi Cleargrass Temperature and Humidity Sensor

* fix CI Travis

* fix CI Travis 2

* Improve device detection (more accurate)


Co-authored-by: t151602 <sergio.mayoralmartinez@telefonica.com>
This commit is contained in:
Sergio Mayoral Martínez
2019-10-14 13:25:08 +02:00
committed by Otto Winter
parent e207c6ad84
commit e30512931b
6 changed files with 117 additions and 3 deletions

View File

@@ -84,13 +84,14 @@ optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &d
bool is_mijia = (raw[1] & 0x20) == 0x20 && raw[2] == 0xAA && raw[3] == 0x01;
bool is_miflora = (raw[1] & 0x20) == 0x20 && raw[2] == 0x98 && raw[3] == 0x00;
bool is_lywsd02 = (raw[1] & 0x20) == 0x20 && raw[2] == 0x5b && raw[3] == 0x04;
bool is_cleargrass = (raw[1] & 0x30) == 0x30 && raw[2] == 0x47 && raw[3] == 0x03;
if (!is_mijia && !is_miflora && !is_lywsd02) {
if (!is_mijia && !is_miflora && !is_lywsd02 && !is_cleargrass) {
// ESP_LOGVV(TAG, "Xiaomi no magic bytes");
return {};
}
uint8_t raw_offset = is_mijia ? 11 : 12;
uint8_t raw_offset = is_mijia || is_cleargrass ? 11 : 12;
const uint8_t raw_type = raw[raw_offset];
const uint8_t data_length = raw[raw_offset + 2];
@@ -107,6 +108,8 @@ optional<XiaomiParseResult> parse_xiaomi(const esp32_ble_tracker::ESPBTDevice &d
result.type = XiaomiParseResult::TYPE_MIJIA;
} else if (is_lywsd02) {
result.type = XiaomiParseResult::TYPE_LYWSD02;
} else if (is_cleargrass) {
result.type = XiaomiParseResult::TYPE_CLEARGRASS;
}
bool success = parse_xiaomi_data_byte(raw_type, data, data_length, result);
if (!success)
@@ -124,6 +127,8 @@ bool XiaomiListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
name = "Mi Jia";
} else if (res->type == XiaomiParseResult::TYPE_LYWSD02) {
name = "LYWSD02";
} else if (res->type == XiaomiParseResult::TYPE_CLEARGRASS) {
name = "Cleargrass";
}
ESP_LOGD(TAG, "Got Xiaomi %s (%s):", name, device.address_str().c_str());

View File

@@ -9,7 +9,7 @@ namespace esphome {
namespace xiaomi_ble {
struct XiaomiParseResult {
enum { TYPE_MIJIA, TYPE_MIFLORA, TYPE_LYWSD02 } type;
enum { TYPE_MIJIA, TYPE_MIFLORA, TYPE_LYWSD02, TYPE_CLEARGRASS } type;
optional<float> temperature;
optional<float> humidity;
optional<float> battery_level;