The ESP32 is connected to an inductive proximity sensor and count a pulse for every 1 Liter of water.
The code below is working fine and returns accurate reading. But if I change the value of update_interval to 6 seconds, the reading starts to drift up by about 17%.
I don’t really need to have updates more frequently than every 60s, but I’m curious about what is causing the isue.
sensor:
- platform: pulse_counter
pin:
number: GPIO2
update_interval: 60s #60s is the default value
name: "Water Meter Pulse"
unit_of_measurement: "L"
icon: "mdi:water"
total:
name: "Water Meter Total"
unit_of_measurement: "L"
id: water_meter_total
device_class: water
state_class: total_increasing
accuracy_decimals: 0
filters:
- offset: 271014
I think it just depends on the frequency. If you had 200 pulses/6s it would be more accurate than if you have 2 pulses/6s.
Try pulse meter component, it counts time between pulses and might be better match for low frequency.
I don’t see how that could affect the accuracy. If I have 100 pulses in 60 seconds or 10 pulses every 6s, the total after, let’s say 600 seconds, should be the same (1000). Why would it count more pulses?
The pulse counter counts a turn of the needle once the magnet is detected, and doesn’t count anything when detection ceases. Whether it’s updating more or less frequently shouldn’t affect the count, unless starting a period while the needle is “detected” counts and extra pulse. But I wouldn’t consider that to be a possibility. Or if the ESP32 restarts the sensor after every update, which sounds weird as well.
I started using pulse_meter as from this tutorial and it was drifting as well.
But if you have regular flow of 5pulses every 12seconds and your count interval is 6seconds how it goes? It doesn’t count “half pulses”.
So the count becomes 2-3-2-3… 50% difference between 2 intervals.
And if there is minimum fluctuation in the flow it could become 2-2-4-2
OK so let’s say in 60 seconds measuring every 6 seconds it could go in two manners:
2-3-2-3-2-3-2-3-2-3 for a regular flow.
0-0-10-0-5-5-0-5-0-0 for an irregular flow.
The total for both is the same (25) since it is counting the pulses. What it should be doing is “increase the total count by X” every 6 seconds.
Measuring the same flow in every 60 seconds would be simply:
25
The problem is that measuring every 60 seconds gives
measure: 25
total: 25
measuring every 6 seconds returns:
measure: 0-0-10-0-5-5-0-5-0-0
total: 27
I don’t understand how the fluctuation affects the wrong total.