diff --git a/esphome/components/light/base_light_effects.h b/esphome/components/light/base_light_effects.h index 5ab9f66ce4..a6ab299308 100644 --- a/esphome/components/light/base_light_effects.h +++ b/esphome/components/light/base_light_effects.h @@ -102,21 +102,24 @@ class RandomLightEffect : public LightEffect { class LambdaLightEffect : public LightEffect { public: - LambdaLightEffect(const std::string &name, std::function f, uint32_t update_interval) + LambdaLightEffect(const std::string &name, std::function f, uint32_t update_interval) : LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {} + void start() override { this->initial_run_ = true; } void apply() override { const uint32_t now = millis(); if (now - this->last_run_ >= this->update_interval_) { this->last_run_ = now; - this->f_(); + this->f_(this->initial_run_); + this->initial_run_ = false; } } protected: - std::function f_; + std::function f_; uint32_t update_interval_; uint32_t last_run_{0}; + bool initial_run_; }; class AutomationLightEffect : public LightEffect { diff --git a/esphome/components/light/effects.py b/esphome/components/light/effects.py index 4b2209c833..a987e0fc96 100644 --- a/esphome/components/light/effects.py +++ b/esphome/components/light/effects.py @@ -141,7 +141,9 @@ def register_addressable_effect( }, ) async def lambda_effect_to_code(config, effect_id): - lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [], return_type=cg.void) + lambda_ = await cg.process_lambda( + config[CONF_LAMBDA], [(bool, "initial_run")], return_type=cg.void + ) return cg.new_Pvariable( effect_id, config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL] )