Filter min/max based on binary sensor value very slow

Hi,

I’m trying to get a more accurate range of values from a DIY bed presence sensor to use in HA by getting a min and max value over the past 5 values. If any value min is below x or above y I can the safely determine the bed is occupied or not.

However, the min/max sensors are really slow to change and respond. It takes about 5 minutes for a change to process, while the window is set to only 5, so I basically assumed this would take 5 seconds at most?

This is my current config:

esp32_touch:
   setup_mode: false
binary_sensor:
   - platform: esp32_touch
     name: "Top Right"
     pin: GPIO15
     threshold: 48
     id: top_right     
     filters:
       - delayed_on_off: 1s
     
sensor:
  - platform: template
    name: "Bed Top Right Readings"
    id: "top_right_readings"
    update_interval: 5s
    accuracy_decimals: 0
    lambda: |-
      return ((uint32_t) id(top_right)->get_value());
  - platform: template
    name: "Bed minimum"
    id: "top_right_minimum"
    filters:
       - min:
           window_size: 5
           send_every: 5
           send_first_at: 5
    lambda: |-
      return ((uint32_t) id(top_right)->get_value());
  - platform: template
    name: "Bed maximum"
    id: "top_right_maximum"
    filters:
       - max:
           window_size: 5
           send_every: 5
           send_first_at: 5
    lambda: |-
      return ((uint32_t) id(top_right)->get_value());

Any ideas what I’m doing wrong or is this supposed to take this long?

Regards,

Eduard

You might try adding update_interval: 5s to each of the min & max template sensors.
By default they will update only once per minute, and the filters you have on therm won’t report changes for 5 minutes as a result.
After adding the 5s interval, you’ll see their reports ~25 seconds after startup.