Merge pull request #24 from slimcdk/main

Suppress aggressive encoder polling
This commit is contained in:
joshr120 2025-02-12 22:06:49 +13:00 committed by GitHub
commit cc3eaf42a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 12 deletions

View File

@ -71,14 +71,6 @@ esphome:
- lambda: id(sensored_home_pos) = id(encoder)->get_state(); # Set the home position to power on position
# - button.press: home
web_server:
include_internal: true
ota: false
version: 3
log: false
i2c:
sda: 8
scl: 9
@ -196,7 +188,7 @@ binary_sensor:
filters:
- delayed_on: 10ms
on_press:
- tmc2209.disable: motor
- stepper.stop: motor
- platform: gpio
name: Button 3
@ -224,6 +216,7 @@ sensor:
name: Encoder
id: encoder
update_interval: 0s # beware of the polling rate
internal: true # don't publish sensor data to Home Assistant or web server
filters:
- delta: 2 # throttle the high polling rate to only act on value changes
# compute absolute position from angle value
@ -240,6 +233,7 @@ sensor:
id(encoder_tracking_)[0] = curr;
return id(encoder_tracking_)[1];
- multiply: -1.0
- throttle: 250ms # limit the amount of new sensor states from this component
accuracy_decimals: 0
state_class: measurement
@ -260,7 +254,7 @@ cover:
# internal: true
lambda: "return 1.0 - ((id(encoder)->get_state()-id(sensored_home_pos)) / ${encoder_closed_pos});"
stop_action:
- tmc2209.disable: motor
- stepper.stop: motor
open_action:
- stepper.report_position:
id: motor

View File

@ -178,9 +178,10 @@ sensor:
name: Encoder
id: encoder
update_interval: 0s # beware of the polling rate
internal: false # publish sensor data to Home Assistant and/or web server
filters:
- delta: 2
# filter which computes absolute position from angle value
- 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; //current encoder value 0-4095
const uint16_t prev = id(encoder_tracking_)[0]; //previous encoder value 0-4095
@ -193,6 +194,8 @@ sensor:
}
id(encoder_tracking_)[0] = curr;
return id(encoder_tracking_)[1];
- multiply: -1.0
- throttle: 100ms # limit the amount of new sensor states from this component
accuracy_decimals: 0
state_class: measurement