8static const char *
const TAG =
"hte501";
11 uint8_t
address[] = {0x70, 0x29};
12 uint8_t identification[9];
14 if (identification[8] !=
calc_crc8_(identification, 0, 7)) {
19 ESP_LOGV(TAG,
" Serial Number: 0x%s",
format_hex(identification + 0, 7).c_str());
23 ESP_LOGCONFIG(TAG,
"HTE501:");
25 switch (this->error_code_) {
27 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
30 ESP_LOGE(TAG,
"The crc check failed");
36 LOG_UPDATE_INTERVAL(
this);
43 uint8_t address_1[] = {0x2C, 0x1B};
44 this->
write(address_1, 2);
46 uint8_t i2c_response[6];
47 this->
read(i2c_response, 6);
48 if (i2c_response[2] !=
calc_crc8_(i2c_response, 0, 1) && i2c_response[5] !=
calc_crc8_(i2c_response, 3, 4)) {
59 float humidity = ((float)
encode_uint16(i2c_response[3], i2c_response[4])) / 100.0f;
61 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%",
temperature, humidity);
71 unsigned char crc_val = 0xFF;
74 for (i = from; i <= to; i++) {
76 for (j = 0; j < 8; j++) {
77 if (((crc_val ^ cur_val) & 0x80) != 0)
79 crc_val = ((crc_val << 1) ^ 0x31);
81 crc_val = (crc_val << 1);
83 cur_val = cur_val << 1;
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
sensor::Sensor * temperature_sensor_
float get_setup_priority() const override
sensor::Sensor * humidity_sensor_
unsigned char calc_crc8_(const unsigned char buf[], unsigned char from, unsigned char to)
enum esphome::hte501::HTE501Component::ErrorCode NONE
void dump_config() override
ErrorCode write_read(const uint8_t *write_data, size_t write_len, uint8_t *read_data, size_t read_len) const
writes an array of bytes to a device, then reads an array, as a single transaction
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.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.