Pulse_counter not counting properly

I’m pretty new with esphome, I want to make a small weather station with the weather kit from sparkfun ad both the rain gauge and the anemometer send pulses to keep track of precipitation and wind speed (ex. Rain Gauge: 1 pulse = 0.254mm Anemometer: 1 pulse per second = 2.4km/h).
Now I found the pulse_counter with the “Total” attribute which should give me the total pulses, so I built a small circuit on a breadboard with a button instead of the reed switches used by the rain gauge and the anemometer to test it out.

sensor:
  - platform: pulse_counter
    pin:
      number: 21
      inverted: true
      mode:
        input: true
        pullup: true
    name: 'Pulsazioni'
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 10s
    use_pcnt: False
    internal_filter: 50us

    total:
      name: 'Pulsazioni Totali'

This is the code, as you can see I tried also to disable the esp32 dedicated hardware to increase the internal filter but the issue it’s still there. The issue is if I click (whether I do it quickly or slowly) the button for example 15 times the registered pulsed could go from the exact value to even 8-12 pulses more, so I could even get a total of 27 clicks.
The only difference I saw was when I set the internal filter value to 1ms which caused to count less clicks than the actual made (ex. 10 click made and 6 clicks counted)
The pulse_counter documentations also says on the esp32 it should be highly accurate, so I suppose I’m doing something wrong but can’t figure out what.

In your case the pulse meter might be worth a look :eyes: :point_down:

I already saw that and tested it. I got the same issue, still counts more clicks than I actually do.

I use pulse meter for my anemometer. It does not count but measure the frequency of each pulse and convert that into pulses per minute equivalent. It is more accurate, but it does not rule out noise that is picked up on the data line or the need for a proper pull up resistor. If you search there are a number of threads on this subject and I will not repeat it here.

Not knowing your specifics but your sensor might be floating.

at the moment I’m only using a button to emulate a pulse, I don’t know if this could be the origin of the issue. I haven’t bought the weather kit yet so I cannot try directly with the anemometer

And I’ll give a look to the other post about pulse meter

That sounds like you’re experiencing switch bouncing as the switch contacts are rattling when closing.

You might need a debounce circuit on the switch or the debounce filter on the input:

Ok I finally found a way to use the pulse_meter. I placed an external pullup resistor and now the pulse_meter works fine so I will use that. But I’m still curious about why in this configuration the pulse_counter doesn’t recognize any input (both with pullup or pulldown resistor) and same with pulse_meter with a Pulldown.

I didn’t knew about that filter. I’ll give it a try asap.

Can you share your code fore pulse_meter rain gauge and anemometer ?
Thx