9static const uint8_t MEASURECOMMANDS[] = {0xFD, 0xF6, 0xE0};
10static const uint8_t SERIAL_NUMBER_COMMAND = 0x89;
13static constexpr float TEMPERATURE_OFFSET = -45.0f;
14static constexpr float TEMPERATURE_SPAN = 175.0f;
15static constexpr float HUMIDITY_OFFSET = -6.0f;
16static constexpr float HUMIDITY_SPAN = 125.0f;
17static constexpr float RAW_MAX = 65535.0f;
22 ESP_LOGE(TAG,
"Get serial number failed");
31 auto err = this->
write(
nullptr, 0);
69 " Serial number: %08" PRIx32,
74 ESP_LOGW(TAG,
"Get serial number failed");
92 ESP_LOGW(TAG,
"Sensor read failed");
99 float temp = TEMPERATURE_OFFSET + TEMPERATURE_SPAN *
static_cast<float>(
buffer[0]) / RAW_MAX;
105 float rh = 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.
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.
void publish_state(float state)
Publish a new state to the front-end.
SHT4XPRECISION precision_
void read_serial_number_()
SHT4XHEATERPOWER heater_power_
uint32_t last_heater_millis_
sensor::Sensor * humidity_sensor_
sensor::Sensor * temp_sensor_
uint32_t heater_interval_
void dump_config() override
SHT4XHEATERTIME heater_time_
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "sht4x")
uint32_t IRAM_ATTR HOT millis()