22static const char *
const TAG =
"aht10";
23static const uint8_t AHT10_INITIALIZE_CMD[] = {0xE1, 0x08, 0x00};
24static const uint8_t AHT20_INITIALIZE_CMD[] = {0xBE, 0x08, 0x00};
25static const uint8_t AHT10_MEASURE_CMD[] = {0xAC, 0x33, 0x00};
26static const uint8_t AHT10_SOFTRESET_CMD[] = {0xBA};
28static const uint8_t AHT10_DEFAULT_DELAY = 5;
29static const uint8_t AHT10_READ_DELAY = 80;
30static const uint8_t AHT10_SOFTRESET_DELAY = 30;
32static const uint8_t AHT10_ATTEMPTS = 3;
33static const uint8_t AHT10_INIT_ATTEMPTS = 10;
35static const uint8_t AHT10_STATUS_BUSY = 0x80;
37static const float AHT10_DIVISOR = 1048576.0f;
41 ESP_LOGE(TAG,
"Reset failed");
43 delay(AHT10_SOFTRESET_DELAY);
48 error_code = this->
write(AHT20_INITIALIZE_CMD,
sizeof(AHT20_INITIALIZE_CMD));
51 error_code = this->
write(AHT10_INITIALIZE_CMD,
sizeof(AHT10_INITIALIZE_CMD));
55 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
59 uint8_t cal_attempts = 0;
60 uint8_t data = AHT10_STATUS_BUSY;
61 while (data & AHT10_STATUS_BUSY) {
62 delay(AHT10_DEFAULT_DELAY);
64 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
69 if (cal_attempts > AHT10_INIT_ATTEMPTS) {
70 ESP_LOGE(TAG,
"Initialization timed out");
75 if ((data & 0x68) != 0x08) {
76 ESP_LOGE(TAG,
"Initialization failed");
103 if ((data[0] & 0x80) == 0x80) {
104 ESP_LOGD(TAG,
"Device busy, will retry");
108 if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) {
111 ESP_LOGV(TAG,
"Invalid humidity (reading not required)");
113 ESP_LOGD(TAG,
"Invalid humidity, retrying");
128 float temperature = ((200.0f *
static_cast<float>(raw_temperature)) / AHT10_DIVISOR) - 50.0f;
132 float humidity = raw_humidity == 0 ? NAN :
static_cast<float>(raw_humidity) * 100.0f / AHT10_DIVISOR;
133 if (std::isnan(humidity)) {
134 ESP_LOGW(TAG,
"Invalid humidity reading (0%%), ");
153 ESP_LOGCONFIG(TAG,
"AHT10:");
154 LOG_I2C_DEVICE(
this);
156 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
void mark_failed()
Mark this component as failed.
void status_set_warning()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void status_clear_warning()
void dump_config() override
sensor::Sensor * temperature_sensor_
sensor::Sensor * humidity_sensor_
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
@ ERROR_INVALID_ARGUMENT
method called invalid argument(s)
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.
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()