diff --git a/esphome/components/combination/combination.cpp b/esphome/components/combination/combination.cpp index 27d6af1346..b858eee4ee 100644 --- a/esphome/components/combination/combination.cpp +++ b/esphome/components/combination/combination.cpp @@ -60,6 +60,8 @@ void KalmanCombinationComponent::dump_config() { void KalmanCombinationComponent::setup() { for (auto &source : this->sensor_sources_) { + // [&source] is safe: source refers to a FixedVector element that never reallocates, + // so the reference remains valid for the component's lifetime. source.sensor->add_on_state_callback([&source](float x) -> void { static_cast(source.parent)->correct_(x, source.compute(x)); });