13static constexpr uint32_t MEASUREMENT_TIMEOUT_ID = 0;
15static const uint8_t REQUEST_CMD[1] = {0x00};
16static const uint16_t MAX_COUNT = 0x3FFE;
18void HoneywellHIComponent::read_sensor_data_() {
26 const uint16_t raw_humidity =
encode_uint16(data[0] & 0x3F, data[1]);
27 float humidity = (
static_cast<float>(raw_humidity) / MAX_COUNT) * 100;
29 const uint16_t raw_temperature =
encode_uint16(data[2], data[3]) >> 2;
30 float temperature = (
static_cast<float>(raw_temperature) / MAX_COUNT) * 165 - 40;
32 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%",
temperature, humidity);
33 PUBLISH_STATE(this->temperature_sensor_,
temperature);
34 PUBLISH_STATE(this->humidity_sensor_, humidity);
55 return ((data[0] & 0xC0) == 0x00);
64 ESP_LOGV(TAG,
"Update Honeywell HIH Sensor");
75 this->read_sensor_data_();
80 ESP_LOGD(TAG,
"Honeywell HIH:");
82 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
83 LOG_SENSOR(
" ",
"Humidity", this->humidity_sensor_);
84 LOG_UPDATE_INTERVAL(
this);
void mark_failed()
Mark this component as failed.
bool cancel_timeout(const char *name)
Cancel a timeout function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
SUB_SENSOR(temperature) SUB_SENSOR(humidity) private void start_measurement_()
void measurement_timeout_()
bool is_measurement_ready_()
void dump_config() override
bool measurement_running_
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
ESPHOME_LOG_TAG(TAG, "honeywell_hih.i2c")
@ ERROR_OK
No error found during execution of method.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.