From 801c1515f6c013290ff31a7712a439e0d61a82e0 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Wed, 12 Feb 2025 22:00:21 +0000 Subject: [PATCH] reset home once tension is gone --- blind.yaml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/blind.yaml b/blind.yaml index b1bfcf6..8e9cb15 100644 --- a/blind.yaml +++ b/blind.yaml @@ -152,6 +152,11 @@ globals: restore_value: no initial_value: "0" + - id: home_resetting_ + type: bool + restore_value: no + initial_value: "false" + stepper: - platform: tmc2209 id: motor @@ -172,12 +177,15 @@ stepper: args: [ "id(encoder)->get_state()", "id(motor)->current_direction", "cover_operation_to_str(id(pd_blinds)->current_operation)" ] - lambda: | - if (id(motor).current_direction < 0) - id(sensored_home_pos) = id(encoder)->get_state(); + if (id(motor).current_direction < 0) { + if (id(pd_blinds)->current_operation == COVER_OPERATION_IDLE) { + id(sensored_home_pos) = id(encoder)->get_state(); + } else { + // Reset home once the tension is released and the encoder is idle + id(home_resetting_) = true; + } + } - stepper.stop: motor - - cover.template.publish: - id: pd_blinds - state: OPEN - light.turn_on: id: led1 transition_length: 0s @@ -323,9 +331,15 @@ sensor: else if (delta < -2047) delta += 4096; if (delta == 0 && id(pd_blinds)->current_operation != COVER_OPERATION_IDLE) { + if (id(home_resetting_)) { + id(home_resetting_) = false; + id(sensored_home_pos) = id(encoder)->get_state(); + ESP_LOGI("cover", "idle at %d (home reset)", id(encoder_tracking_)[1]); + } else { + ESP_LOGI("cover", "idle at %d", id(encoder_tracking_)[1]); + } id(pd_blinds)->current_operation = COVER_OPERATION_IDLE; id(pd_blinds)->publish_state(false); - ESP_LOGI("cover", "idle at %d", id(encoder_tracking_)[1]); } if (delta < 2 && delta > -2) return {}; @@ -402,6 +416,7 @@ cover: ESP_LOGI("cover", "From %f to open (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); + id(home_resetting_) = false; id(motor).set_target(id(motor)->current_position + stepdelta); close_action: - lambda: |- @@ -411,6 +426,7 @@ cover: ESP_LOGI("cover", "From %f to closed (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); + id(home_resetting_) = false; id(motor).set_target(id(motor)->current_position + stepdelta); position_action: - lambda: |- @@ -420,4 +436,5 @@ cover: ESP_LOGI("cover", "From %f to %f (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, pos, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); + id(home_resetting_) = false; id(motor).set_target(id(motor)->current_position + stepdelta); -- 2.50.1