From ad6c5ff11d8bdcb8b180554b20c914838dce2799 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 10 Feb 2022 11:12:05 +1300 Subject: [PATCH] Clamp rotary_encoder restored value to min and max (#3184) --- esphome/components/rotary_encoder/rotary_encoder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/rotary_encoder/rotary_encoder.cpp b/esphome/components/rotary_encoder/rotary_encoder.cpp index c5227b41a7..c5e9cec596 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.cpp +++ b/esphome/components/rotary_encoder/rotary_encoder.cpp @@ -138,6 +138,8 @@ void RotaryEncoderSensor::setup() { initial_value = 0; break; } + initial_value = clamp(initial_value, this->store_.min_value, this->store_.max_value); + this->store_.counter = initial_value; this->store_.last_read = initial_value;