Update MiCS Values (#7173)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Trevor Schirmer 2024-08-29 20:36:32 -04:00 committed by GitHub
parent f8e8bd2c24
commit a5d46ae9e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -70,72 +70,62 @@ void MICS4514Component::update() {
if (this->carbon_monoxide_sensor_ != nullptr) { if (this->carbon_monoxide_sensor_ != nullptr) {
float co = 0.0f; float co = 0.0f;
if (red_f <= 0.425f) { if (red_f > 3.4f) {
co = (0.425f - red_f) / 0.000405f; co = 0.0;
if (co < 1.0f) } else if (red_f < 0.01) {
co = 0.0f; co = 1000.0;
if (co > 1000.0f) } else {
co = 1000.0f; co = 4.2 / pow(red_f, 1.2);
} }
this->carbon_monoxide_sensor_->publish_state(co); this->carbon_monoxide_sensor_->publish_state(co);
} }
if (this->nitrogen_dioxide_sensor_ != nullptr) { if (this->nitrogen_dioxide_sensor_ != nullptr) {
float nitrogendioxide = 0.0f; float nitrogendioxide = 0.0f;
if (ox_f >= 1.1f) { if (ox_f < 0.3f) {
nitrogendioxide = (ox_f - 0.045f) / 6.13f; nitrogendioxide = 0.0;
if (nitrogendioxide < 0.1f) } else {
nitrogendioxide = 0.0f; nitrogendioxide = 0.164 * pow(ox_f, 0.975);
if (nitrogendioxide > 10.0f)
nitrogendioxide = 10.0f;
} }
this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide); this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide);
} }
if (this->methane_sensor_ != nullptr) { if (this->methane_sensor_ != nullptr) {
float methane = 0.0f; float methane = 0.0f;
if (red_f <= 0.786f) { if (red_f > 0.9f || red_f < 0.5) { // outside the range->unlikely
methane = (0.786f - red_f) / 0.000023f; methane = 0.0;
if (methane < 1000.0f) } else {
methane = 0.0f; methane = 630 / pow(red_f, 4.4);
if (methane > 25000.0f)
methane = 25000.0f;
} }
this->methane_sensor_->publish_state(methane); this->methane_sensor_->publish_state(methane);
} }
if (this->ethanol_sensor_ != nullptr) { if (this->ethanol_sensor_ != nullptr) {
float ethanol = 0.0f; float ethanol = 0.0f;
if (red_f <= 0.306f) { if (red_f > 1.0f || red_f < 0.02) { // outside the range->unlikely
ethanol = (0.306f - red_f) / 0.00057f; ethanol = 0.0;
if (ethanol < 10.0f) } else {
ethanol = 0.0f; ethanol = 1.52 / pow(red_f, 1.55);
if (ethanol > 500.0f)
ethanol = 500.0f;
} }
this->ethanol_sensor_->publish_state(ethanol); this->ethanol_sensor_->publish_state(ethanol);
} }
if (this->hydrogen_sensor_ != nullptr) { if (this->hydrogen_sensor_ != nullptr) {
float hydrogen = 0.0f; float hydrogen = 0.0f;
if (red_f <= 0.279f) { if (red_f > 0.9f || red_f < 0.02) { // outside the range->unlikely
hydrogen = (0.279f - red_f) / 0.00026f; hydrogen = 0.0;
if (hydrogen < 1.0f) } else {
hydrogen = 0.0f; hydrogen = 0.85 / pow(red_f, 1.75);
if (hydrogen > 1000.0f)
hydrogen = 1000.0f;
} }
this->hydrogen_sensor_->publish_state(hydrogen); this->hydrogen_sensor_->publish_state(hydrogen);
} }
if (this->ammonia_sensor_ != nullptr) { if (this->ammonia_sensor_ != nullptr) {
float ammonia = 0.0f; float ammonia = 0.0f;
if (red_f <= 0.8f) { if (red_f > 0.98f || red_f < 0.2532) { // outside the ammonia range->unlikely
ammonia = (0.8f - red_f) / 0.0015f; ammonia = 0.0;
if (ammonia < 1.0f) } else {
ammonia = 0.0f; ammonia = 0.9 / pow(red_f, 4.6);
if (ammonia > 500.0f)
ammonia = 500.0f;
} }
this->ammonia_sensor_->publish_state(ammonia); this->ammonia_sensor_->publish_state(ammonia);
} }