10static const uint8_t MEASURECOMMANDS[] = {0xFD, 0xF6, 0xE0};
11static const uint8_t SERIAL_NUMBER_COMMAND = 0x89;
14static constexpr float TEMPERATURE_OFFSET = -45.0f;
15static constexpr float TEMPERATURE_SPAN = 175.0f;
16static constexpr float HUMIDITY_OFFSET = -6.0f;
17static constexpr float HUMIDITY_SPAN = 125.0f;
18static constexpr float RAW_MAX = 65535.0f;
23 ESP_LOGE(TAG,
"Get serial number failed");
30 if (this->serial_number_text_sensor_ !=
nullptr) {
33 this->serial_number_text_sensor_->publish_state(
serial_number);
39 auto err = this->
write(
nullptr, 0);
74void SHT4XComponent::dump_config() {
77 " Serial number: %08" PRIx32,
82 ESP_LOGW(TAG,
"Get serial number failed");
86void SHT4XComponent::update() {
100 ESP_LOGW(TAG,
"Sensor read failed");
106 PUBLISH_STATE(this->temp_sensor_, TEMPERATURE_OFFSET + TEMPERATURE_SPAN *
static_cast<float>(
buffer[0]) / RAW_MAX);
107 PUBLISH_STATE(this->humidity_sensor_, HUMIDITY_OFFSET + HUMIDITY_SPAN *
static_cast<float>(
buffer[1]) / RAW_MAX);
114 ESP_LOGD(TAG,
"Heater turning on");
void mark_failed()
Mark this component as failed.
virtual void setup()
Where the component's initialization should happen.
void status_set_warning()
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
bool get_8bit_register(uint8_t i2c_register, 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.
SHT4XPRECISION precision_
void read_serial_number_()
SHT4XHEATERPOWER heater_power_
uint32_t last_heater_millis_
uint32_t heater_interval_
SHT4XHEATERTIME heater_time_
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "sht4x")
constexpr size_t format_hex_size(size_t byte_count)
Calculate buffer size needed for format_hex_to: "XXXXXXXX...\0" = bytes * 2 + 1.
uint32_t IRAM_ATTR HOT millis()
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).