@@ -11,7 +11,7 @@ namespace esphome
1111 {
1212
1313 static const char *const TAG = " sen5x" ;
14- static const char *const ESP_LOG_MSG_CO2_CAL_FAIL = " Perform Forced CO2 Calibration failed" ;
14+ static const char *const ESP_LOG_MSG_CO2_CAL_FAIL = " Perform Forced CO₂ Calibration failed" ;
1515 static const char *const ESP_LOG_MSG_ACT_SHT_HEATER_FAIL = " Activate SHT Heater failed" ;
1616 static const char *const ESP_LOG_MSG_FAN_CLEAN_FAIL = " Fan Cleaning failed" ;
1717
@@ -473,14 +473,14 @@ namespace esphome
473473 this ->model_ .value () == SEN55 || this ->model_ .value () == SEN60 ||
474474 this ->model_ .value () == SEN65 || this ->model_ .value () == SEN68))
475475 {
476- ESP_LOGE (TAG, " CO2 Sensor Auto Self Calibrate Parameter is not supported" );
476+ ESP_LOGE (TAG, " CO₂ Sensor Auto Self Calibrate Parameter is not supported" );
477477 this ->error_code_ = UNSUPPORTED_CONF;
478478 this ->mark_failed ();
479479 return ;
480480 }
481481 if (!this ->write_command (SEN6X_CMD_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION, this ->co2_auto_calibrate_ .value () ? 0x01 : 0x00 ))
482482 {
483- ESP_LOGE (TAG, " Failed to set CO2 Sensor Automatic Self Calibration" );
483+ ESP_LOGE (TAG, " Failed to set CO₂ Sensor Automatic Self Calibration" );
484484 this ->error_code_ = COMMUNICATION_FAILED;
485485 this ->mark_failed ();
486486 return ;
@@ -500,14 +500,14 @@ namespace esphome
500500 this ->model_ .value () == SEN55 || this ->model_ .value () == SEN60 ||
501501 this ->model_ .value () == SEN65 || this ->model_ .value () == SEN68))
502502 {
503- ESP_LOGE (TAG, " CO2 Altitude Compensation Parameter is not supported" );
503+ ESP_LOGE (TAG, " CO₂ Altitude Compensation Parameter is not supported" );
504504 this ->error_code_ = UNSUPPORTED_CONF;
505505 this ->mark_failed ();
506506 return ;
507507 }
508508 if (!this ->write_command (SEN6X_CMD_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION, this ->co2_auto_calibrate_ .value () ? 0x01 : 0x00 ))
509509 {
510- ESP_LOGE (TAG, " Failed to set CO2 Sensor Automatic Self Calibration" );
510+ ESP_LOGE (TAG, " Failed to set CO₂ Sensor Automatic Self Calibration" );
511511 this ->error_code_ = COMMUNICATION_FAILED;
512512 this ->mark_failed ();
513513 return ;
@@ -557,7 +557,7 @@ namespace esphome
557557 this ->model_ .value () == SEN55 || this ->model_ .value () == SEN60 ||
558558 this ->model_ .value () == SEN65 || this ->model_ .value () == SEN68))
559559 {
560- ESP_LOGE (TAG, " CO2 Sensor is not supported" );
560+ ESP_LOGE (TAG, " CO₂ Sensor is not supported" );
561561 this ->nox_sensor_ = nullptr ; // mark as not used
562562 this ->error_code_ = UNSUPPORTED_CONF;
563563 this ->mark_failed ();
@@ -672,7 +672,7 @@ namespace esphome
672672 LOG_SENSOR (" " , " Humidity" , this ->humidity_sensor_ );
673673 LOG_SENSOR (" " , " VOC" , this ->voc_sensor_ );
674674 LOG_SENSOR (" " , " NOx" , this ->nox_sensor_ );
675- LOG_SENSOR (" " , " CO2 " , this ->co2_sensor_ );
675+ LOG_SENSOR (" " , " CO₂ " , this ->co2_sensor_ );
676676 if (this ->co2_sensor_ != nullptr )
677677 {
678678 ESP_LOGCONFIG (TAG, " Automatic self calibration: %s" , co2_auto_calibrate_ ? " On" : " Off" );
@@ -1007,22 +1007,30 @@ namespace esphome
10071007
10081008 void SEN5XComponent::set_ambient_pressure_compensation (float pressure_in_hpa)
10091009 {
1010- uint16_t new_ambient_pressure = (uint16_t )pressure_in_hpa;
1011- if (!this ->initialized_ )
1010+ if (this ->model_ .value () == SEN63C || this ->model_ .value () == SEN66)
10121011 {
1013- this ->co2_ambient_pressure_ = new_ambient_pressure;
1014- return ;
1015- }
1016- // Only send pressure value if it has changed since last update
1017- if (new_ambient_pressure != this ->co2_ambient_pressure_ )
1018- {
1019- update_co2_ambient_pressure_compensation_ (new_ambient_pressure);
1020- this ->co2_ambient_pressure_ = new_ambient_pressure;
1021- this ->set_timeout (20 , [this ]() {});
1012+ uint16_t new_ambient_pressure = (uint16_t )pressure_in_hpa;
1013+ if (!this ->initialized_ )
1014+ {
1015+ this ->co2_ambient_pressure_ = new_ambient_pressure;
1016+ return ;
1017+ }
1018+ // Only send pressure value if it has changed since last update
1019+ if (new_ambient_pressure != this ->co2_ambient_pressure_ )
1020+ {
1021+ update_co2_ambient_pressure_compensation_ (new_ambient_pressure);
1022+ this ->co2_ambient_pressure_ = new_ambient_pressure;
1023+ this ->set_timeout (20 , [this ]() {});
1024+ }
1025+ else
1026+ {
1027+ ESP_LOGD (TAG, " Ambient Pressure compensation skipped - no change required" );
1028+ }
10221029 }
10231030 else
10241031 {
1025- ESP_LOGD (TAG, " Ambient Pressure compensation skipped - no change required" );
1032+ ESP_LOGE (TAG, " Set Ambient Pressure Compensation is not supported" );
1033+ return false ;
10261034 }
10271035 }
10281036
@@ -1122,47 +1130,55 @@ namespace esphome
11221130
11231131 bool SEN5XComponent::perform_forced_co2_calibration (uint16_t co2)
11241132 {
1125- ESP_LOGE (TAG, " Perform Forced CO2 Calibration started, target co2=%d" , co2);
1126- this ->initialized_ = false ; // prevent update from trying to read the sensors
1127- // measurements must be stopped first
1128- if (!this ->stop_measurements_ ())
1133+ if (this ->model_ .value () == SEN63C || this ->model_ .value () == SEN66)
11291134 {
1130- ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1131- this ->initialized_ = true ;
1132- return true ;
1133- }
1134- this ->set_timeout (1000 , [this , co2]()
1135- {
1136- if (!this ->write_command (SEN6X_CMD_PERFORM_FORCED_CO2_RECALIBRATION, co2)) {
1137- ESP_LOGE (TAG, " I2C Write error Perform Forced CO2 Recalibration (error=%d)" , this ->last_error_ );
1138- if (!this ->running_ ) {
1139- this ->start_measurements_ ();
1140- ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1141- }
1142- } else {
1143- this ->set_timeout (500 , [this ]() {
1144- uint16_t correction = 0 ;
1145- if (!this ->read_data (correction)) {
1135+ ESP_LOGE (TAG, " Perform Forced CO₂ Calibration started, target co2=%d" , co2);
1136+ this ->initialized_ = false ; // prevent update from trying to read the sensors
1137+ // measurements must be stopped first
1138+ if (!this ->stop_measurements_ ())
1139+ {
1140+ ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1141+ this ->initialized_ = true ;
1142+ return true ;
1143+ }
1144+ this ->set_timeout (1000 , [this , co2]()
1145+ {
1146+ if (!this ->write_command (SEN6X_CMD_PERFORM_FORCED_CO2_RECALIBRATION, co2)) {
1147+ ESP_LOGE (TAG, " I2C Write error Perform Forced CO₂ Recalibration (error=%d)" , this ->last_error_ );
1148+ if (!this ->running_ ) {
11461149 this ->start_measurements_ ();
11471150 ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1148- } else {
1149- if (correction == 0xFFFF ) {
1151+ }
1152+ } else {
1153+ this ->set_timeout (500 , [this ]() {
1154+ uint16_t correction = 0 ;
1155+ if (!this ->read_data (correction)) {
11501156 this ->start_measurements_ ();
1151- ESP_LOGE (TAG, " Perform Forced CO2 Calibration command reports failure " );
1157+ ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL );
11521158 } else {
1153- if (!this ->start_measurements_ ()) {
1154- ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1159+ if (correction == 0xFFFF ) {
1160+ this ->start_measurements_ ();
1161+ ESP_LOGE (TAG, " Perform Forced CO₂ Calibration command reports failure" );
11551162 } else {
1156- ESP_LOGD (TAG, " Perform Forced CO2 Calibration complete" );
1163+ if (!this ->start_measurements_ ()) {
1164+ ESP_LOGE (TAG, ESP_LOG_MSG_CO2_CAL_FAIL);
1165+ } else {
1166+ ESP_LOGD (TAG, " Perform Forced CO₂ Calibration complete" );
1167+ }
11571168 }
11581169 }
1159- }
1160- });
1161- }
1162- this ->set_timeout (50 , [this ]() {
1163- this ->initialized_ = true ;
1164- }); });
1165- return true ;
1170+ });
1171+ }
1172+ this ->set_timeout (50 , [this ]() {
1173+ this ->initialized_ = true ;
1174+ }); });
1175+ return true ;
1176+ }
1177+ else
1178+ {
1179+ ESP_LOGE (TAG, " Perform Forced CO₂ Calibration is not supported" );
1180+ return false ;
1181+ }
11661182 }
11671183 } // namespace sen5x
11681184} // namespace esphome
0 commit comments