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;
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