diff --git a/esphome/components/slow_pwm/slow_pwm_output.cpp b/esphome/components/slow_pwm/slow_pwm_output.cpp index 81c721a866..d6b2cdfe12 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.cpp +++ b/esphome/components/slow_pwm/slow_pwm_output.cpp @@ -70,7 +70,7 @@ void SlowPWMOutput::dump_config() { void SlowPWMOutput::write_state(float state) { this->state_ = state; if (this->restart_cycle_on_state_change_) - this->period_start_time_ = millis(); + this->restart_cycle(); } } // namespace slow_pwm diff --git a/esphome/components/slow_pwm/slow_pwm_output.h b/esphome/components/slow_pwm/slow_pwm_output.h index be45736864..3e5a3e2a40 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.h +++ b/esphome/components/slow_pwm/slow_pwm_output.h @@ -14,6 +14,7 @@ class SlowPWMOutput : public output::FloatOutput, public Component { void set_restart_cycle_on_state_change(bool restart_cycle_on_state_change) { restart_cycle_on_state_change_ = restart_cycle_on_state_change; } + void restart_cycle() { this->period_start_time_ = millis(); } /// Initialize pin void setup() override;