I have a watermeter that uses a pulse-sensor to determine the flow-rate.
This which works just fine on itself but there are some drawbacks in the ESPhome implementation of the pulse-sensor.
The watermeter has a metal rotor that spins once for every 1 Ltr of water consumption.
The timeout
function on the pulse-sensor settings determines how long it should wait before it assumes 0
if no pulses are received in the set period.
This timeout defaults to 5 minutes.
(see: Pulse Meter Sensor — ESPHome) It can obviously be set to anything either above or below that, but both have their drawbacks.
What I am curious about is whether it is possible to make the timeout proportional to the measured value by means of a lamba.
i.e. if the waterflow is 30 L/min and the tap is turned of, the default timeout would add an additional 150 L to the total counter. Where it would be reasonable to expect a new sensor reading -at that flowrate- within 2 seconds (60/30). Therefore the 5 minutes, or 150 L, seems like an excessive amount of overhead.
Obviously reducing the time to something lower is certainly an option, but that still leaves the same issue of overhead flow recording.
If it would be possible to set the timeout dynamically, say; to expect the next value within x/60
seconds and if not received then reduce the output value as well as increase the timeout proportional to the new output value.
For example:
if the rate is 30 L/min, it expects a new value within 2 seconds.
So, f.e. after 4 seconds, reduce output by half, double the timeout value, then after 8 seconds, do that again etc.
So that the output value tends to 0
and the timeout tends to max (i.e. 5 minutes or so) If one would be able to set the gradient of the reduction of the output value that would allow a better and more accurate approximation of the actual value.
A fixed timeout, by its shear nature, also ignore low flow rates.
I.e. if I set the timeout to 120 seconds, then in the above example I still get 60 L of additional -and unrealistic- consumption. But anything less than 0.5 L/min will not be picked up at all as the pulses will be spread more than 120 seconds apart.