10static constexpr uint32_t WARMUP_TIMEOUT_ID = 0;
12static const uint8_t SENSOR_REGISTER = 0x04;
13static const uint8_t POWER_MODE_REGISTER = 0x0a;
19 ESP_LOGCONFIG(TAG,
"Waking up MICS 4514, sensors will have data after 3 minutes");
27 ESP_LOGCONFIG(TAG,
"Device already awake.");
30void MICS4514Component::dump_config() {
31 ESP_LOGCONFIG(TAG,
"MICS 4514:");
33 LOG_UPDATE_INTERVAL(
this);
34 LOG_SENSOR(
" ",
"Nitrogen Dioxide", this->nitrogen_dioxide_sensor_);
35 LOG_SENSOR(
" ",
"Carbon Monoxide", this->carbon_monoxide_sensor_);
36 LOG_SENSOR(
" ",
"Methane", this->methane_sensor_);
37 LOG_SENSOR(
" ",
"Ethanol", this->ethanol_sensor_);
38 LOG_SENSOR(
" ",
"Hydrogen", this->hydrogen_sensor_);
39 LOG_SENSOR(
" ",
"Ammonia", this->ammonia_sensor_);
41void MICS4514Component::update() {
48 ESP_LOGV(TAG,
"Got data: %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]);
61 ESP_LOGW(TAG,
"Calibration values are zero, retrying");
69 if (this->carbon_monoxide_sensor_ !=
nullptr) {
73 }
else if (red_f < 0.01f) {
76 co = 4.2f / powf(red_f, 1.2f);
78 this->carbon_monoxide_sensor_->publish_state(co);
81 if (this->nitrogen_dioxide_sensor_ !=
nullptr) {
82 float nitrogendioxide = 0.0f;
84 nitrogendioxide = 0.0;
86 nitrogendioxide = 0.164f * powf(ox_f, 0.975f);
88 this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide);
91 if (this->methane_sensor_ !=
nullptr) {
93 if (red_f > 0.9f || red_f < 0.5f) {
96 methane = 630 / powf(red_f, 4.4f);
98 this->methane_sensor_->publish_state(methane);
101 if (this->ethanol_sensor_ !=
nullptr) {
102 float ethanol = 0.0f;
103 if (red_f > 1.0f || red_f < 0.02f) {
106 ethanol = 1.52f / powf(red_f, 1.55f);
108 this->ethanol_sensor_->publish_state(ethanol);
111 if (this->hydrogen_sensor_ !=
nullptr) {
112 float hydrogen = 0.0f;
113 if (red_f > 0.9f || red_f < 0.02f) {
116 hydrogen = 0.85f / powf(red_f, 1.75f);
118 this->hydrogen_sensor_->publish_state(hydrogen);
121 if (this->ammonia_sensor_ !=
nullptr) {
122 float ammonia = 0.0f;
123 if (red_f > 0.98f || red_f < 0.2532f) {
126 ammonia = 0.9f / powf(red_f, 4.6f);
128 this->ammonia_sensor_->publish_state(ammonia);