From d61e2f9c29543e19c79b6accaf94a47b11cf87ab Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:06:13 -0500 Subject: [PATCH] [light] Fix millis overflow in transition progress and flash timing (#14292) Co-authored-by: J. Nick Koston Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- esphome/components/light/light_transformer.h | 7 +++---- esphome/components/light/transformers.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/light/light_transformer.h b/esphome/components/light/light_transformer.h index 079c2d2ae0..b9535c834c 100644 --- a/esphome/components/light/light_transformer.h +++ b/esphome/components/light/light_transformer.h @@ -44,12 +44,11 @@ class LightTransformer { /// The progress of this transition, on a scale of 0 to 1. float get_progress_() { uint32_t now = esphome::millis(); - if (now < this->start_time_) - return 0.0f; - if (now >= this->start_time_ + this->length_) + uint32_t elapsed = now - this->start_time_; + if (elapsed >= this->length_) return 1.0f; - return clamp((now - this->start_time_) / float(this->length_), 0.0f, 1.0f); + return clamp(elapsed / float(this->length_), 0.0f, 1.0f); } uint32_t start_time_; diff --git a/esphome/components/light/transformers.h b/esphome/components/light/transformers.h index a26713b723..b6e5e08f2b 100644 --- a/esphome/components/light/transformers.h +++ b/esphome/components/light/transformers.h @@ -78,7 +78,7 @@ class LightFlashTransformer : public LightTransformer { optional apply() override { optional result = {}; - if (this->transformer_ == nullptr && millis() > this->start_time_ + this->length_ - this->transition_length_) { + if (this->transformer_ == nullptr && millis() - this->start_time_ > this->length_ - this->transition_length_) { // second transition back to start value this->transformer_ = this->state_.get_output()->create_default_transition(); this->transformer_->setup(this->state_.current_values, this->get_start_values(), this->transition_length_);