9static const char *
const TAG =
"mics_4514";
11static const uint8_t SENSOR_REGISTER = 0x04;
12static const uint8_t POWER_MODE_REGISTER = 0x0a;
18 ESP_LOGCONFIG(TAG,
"Waking up MICS 4514, sensors will have data after 3 minutes");
26 ESP_LOGCONFIG(TAG,
"Device already awake.");
29void MICS4514Component::dump_config() {
30 ESP_LOGCONFIG(TAG,
"MICS 4514:");
32 LOG_UPDATE_INTERVAL(
this);
33 LOG_SENSOR(
" ",
"Nitrogen Dioxide", this->nitrogen_dioxide_sensor_);
34 LOG_SENSOR(
" ",
"Carbon Monoxide", this->carbon_monoxide_sensor_);
35 LOG_SENSOR(
" ",
"Methane", this->methane_sensor_);
36 LOG_SENSOR(
" ",
"Ethanol", this->ethanol_sensor_);
37 LOG_SENSOR(
" ",
"Hydrogen", this->hydrogen_sensor_);
38 LOG_SENSOR(
" ",
"Ammonia", this->ammonia_sensor_);
40void MICS4514Component::update() {
50 ESP_LOGV(TAG,
"Got data: %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]);
65 if (this->carbon_monoxide_sensor_ !=
nullptr) {
69 }
else if (red_f < 0.01) {
72 co = 4.2 / pow(red_f, 1.2);
74 this->carbon_monoxide_sensor_->publish_state(co);
77 if (this->nitrogen_dioxide_sensor_ !=
nullptr) {
78 float nitrogendioxide = 0.0f;
80 nitrogendioxide = 0.0;
82 nitrogendioxide = 0.164 * pow(ox_f, 0.975);
84 this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide);
87 if (this->methane_sensor_ !=
nullptr) {
89 if (red_f > 0.9f || red_f < 0.5) {
92 methane = 630 / pow(red_f, 4.4);
94 this->methane_sensor_->publish_state(methane);
97 if (this->ethanol_sensor_ !=
nullptr) {
99 if (red_f > 1.0f || red_f < 0.02) {
102 ethanol = 1.52 / pow(red_f, 1.55);
104 this->ethanol_sensor_->publish_state(ethanol);
107 if (this->hydrogen_sensor_ !=
nullptr) {
108 float hydrogen = 0.0f;
109 if (red_f > 0.9f || red_f < 0.02) {
112 hydrogen = 0.85 / pow(red_f, 1.75);
114 this->hydrogen_sensor_->publish_state(hydrogen);
117 if (this->ammonia_sensor_ !=
nullptr) {
118 float ammonia = 0.0f;
119 if (red_f > 0.98f || red_f < 0.2532) {
122 ammonia = 0.9 / pow(red_f, 4.6);
124 this->ammonia_sensor_->publish_state(ammonia);
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.