Ah! Of course, I didn’t think of that.
When x = 0 then Q = (((0 / 60) + 8) / 6 = 8 / 6 = 1.333 and that should of course be 0 as well.
It now is in fact a linear function like this, with Q not reaching 0 when x is 0:
This type of sensor has a minimum useable flow rate.
One option to solve this issue is to add a step in the function that assures the flow rate to go to zero when the rate is below the minimum useable flow rate. Something like this:
While searching the Internet I find several different versions of this YF-B10 sensor with a flow rate range of 2 to 50 L/minute.
So when we assume the minimum useable flow rate to be Q = 2 L/min then the minimum useable pulse rate will be x = 240 pulses/min
So the pulse counter filter can be modified like this to assure the flow rate will go to zero when the pulse count is below 240 pulses/min:
- lambda: !lambda |-
if (x < 240) return (x / 120);
return (((x / 60) + 8) / 6);