esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

sliding_window_moving_average: send_first_at must be smaller than or equal to send_every? #5353

Open ptr727 opened 10 months ago

ptr727 commented 10 months ago

The problem

Using a sliding_window_moving_average on an adc sensor.
Want to use window_size: 64, send_every: 32, and send_first_at: 64.
But get an error send_first_at must be smaller than or equal to send_every! 64 <= 32

This does not make sense to me, if the first value is emitted after only 32 samples, then the buffer/window is only half full, and the first emitted value is only sampled over 32 samples, not 64 as desired.

I want all emitted values to be averaged over 64 samples, that means first fill the window with 64 samples, then start emitting values, then emit again after another 32, and repeat.

See https://github.com/esphome/esphome/blob/aa8a533da6eb35f0ab6ffb64423a6bffe99c2f03/esphome/components/sensor/__init__.py#L168

Which version of ESPHome has the issue?

2023.12.5

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

NA

What platform are you using?

ESP32

Board

esp32dev

Component causing the issue

sensor

Example YAML snippet

# https://esphome.io/components/sensor/
sensor:

  # https://esphome.io/components/sensor/adc.html
  - platform: adc
    pin: GPIO36
    name: ${device_name}_adc_buttons
    id: adc_buttons
    attenuation: 11dB
    # Average over 64 samples, emit every 32 samples, every 320ms at 10ms sampling
    # ~3 times per second to keep key presses responsive
    update_interval: 10ms
    # https://esphome.io/components/sensor/index.html#sliding-window-moving-average
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 64
          send_every: 32
          # send_first_at: 64
          send_first_at: 32
    # Used internally for switch templates only, do not report to HA
    internal: false # true

Anything in the logs that might be useful for us?

No response

Additional information

No response

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.