]> www.infradead.org Git - users/dwmw2/esp32-pool.git/commitdiff
Report opening/closing/idle
authorDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 11 Feb 2025 19:23:21 +0000 (19:23 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 11 Feb 2025 19:23:21 +0000 (19:23 +0000)
blind.yaml

index 5671c770248c90ca9dba6e43b3ef26e6704fca11..6236e37950a35bb9b1306f077b7e97162545bca8 100644 (file)
@@ -246,7 +246,6 @@ sensor:
     internal: true
     update_interval: 0ms
     filters:
-      - delta: 2 # throttle the high polling rate to only act on value changes
       # compute absolute position from angle value
       - lambda: |
           const uint16_t curr = x;
@@ -255,14 +254,30 @@ sensor:
             delta -= 4096;
           else if (delta < -2047)
             delta += 4096;
-          ESP_LOGD("angle", "Old %d new %d delta %d now %d home %d", id(encoder_tracking_)[0], curr, delta,
-            id(encoder_tracking_)[1] + delta, id(sensored_home_pos)          );
+          if (delta == 0 && id(pd_blinds)->current_operation != COVER_OPERATION_IDLE) {
+             id(pd_blinds)->current_operation = COVER_OPERATION_IDLE;
+             id(pd_blinds)->publish_state(false);
+             ESP_LOGI("cover", "idle");
+          }
+          if (delta < 2 && delta > -2)
+            return {};
           id(encoder_tracking_)[0] = curr;
           id(encoder_tracking_)[1] -= delta;
           if (id(encoder_tracking_)[1] < id(sensored_home_pos)) {
              ESP_LOGI("home", "Adjusted to %d", id(encoder_tracking_)[1]);
              id(sensored_home_pos) = id(encoder_tracking_)[1];
           }
+          ESP_LOGD("angle", "Old %d new %d delta %d now %d home %d", id(encoder_tracking_)[0], curr, delta,
+            id(encoder_tracking_)[1] + delta, id(sensored_home_pos));
+
+          if (delta < -100 && id(pd_blinds)->current_operation != COVER_OPERATION_CLOSING) {
+             id(pd_blinds)->current_operation= COVER_OPERATION_CLOSING;
+             ESP_LOGI("cover", "closing");
+          } else if (delta > 100 && id(pd_blinds)->current_operation != COVER_OPERATION_OPENING) {
+             id(pd_blinds)->current_operation = COVER_OPERATION_OPENING;
+             ESP_LOGI("cover", "opening");
+          }
+
           return id(encoder_tracking_)[1];
     accuracy_decimals: 0
     state_class: measurement