10static const uint8_t REG_TVOC = 0x00;
12static const uint8_t REG_CALIBRATION = 0x01;
14static const uint8_t REG_VERSION = 0x11;
16static const uint8_t REG_RESISTANCE = 0x20;
18static const uint8_t REG_ADDRESS = 0x21;
21static const uint16_t ZP_CURRENT = 0x0000;
23static const uint16_t ZP_DEFAULT = 0xFFFF;
28 ESP_LOGD(TAG,
"AGS10 Sensor Version: 0x%02X", *version);
29 PUBLISH_STATE(this->version_sensor_, *version);
31 ESP_LOGE(TAG,
"AGS10 Sensor Version: unknown");
36 ESP_LOGD(TAG,
"AGS10 Sensor Resistance: 0x%08" PRIX32, *resistance);
37 PUBLISH_STATE(this->resistance_sensor_, *resistance);
39 ESP_LOGE(TAG,
"AGS10 Sensor Resistance: unknown");
46 this->tvoc_sensor_->publish_state(*tvoc);
54 ESP_LOGCONFIG(TAG,
"AGS10:");
56 switch (this->error_code_) {
60 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
63 ESP_LOGE(TAG,
"The crc check failed");
66 ESP_LOGE(TAG,
"AGS10 is not ready to return TVOC data or sensor in pre-heat stage.");
69 ESP_LOGE(TAG,
"AGS10 returns TVOC data in unsupported units.");
72 ESP_LOGE(TAG,
"Unknown error: %d", this->error_code_);
75 LOG_UPDATE_INTERVAL(
this);
76 LOG_SENSOR(
" ",
"TVOC Sensor", this->tvoc_sensor_);
77 LOG_SENSOR(
" ",
"Firmware Version Sensor", this->version_sensor_);
78 LOG_SENSOR(
" ",
"Resistance Sensor", this->resistance_sensor_);
85 uint8_t rev_newaddress = ~newaddress;
86 std::array<uint8_t, 5> data{newaddress, rev_newaddress, newaddress, rev_newaddress, 0};
87 data[4] =
crc8(data.data(), 4, 0xFF, 0x31,
true);
91 ESP_LOGE(TAG,
"couldn't write the new I2C address 0x%02X", newaddress);
95 ESP_LOGW(TAG,
"changed I2C address to 0x%02X", newaddress);
96 this->error_code_ =
NONE;
120 std::array<uint8_t, 5> data{0x00, 0x0C, (uint8_t) ((
value >> 8) & 0xFF), (uint8_t) (
value & 0xFF), 0};
121 data[4] =
crc8(data.data(), 4, 0xFF, 0x31,
true);
125 ESP_LOGE(TAG,
"unable to set zero-point calibration with 0x%02X",
value);
128 if (
value == ZP_CURRENT) {
129 ESP_LOGI(TAG,
"zero-point calibration has been set with current resistance");
130 }
else if (
value == ZP_DEFAULT) {
131 ESP_LOGI(TAG,
"zero-point calibration has been reset to the factory defaults");
133 ESP_LOGI(TAG,
"zero-point calibration has been set with 0x%02X",
value);
135 this->error_code_ =
NONE;
147 auto status_byte = res[0];
149 int units = status_byte & 0x0e;
150 int status_bit = status_byte & 0x01;
152 if (status_bit != 0) {
154 ESP_LOGW(TAG,
"Reading AGS10 data failed: illegal status (not ready or sensor in pre-heat stage)!");
160 ESP_LOGE(TAG,
"Reading AGS10 data failed: unsupported units (%d)!", units);
187 if (!data.has_value()) {
189 ESP_LOGE(TAG,
"Reading AGS10 version failed!");
190 return optional<std::array<uint8_t, N>>();
194 auto crc_byte = res[
len];
196 if (crc_byte !=
crc8(res.data(),
len, 0xFF, 0x31,
true)) {
198 ESP_LOGE(TAG,
"Reading AGS10 version failed: crc error!");
199 return optional<std::array<uint8_t, N>>();
BedjetMode mode
BedJet operating mode.
virtual void setup()
Where the component's initialization should happen.
void status_set_warning()
void status_clear_warning()
optional< std::array< uint8_t, N > > read_and_check_(uint8_t a_register)
Read, checks and returns data from the sensor.
bool set_zero_point_with_factory_defaults()
Sets zero-point with factory defaults.
optional< uint8_t > read_version_()
Reads and returns a firmware version of AGS10.
enum esphome::ags10::AGS10Component::ErrorCode NONE
bool set_zero_point_with_current_resistance()
Sets zero-point with current sensor resistance.
optional< uint32_t > read_resistance_()
Reads and returns the resistance of AGS10.
optional< uint32_t > read_tvoc_()
Reads and returns value of TVOC.
void set_zero_point(AGS10SetZeroPointActionMode mode, uint16_t value)
Sets zero-point by mode; the value is only used for CUSTOM_VALUE.
bool set_zero_point_with(uint16_t value)
Sets zero-point with the value.
bool new_i2c_address(uint8_t newaddress)
Modifies target address of AGS10.
void dump_config() override
void set_i2c_address(uint8_t address)
We store the address of the device on the bus.
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
ESPHOME_LOG_TAG(TAG, "ags10")
AGS10SetZeroPointActionMode
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.