PID Climate (#885)

* PID Climate

* Add sensor for debugging PID output value

* Add dump_config, use percent

* Add more observable values

* Update

* Set target temperature

* Add autotuner

* Add algorithm explanation

* Add autotuner action, update controller

* Add simulator

* Format

* Change defaults

* Updates
This commit is contained in:
Otto Winter authored and GitHub committed 2020-01-04 12:43:11 +01:00
1 parent 05f9dede70
commit a6d31f05ee
11 files changed
+1064

No files matched your search

@@ -0,0 +1,47 @@
#include "pid_climate_sensor.h"
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace pid {
static const char *TAG = "pid.sensor";
void PIDClimateSensor::setup() {
this->parent_->add_on_pid_computed_callback([this]() { this->update_from_parent_(); });
this->update_from_parent_();
}
void PIDClimateSensor::update_from_parent_() {
float value;
switch (this->type_) {
case PID_SENSOR_TYPE_RESULT:
value = this->parent_->get_output_value();
break;
case PID_SENSOR_TYPE_ERROR:
value = this->parent_->get_error_value();
break;
case PID_SENSOR_TYPE_PROPORTIONAL:
value = this->parent_->get_proportional_term();
break;
case PID_SENSOR_TYPE_INTEGRAL:
value = this->parent_->get_integral_term();
break;
case PID_SENSOR_TYPE_DERIVATIVE:
value = this->parent_->get_derivative_term();
break;
case PID_SENSOR_TYPE_HEAT:
value = clamp(this->parent_->get_output_value(), 0.0f, 1.0f);
break;
case PID_SENSOR_TYPE_COOL:
value = clamp(-this->parent_->get_output_value(), 0.0f, 1.0f);
break;
default:
value = NAN;
break;
}
this->publish_state(value * 100.0f);
}
void PIDClimateSensor::dump_config() { LOG_SENSOR("", "PID Climate Sensor", this); }
} // namespace pid
} // namespace esphome