Water flow reseting to zero in lambda - help

easy way out to reboot I guess! haha

most of the code at the moment will reset am to zero but we get the calculator effect.

gpio - no idea, cut a paste from an apparent working code to reset a pulse counter.

All that switch was doing was ‘pulsing’ the counter once as it toggled, as though a single unit of flow had just happened. Use a template switch instead.

Can you clarify what is “the calculator effect”?

am just changing the template to switch rather than a gpio.

calculator effect. the pump turns on then off, this generators a “litres delivered” (450 pluses per litre). this value when using the “+=” just keeps adding to itself. so if 1 litres passes through the sensor (litres delivered) the" water amount" adds 1 each count, it just keep adding up 1+1+1 etc. this is with the pump completely off, seems it stuck in a loop and it keeps adding 1 to itself. the reset toggle will just reset it to zero, but it adds 0+1+1+1 etc. (1 being what even the pulse sensor has calculated based on x/450)

So, are you saying that ‘am’ gets incremented even when there is zero flow?
i.e. at the display, the flow rate says 0.00 but ‘water amount’ keeps rising on its own?

yes, but is water amount on the Lovelace., zero flow and it goes up on its own.

I’m creating a prototype of this here, and testing the code directly on it.
I’ll post the result which you should use in place of everything you currently have.
Don’t try to make multiple changes at once, just replace the whole block.

thanks very much, I have gone back to my first code I posted at the moment,

thanks again much appreieated

Here’s a complete block of code that works for me.
As the flow is non-zero, the total water delivered increases.
When flow goes to zero, the total water delivered stops increasing.
pressing the reset switch (online, not an actual button at this point) will clear the total water delivered counter.
Do not mix this code with what you are already using, but see if this gets you to a point where the numbers change the way they’re supposed to (don’t worry if we got the actual units wrong, we’re just trying to see if they change in the ways intended).

  - id: am
    type: float
    restore_value: no

  - platform: pulse_counter
    name: "Flow rate"
    pin: GPIO5
    update_interval: 2s
    unit_of_measurement: "L/hr"  
    - lambda: |-
            id(am) += x / 450.0 / 30;
            return  x / 450.0 * 60.0;

  - platform: template
    id: fish
    name: "Water amount" 
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    update_interval: 5s
    lambda: |-
      return id(am);

  - platform: template
    name: reset_water_delivered
      - lambda:  |-
            id(am) = 0;

I’ve made a change to the above code, so if you’ve copied it for use, copy it all again. Sorry.
What I did was remove the publish action from the pulse-counter, and made the “water amount” sensor publish itself.

just trying to give it a go now, every time I touch an esphome entity it goes unavailable, will do a reboot… fingers crossed


a million thank yous.

with the water pump on “flow rate” increases and “water amount” shows a value. the reset toggle now zeros “water amount” and subsequence cycling of the pump counts from zero when reset! prefect!

thanks again!!! tomorrow I will look at the calibration, and run some tests. the sensors runs a 450 pulses per litre, but I know you have worked this into the code.

I will report back, and once again thanks very much for your help.

Thanks again for all your help. much appreciated, going to make my life much easier now I have it working.

It all runs well after numerous test and have included an input number so I can stop the pump at a specific amount of litres.

1 Like