ESPHome  2024.12.2
pid_climate_sensor.cpp
Go to the documentation of this file.
1 #include "pid_climate_sensor.h"
2 #include "esphome/core/log.h"
3 #include "esphome/core/helpers.h"
4 
5 namespace esphome {
6 namespace pid {
7 
8 static const char *const TAG = "pid.sensor";
9 
11  this->parent_->add_on_pid_computed_callback([this]() { this->update_from_parent_(); });
12  this->update_from_parent_();
13 }
15  float value;
16  switch (this->type_) {
18  value = this->parent_->get_output_value();
19  break;
21  value = this->parent_->get_error_value();
22  break;
24  value = this->parent_->get_proportional_term();
25  break;
27  value = this->parent_->get_integral_term();
28  break;
30  value = this->parent_->get_derivative_term();
31  break;
33  value = clamp(this->parent_->get_output_value(), 0.0f, 1.0f);
34  break;
36  value = clamp(-this->parent_->get_output_value(), 0.0f, 1.0f);
37  break;
38  case PID_SENSOR_TYPE_KP:
39  value = this->parent_->get_kp();
40  this->publish_state(value);
41  return;
42  case PID_SENSOR_TYPE_KI:
43  value = this->parent_->get_ki();
44  this->publish_state(value);
45  return;
46  case PID_SENSOR_TYPE_KD:
47  value = this->parent_->get_kd();
48  this->publish_state(value);
49  return;
50  default:
51  value = NAN;
52  break;
53  }
54  this->publish_state(value * 100.0f);
55 }
56 void PIDClimateSensor::dump_config() { LOG_SENSOR("", "PID Climate Sensor", this); }
57 
58 } // namespace pid
59 } // namespace esphome
float get_integral_term() const
Definition: pid_climate.h:50
void add_on_pid_computed_callback(std::function< void()> &&callback)
Definition: pid_climate.h:67
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: helpers.h:93
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
float get_error_value() const
Definition: pid_climate.h:43
float get_output_value() const
Definition: pid_climate.h:42
float get_derivative_term() const
Definition: pid_climate.h:51
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
float get_proportional_term() const
Definition: pid_climate.h:49