7 static const char *
const TAG =
"hte501";
10 ESP_LOGCONFIG(TAG,
"Setting up HTE501...");
11 uint8_t
address[] = {0x70, 0x29};
12 this->
write(address, 2,
false);
13 uint8_t identification[9];
14 this->
read(identification, 9);
15 if (identification[8] !=
calc_crc8_(identification, 0, 7)) {
20 ESP_LOGV(TAG,
" Serial Number: 0x%s",
format_hex(identification + 0, 7).c_str());
24 ESP_LOGCONFIG(TAG,
"HTE501:");
26 switch (this->error_code_) {
28 ESP_LOGE(TAG,
"Communication with HTE501 failed!");
31 ESP_LOGE(TAG,
"The crc check failed");
37 LOG_UPDATE_INTERVAL(
this);
44 uint8_t address_1[] = {0x2C, 0x1B};
45 this->
write(address_1, 2,
true);
47 uint8_t i2c_response[6];
48 this->
read(i2c_response, 6);
49 if (i2c_response[2] !=
calc_crc8_(i2c_response, 0, 1) && i2c_response[5] !=
calc_crc8_(i2c_response, 3, 4)) {
55 if (temperature > 55536) {
56 temperature = (temperature - 65536) / 100;
58 temperature = temperature / 100;
60 float humidity = ((float)
encode_uint16(i2c_response[3], i2c_response[4])) / 100.0f;
62 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity);
72 unsigned char crc_val = 0xFF;
75 for (i = from; i <= to; i++) {
77 for (j = 0; j < 8; j++) {
78 if (((crc_val ^ cur_val) & 0x80) != 0)
80 crc_val = ((crc_val << 1) ^ 0x31);
82 crc_val = (crc_val << 1);
84 cur_val = cur_val << 1;
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void dump_config() override
unsigned char calc_crc8_(const unsigned char buf[], unsigned char from, unsigned char to)
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * humidity_sensor_
enum esphome::hte501::HTE501Component::ErrorCode NONE
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
sensor::Sensor * temperature_sensor_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.