mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 10:14:13 +01:00
Add Integral Reset Action to PIDClimate (#1104)
This commit is contained in:
parent
7a16f846eb
commit
33212d1abf
4 changed files with 28 additions and 0 deletions
|
@ -7,6 +7,7 @@ from esphome.const import CONF_ID, CONF_SENSOR
|
|||
pid_ns = cg.esphome_ns.namespace('pid')
|
||||
PIDClimate = pid_ns.class_('PIDClimate', climate.Climate, cg.Component)
|
||||
PIDAutotuneAction = pid_ns.class_('PIDAutotuneAction', automation.Action)
|
||||
PIDResetIntegralTermAction = pid_ns.class_('PIDResetIntegralTermAction', automation.Action)
|
||||
|
||||
CONF_DEFAULT_TARGET_TEMPERATURE = 'default_target_temperature'
|
||||
|
||||
|
@ -64,6 +65,18 @@ def to_code(config):
|
|||
cg.add(var.set_default_target_temperature(config[CONF_DEFAULT_TARGET_TEMPERATURE]))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
'climate.pid.reset_integral_term',
|
||||
PIDResetIntegralTermAction,
|
||||
automation.maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(PIDClimate),
|
||||
})
|
||||
)
|
||||
def pid_reset_integral_term(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action('climate.pid.autotune', PIDAutotuneAction, automation.maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(PIDClimate),
|
||||
cv.Optional(CONF_NOISEBAND, default=0.25): cv.float_,
|
||||
|
|
|
@ -148,5 +148,7 @@ void PIDClimate::start_autotune(std::unique_ptr<PIDAutotuner> &&autotune) {
|
|||
});
|
||||
}
|
||||
|
||||
void PIDClimate::reset_integral_term() { this->controller_.reset_accumulated_integral(); }
|
||||
|
||||
} // namespace pid
|
||||
} // namespace esphome
|
||||
|
|
|
@ -39,6 +39,7 @@ class PIDClimate : public climate::Climate, public Component {
|
|||
default_target_temperature_ = default_target_temperature;
|
||||
}
|
||||
void start_autotune(std::unique_ptr<PIDAutotuner> &&autotune);
|
||||
void reset_integral_term();
|
||||
|
||||
protected:
|
||||
/// Override control to change settings of the climate device.
|
||||
|
@ -90,5 +91,15 @@ template<typename... Ts> class PIDAutotuneAction : public Action<Ts...> {
|
|||
PIDClimate *parent_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class PIDResetIntegralTermAction : public Action<Ts...> {
|
||||
public:
|
||||
PIDResetIntegralTermAction(PIDClimate *parent) : parent_(parent) {}
|
||||
|
||||
void play(Ts... x) { this->parent_->reset_integral_term(); }
|
||||
|
||||
protected:
|
||||
PIDClimate *parent_;
|
||||
};
|
||||
|
||||
} // namespace pid
|
||||
} // namespace esphome
|
||||
|
|
|
@ -40,6 +40,8 @@ struct PIDController {
|
|||
return proportional_term + integral_term + derivative_term;
|
||||
}
|
||||
|
||||
void reset_accumulated_integral() { accumulated_integral_ = 0; }
|
||||
|
||||
/// Proportional gain K_p.
|
||||
float kp = 0;
|
||||
/// Integral gain K_i.
|
||||
|
|
Loading…
Reference in a new issue