ESPHome 2026.2.4
Loading...
Searching...
No Matches
xiaomi_hhccjcy10.cpp
Go to the documentation of this file.
1#include "xiaomi_hhccjcy10.h"
3#include "esphome/core/log.h"
4
5#ifdef USE_ESP32
6
7namespace esphome {
8namespace xiaomi_hhccjcy10 {
9
10static const char *const TAG = "xiaomi_hhccjcy10";
11
13 ESP_LOGCONFIG(TAG, "Xiaomi HHCCJCY10");
14 LOG_SENSOR(" ", "Temperature", this->temperature_);
15 LOG_SENSOR(" ", "Moisture", this->moisture_);
16 LOG_SENSOR(" ", "Conductivity", this->conductivity_);
17 LOG_SENSOR(" ", "Illuminance", this->illuminance_);
18 LOG_SENSOR(" ", "Battery Level", this->battery_level_);
19}
20
22 if (device.address_uint64() != this->address_) {
23 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
24 return false;
25 }
26 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
27 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", device.address_str_to(addr_buf));
28
29 bool success = false;
30 for (auto &service_data : device.get_service_datas()) {
31 if (!service_data.uuid.contains(0x50, 0xFD)) {
32 ESP_LOGVV(TAG, "no tuya service data UUID.");
33 continue;
34 }
35 if (service_data.data.size() != 9) { // tuya alternate between two service data
36 continue;
37 }
38 const uint8_t *data = service_data.data.data();
39
40 if (this->temperature_ != nullptr) {
41 const int16_t temperature = encode_uint16(data[1], data[2]);
42 this->temperature_->publish_state((float) temperature / 10.0f);
43 }
44
45 if (this->moisture_ != nullptr)
46 this->moisture_->publish_state(data[0]);
47
48 if (this->conductivity_ != nullptr) {
49 const uint16_t conductivity = encode_uint16(data[7], data[8]);
50 this->conductivity_->publish_state((float) conductivity);
51 }
52
53 if (this->illuminance_ != nullptr) {
54 const uint32_t illuminance = encode_uint24(data[3], data[4], data[5]);
55 this->illuminance_->publish_state((float) illuminance);
56 }
57
58 if (this->battery_level_ != nullptr)
59 this->battery_level_->publish_state(data[6]);
60 success = true;
61 }
62
63 return success;
64}
65
66} // namespace xiaomi_hhccjcy10
67} // namespace esphome
68
69#endif
const char * address_str_to(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf) const
Format MAC address into provided buffer, returns pointer to buffer for convenience.
const std::vector< ServiceData > & get_service_datas() const
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
Definition helpers.h:532
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:528
uint16_t temperature
Definition sun_gtil2.cpp:12