186 uint8_t error_code = this->
rx_buffer_[APC1_MEASUREMENT_OFFSET_ERROR_CODE];
188 if (error_code != 0) {
189 for (uint8_t bit = 0; bit < ErrorStrings::COUNT; bit++) {
190 if (error_code & (1 << bit)) {
191 ESP_LOGW(TAG,
"APC1: %s", LOG_STR_ARG(ErrorStrings::get_log_str(bit, ErrorStrings::LAST_INDEX)));
196 ESP_LOGI(TAG,
"APC1: Hardware error cleared");
200 if (this->error_code_sensor_ !=
nullptr) {
201 this->error_code_sensor_->publish_state(error_code);
205 uint8_t aqi = this->
rx_buffer_[APC1_MEASUREMENT_OFFSET_AQI];
209 ESP_LOGI(TAG,
"APC1: Gas sensor warming up (AQI=0)");
213 ESP_LOGI(TAG,
"APC1: Gas sensor warm-up complete (AQI=%u)", aqi);
219 const auto u16 = [
this](uint8_t offset) {
222 const auto u32 = [
this](uint8_t offset) {
226 uint16_t pm_1_0 = u16(10);
227 uint16_t pm_2_5 = u16(12);
228 uint16_t pm_10_0 = u16(14);
229 uint16_t tvoc = u16(28);
230 uint16_t eco2 = u16(30);
231 float temp_comp =
static_cast<int16_t
>(u16(34)) / 10.0f;
232 float hum_comp = u16(36) / 10.0f;
234 ESP_LOGD(TAG,
"APC1: PM1.0: %u, PM2.5: %u, PM10: %u, TVOC: %u, eCO2: %u, AQI: %u, Temp: %.1f°C, Hum: %.1f%%", pm_1_0,
235 pm_2_5, pm_10_0, tvoc, eco2, aqi, temp_comp, hum_comp);
237 if (this->pm_1_0_std_sensor_ !=
nullptr)
238 this->pm_1_0_std_sensor_->publish_state(u16(4));
239 if (this->pm_2_5_std_sensor_ !=
nullptr)
240 this->pm_2_5_std_sensor_->publish_state(u16(6));
241 if (this->pm_10_0_std_sensor_ !=
nullptr)
242 this->pm_10_0_std_sensor_->publish_state(u16(8));
244 if (this->pm_1_0_sensor_ !=
nullptr)
245 this->pm_1_0_sensor_->publish_state(pm_1_0);
246 if (this->pm_2_5_sensor_ !=
nullptr)
247 this->pm_2_5_sensor_->publish_state(pm_2_5);
248 if (this->pm_10_0_sensor_ !=
nullptr)
249 this->pm_10_0_sensor_->publish_state(pm_10_0);
251 if (this->pm_0_3um_sensor_ !=
nullptr)
252 this->pm_0_3um_sensor_->publish_state(u16(16));
253 if (this->pm_0_5um_sensor_ !=
nullptr)
254 this->pm_0_5um_sensor_->publish_state(u16(18));
255 if (this->pm_1_0um_sensor_ !=
nullptr)
256 this->pm_1_0um_sensor_->publish_state(u16(20));
257 if (this->pm_2_5um_sensor_ !=
nullptr)
258 this->pm_2_5um_sensor_->publish_state(u16(22));
259 if (this->pm_5_0um_sensor_ !=
nullptr)
260 this->pm_5_0um_sensor_->publish_state(u16(24));
261 if (this->pm_10_0um_sensor_ !=
nullptr)
262 this->pm_10_0um_sensor_->publish_state(u16(26));
264 if (this->tvoc_sensor_ !=
nullptr)
265 this->tvoc_sensor_->publish_state(tvoc);
266 if (this->eco2_sensor_ !=
nullptr)
267 this->eco2_sensor_->publish_state(eco2);
268 if (this->aqi_sensor_ !=
nullptr)
269 this->aqi_sensor_->publish_state(aqi > 0 ? aqi : NAN);
271 if (this->temperature_sensor_ !=
nullptr)
272 this->temperature_sensor_->publish_state(temp_comp);
273 if (this->humidity_sensor_ !=
nullptr)
274 this->humidity_sensor_->publish_state(hum_comp);
276 if (this->raw_temperature_sensor_ !=
nullptr) {
277 this->raw_temperature_sensor_->publish_state(
static_cast<int16_t
>(u16(38)) / 10.0f);
279 if (this->raw_humidity_sensor_ !=
nullptr)
280 this->raw_humidity_sensor_->publish_state(u16(40) / 10.0f);
282 if (this->rs0_sensor_ !=
nullptr) {
283 this->rs0_sensor_->publish_state(u32(42));
285 if (this->rs2_sensor_ !=
nullptr) {
286 this->rs2_sensor_->publish_state(u32(50));
288 if (this->rs3_sensor_ !=
nullptr) {
289 this->rs3_sensor_->publish_state(u32(54));
294 const uint8_t *serial = this->
rx_buffer_.data() + APC1_DEVICE_INFO_OFFSET_SERIAL;
295 uint16_t fw_version =
297 ESP_LOGI(TAG,
"APC1: Module: %.6s, Serial: %08" PRIX32
"%08" PRIX32
", Firmware: 0x%04X (%u)",
298 reinterpret_cast<const char *
>(this->
rx_buffer_.data() + APC1_DEVICE_INFO_OFFSET_MODULE),
300 encode_uint32(serial[4], serial[5], serial[6], serial[7]), fw_version, fw_version);