7static const char *
const TAG =
"sht3xd";
18static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING = 0x3780;
19static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER = 0x3682;
21static const uint16_t SHT3XD_COMMAND_READ_STATUS = 0xF32D;
22static const uint16_t SHT3XD_COMMAND_CLEAR_STATUS = 0x3041;
23static const uint16_t SHT3XD_COMMAND_HEATER_ENABLE = 0x306D;
24static const uint16_t SHT3XD_COMMAND_HEATER_DISABLE = 0x3066;
25static const uint16_t SHT3XD_COMMAND_SOFT_RESET = 0x30A2;
26static const uint16_t SHT3XD_COMMAND_POLLING_H = 0x2400;
27static const uint16_t SHT3XD_COMMAND_FETCH_DATA = 0xE000;
30 uint16_t raw_serial_number[2]{0};
31 if (!this->
get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING, raw_serial_number, 2)) {
32 if (!this->
get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER, raw_serial_number, 2, 10)) {
33 ESP_LOGW(TAG,
"Serial number read failed, continuing without it (clone or non-standard sensor)");
36 this->
serial_number_ = (uint32_t(raw_serial_number[0]) << 16) | uint32_t(raw_serial_number[1]);
39 this->
mark_failed(LOG_STR(
"Failed to set heater mode"));
47 " Serial Number: 0x%08" PRIX32
"\n"
48 " Heater Enabled: %s",
51 LOG_UPDATE_INTERVAL(
this);
58 ESP_LOGD(TAG,
"Retrying to reconnect the sensor.");
73 float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
74 float humidity = 100.0f * float(raw_data[1]) / 65535.0f;
76 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%",
temperature, humidity);
void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
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.
bool status_has_warning() const
void status_clear_warning()
bool get_register(uint16_t command, uint16_t *data, uint8_t len, uint8_t delay=0)
get data words from I2C register.
bool write_command(T i2c_register)
Write a command to the I2C device.
bool read_data(uint16_t *data, uint8_t len)
Read data words from I2C device.
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * temperature_sensor_
sensor::Sensor * humidity_sensor_
void dump_config() override
Providing packet encoding functions for exchanging data with a remote host.