Hi everyone!
My first home assistant post here! I had the same issue, but I did some tests to check how the filter works. I think the problem is that you are counting pulses using the rising edge, and in the pulse_counter documentation it says clearly it has to be on falling edge:
internal_filter ( Optional , Time): If a pulse shorter than this time is detected, it’s discarded and no pulse is counted. Defaults to 13us
. On the ESP32, this value can not be higher than 13us
, for the ESP8266 you can use larger intervals too. If you enable this, set up the count_mode
to increase on the falling edge, not leading edge. For S0 pulse meters that are used to meter power consumption 50-100 ms is a reasonable value.
So, I wrote a simple code to count values:
sensor:
- platform: pulse_counter
name: "rain_gauge"
pin:
number: D5
mode: INPUT_PULLUP
update_interval: 1s
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
internal_filter: 13us
filters:
- multiply: 0.0166666666666666666667
In this way, it’s shown the pulse count per second, every second. Then, using the function generator of my Picoscope, I generated a signal simulating some bouncings:
It’s counting 4, which is correct, since I have the filter to 13us and my shortest pulse is 17us long. Then I changed the filter time to 10ms, and now it’s counting 1 even if I send 2 pulses together. (Sorry, I uploaded more oscilloscope captures, but it’s telling me I can’t upload more than 1 image because I’m a new user… )
The limit where it counts 2 pulses is when I split the pulses about 12ms.
So, my final code is as follows:
sensor:
- platform: pulse_counter
name: "rain_gauge"
pin:
number: D5
mode: INPUT_PULLUP
update_interval: 60s
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
internal_filter: 10ms
unit_of_measurement: "mm"
icon: "mdi:water"
filters:
- multiply: 0.359254458
I guess it would be nice if there was some option to prevent sending data if it counts zero, I think it’s not much useful to fill the database with zeros.
Hope to help!