Unexpected Filter Behavior

Edit:- ESPHome 2025.10.5
On ESP32 Devkit V1.

Not Seeing what I’d expect from the Code Below.
Simply trying to display the Fan Speed from My Printer Enclosure.

The Waveform from the Fan Tach looks Ok on the Scope, sitting at 3V & 20Hz with a bit of movement.

It jumps about a bit, but became more stable when I added the Median Filter.
Then tried sliding_window… & it jumped all over the place. mostly displaying numbers in the 2000 to 4500 RPM range, while the Scope still showed a more stable 20Hz.

Throttle_Average also jumps about, but more with a +/- 150 RPM variation.

Other thing I notice is that when using Median:, the Time_out seems to be ignored.

Any Suggestions on Why this is happening when I enable some of the commented out Filters?

Note Also I’m not trying to use any of the Average Types at the Same Time.

Code as follows:-

sensor:

  - platform: pulse_meter
    pin: 34 # Was 23
    unit_of_measurement: 'RPM'
    name: 'Fan 1 RPM'
    id: 'fan1_rpm'
    accuracy_decimals: 0

    timeout: 1s # Reset to 0 after 1 second without a pulse
    filters:
      - multiply: .5  # (2 pulses per Rev)
      - median:
          window_size: 20
          send_every: 10
          send_first_at: 1
#      - sliding_window_moving_average:
#          window_size: 15
#          send_every: 15
#      - throttle_average: 1s

You might want to try pulse_counter and look at this working example:

Which demonstrates getting fan RPM.

You need pullup on your tach input. Either internal or external. Gpio34 doesn’t have internal, so use some other pin
And pulse counter is better choice.

sensor:
  - platform: pulse_counter
    pin:
      number: GPIO33
      mode:
        input: true
        pullup: true

Wait, are your trying to read the values from a PWM controlled fan from the third pin?
PWM -pulse width modulated- feel the width
Where is it getting controlled from? Ask that. It might be easier.

The Source has a 5V Pull-Up that I’m Scaling back to 3.

Have been on a few other Pins,
But the Issue I’m trying to address is the behavior of the Filter.

It is reading fine with No Filter, but the display flicks about a bit in the 590 to 620 RPM Range.

That Steadied with Median:, but it killed the Timeout, so if the Fan Stopped.
It then took the default 5 minutes before it returned to zero.

So it’s the Filter Behavior I’m Looking for Assistance on.

Full block of Sensor Code with Comments on Behavior…

sensor:

  - platform: pulse_meter
    pin: 34 # Was 23
    unit_of_measurement: 'RPM'
    name: 'Fan 1 RPM'
    id: 'fan1_rpm'
    accuracy_decimals: 0
#    internal_filter_mode: PULSE #Default is EDGE # No Improvement
#    internal_filter: 2ms
    timeout: 1s # Reset to 0 after 1 second without a pulse
#    update_interval: 5s ## Errors, Not Applicable for Pulse_meter

    filters:
      - multiply: .5  # (2 pulses per Rev)
#      - median:   #Seems to Default Timeout Back to 5 Minutes
#          window_size: 20
#          send_every: 10
#          send_first_at: 1
#      - sliding_window_moving_average:  # Gives Widely Varying Readings
#          window_size: 100
#          send_every: 100
#      - throttle_average: 1s  # Also Causes Wildly Varying Readings

add a timeout filter (pick one from the examples, middle one looks like what you want).

# Example configuration entry
filters:
  - timeout: 10s  # sent value will be NaN
  - timeout:
      timeout: 10s
      value: !lambda return 0;
  - timeout:
      timeout: 10s
      value: last  # sent value will be the last value received by the filter

Ahhh,

filters:
  - timeout:
      timeout: 10s
      value: !lambda return 0;

So that should fix the issue with the initial filter disabling?

  - platform: pulse_meter
    pin: 34 # Was 23
    unit_of_measurement: 'RPM'
    name: 'Fan 1 RPM'
    id: 'fan1_rpm'
    accuracy_decimals: 0
    timeout: 1s # Reset to 0 after 1 second without a pulse

Thanks.

Will give it a Try in 12 hours.
As is Tomorrow morning here in Aus.

That Issue is Solved.
It was the Order in Which I was Applying the Filters that was causing the Unexpected Values being Passed.
Current Code is this, including Commented out Blocks.

sensor:

  - platform: pulse_meter
    pin: 34 # Was 23
    unit_of_measurement: 'RPM'
    name: 'Fan 1 RPM'
    id: 'fan1_rpm'
    accuracy_decimals: 0
#    internal_filter_mode: PULSE #Default is EDGE # No Improvement
#    internal_filter: 2ms
    timeout: 1s # Reset to 0 after 1 second without a pulse

    filters:
#      - throttle_average: 3s  # Works Now When Above Multiply.
      - sliding_window_moving_average:  # Needs to be Before Multiply.
          window_size: 100
          send_every: 10
      - multiply: .5  # (2 pulses per Rev)
      - lambda: 'return 5 * round(x / 5);' # Just to Round to Nearest Value when ther is Flicker.
#      - median:   #Seems to Default Timeout Back to 5 Minutes
#          window_size: 5
#          send_every: 5
#          send_first_at: 1
      - timeout: # Fixes Value Not Returning to Zero with Averaging Avtive.
          timeout: 1s
          value: !lambda return 0;