Water Consumption dashboard. Incorrect counted results

I’m not very experienced but may have found a bug? I created a water flow sensor for our house, and can actually get accurate readings from this. I can even see accurate readings in Home assistant history, AND the correct volumes.

However, the energy dashboard doesnt seem to be accumulating the data correctly?

You can see my sensor history, for the most part it updates on the minute, UNLESS there is a blip (I noticed 2x 1 minutes were combined). But apart from that i can see the exact amounts of water per minute. However, in the Main shower block, HA water consumption didn’t add this up per minute. Where the flow rate was pretty much flat line stable, between 6:08-6:18am it almost took the first reading or the average of those 8 slots, and combined this with the rest of the minute blocks.

So the net result was over this 1 hour time frame, 20.31Litres was reported rather than the actual of 52.69Litres.

I dont suppose anyone has any suggestions?

The main ESPhome code part is this.

sensor:
  - platform: pulse_counter
    name: flowsensor
    device_class: water
    state_class: total_increasing
    id: water_pulse #Added to show up as water
    update_interval : 60s
    pin: 
      number: GPIO2
      mode: INPUT_PULLUP
    unit_of_measurement: "L" # was l/min
    icon: "mdi:water"
    filters: 
      - lambda: return (x+1)/9.85/60;
      - filter_out: 0.00169

I did wonder if at times it depends when the code is installed for the time pattern. For example if it starts at 06:08:30 then the 60s pattern is 06:09:30 etc. Where as i’ve been trying to use Co-pilot chat to get this to update on the exact minute ie 06:09:00 but thus far i have not managed to get a suitable outcome.

@petro I think you have replied to a few of my Energy threads and others, so i wondered if you had any insight as you seem extremely knowledgeable on these areas.

Your use-case rather looks like a pulse meter to me? :thinking:

Also don’t you want to use the total function directly in espHome for maximum accuracy?

Also better don’t limit the update interval from an pulse counter/meter but rather use a filter with throttle if you don’t like realtime updates in HA!

It is actually still measured per time frame, like X-pulses per Y-time. So you get a waterflow like 5L per minute or 10 liters per minute for example. To get totals you need to integrate over time, easiest as written before just use the total function of the pulse meter/counter :bulb:

Sorry not sure I follow all your points @orange-assistant ?

Your use-case rather looks like a pulse meter to me?

Yes it’s a Hall effect water turbine. I’ve checked the actual use, vs my code so far and can get it very accurate reported as you can see in the history?

Can you elaborate on the total function for maximum accuracy please?

“Also better don’t limit the update interval from an pulse counter/meter but rather use a filter with throttle if you don’t like realtime updates in HA!”

Also can you explain this? If it’s changed from 60s (i’ve tried this at other times and the formula needs changing to reflect the update time.)

It is actually still measured per time frame, like X-pulses per Y-time. So you get a waterflow like 5L per minute or 10 liters per minute for example. To get totals you need to integrate over time, easiest as written before just use the total function of the pulse meter/counter :bulb:

So the Litre part, was so that the sensor imports in to HA correctly. I initially tried l/min but i had strange results so changed the formatting. It was just a left over note of a change i made.

Sorry this is my first go with ESP Home for making something. Very new to this.

Instead of only sending the a snapshot of your waterflow every 60 seconds from the esp to HA and “try” to sum it up (which obviously only leads to wrong results you are getting) you just send the totals to HA so the esp will even continue totalizing/counting if HA isn’t available (reboot for to install an update for got example). The moment HA comes back online it will then reicive the next correct total.

You actually force (wrong) readings (waterflow, something like liters per minute for example) to be “accepted” as a total (liters).

Just think (or read) about the difference of power and energy - same same but different! :arrows_clockwise:

All good, every one needs to start somewhere. The docs linked actually also tells you about the total and other things quite easy to follow. Also the forum is full of good information you find with the search function. And last but not least many are here to help so if you get stuck just post again - or if you solved it also post (your yaml!) and feel free to mark the thread as resolved :white_check_mark:

I did wonder about this, and just let the ESP send it all in real time i think? Then make a Helper like utility meter, to log the pulses and convert i think i started to look at but i was getting results that were miles out. :frowning:

This is the default with the pulse components!

This is the bad way (integral/riemann sum)! Just use total: on your pulse meter/counter like the espHome docs show, otherwise you will run into troubles like explained before. :point_up_2:

In a nutshell: The ESPHome node counts pulses and sums up, both the (“Instantiounius”) waterflow and total gets reported to HA. :droplet: :bucket:

You might then use the utility meter in HA on the total sensor from that espHome node to derivate daily/weekly/monthly usage/consumption :bar_chart:

I still can’t get my head around this all :frowning:

I did try a few other things last night, the update time rate and such to 30s to see if it would solve the flat line sections for miss counts. I also tried adding a bit of jitter.

But what is baffling me is that my actual History data is accurate. The litres reported and tracked are spot on for use. It’s just Home assistant not taking this data and recording it right in the Water Consumption part it feels…

All the guides i saw were to use a pulse counter and not the pulse meter.

What’s even more confusing is their linked Guide (I used another) Contradicts the sensors…

Build a cheap water usage sensor using ESPhome and a proximity sensor - PieterBrinkman.com

I started to try this but using this code posted, It wouldn’t even go close to installing, it just gave errors…

Wont let both be together. Just tried a code copy and paste in for their version.

Going back to my updated code, the ESP log reports this (Which just happens to be because I just filled a 1 litre jug on a sink very slight slope and done quickly so it’s likely the 14ml over accounts for that :slight_smile: :- SO my code is calibrated Very accurately.