Make pid cimate respect mode

This commit is contained in:
Anton Sergunov 2024-11-13 13:57:07 +00:00
parent 0a92405f2d
commit 31939918dc
2 changed files with 16 additions and 5 deletions

View file

@ -90,6 +90,18 @@ void PIDClimate::dump_config() {
this->autotuner_->dump_config();
}
}
float PIDClimate::value_by_mode_(float value) {
switch (this->mode) {
case climate::CLIMATE_MODE_OFF:
return 0.0f;
case climate::CLIMATE_MODE_HEAT:
return std::max(0.0f, value);
case climate::CLIMATE_MODE_COOL:
return std::min(0.0f, value);
default:
return value;
}
}
void PIDClimate::write_output_(float value) {
this->output_value_ = value;
@ -147,11 +159,7 @@ void PIDClimate::update_pid_() {
}
}
if (this->mode == climate::CLIMATE_MODE_OFF) {
this->write_output_(0.0);
} else {
this->write_output_(value);
}
this->write_output_(this->value_by_mode_(value));
if (this->do_publish_)
this->publish_state();

View file

@ -84,6 +84,9 @@ class PIDClimate : public climate::Climate, public Component {
bool supports_cool_() const { return this->cool_output_ != nullptr; }
bool supports_heat_() const { return this->heat_output_ != nullptr; }
/// Return cloest possible output value with respect to mode
float value_by_mode_(float value) const;
void write_output_(float value);
/// The sensor used for getting the current temperature