Using ESPhome to build a water flow rate meter

@guyy, start reading from the top of this thread. I even shared my completed YAML, which is still running a year later.

1 Like

hi,
Thanks it look very nice but i think its too complicated for me.
do you familier with other easy method of doing it ?

So reading through this guide, I have a YF-S201 water sensor
https://www.hobbytronics.co.uk/yf-s201-water-flow-meter
From the datasheet I can see it is Pulses per Liter: 450

So my config

sensor:

  • platform: pulse_counter
    pin: GPIO5
    name: ā€œPulse Counterā€
    update_interval: 5s
    filters:
    • lambda: return (x / 450.0) * 60.0;
      unit_of_measurement: ā€œL/hrā€

and this returns

[18:54:16][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2304.00 pulses/min
[18:54:16][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 307.20001 L/hr with 2 decimals of accuracy
[18:54:21][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2352.00 pulses/min
[18:54:21][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 313.60001 L/hr with 2 decimals of accuracy
[18:54:26][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2328.00 pulses/min
[18:54:26][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 310.39999 L/hr with 2 decimals of accuracy
[18:54:31][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2268.00 pulses/min
[18:54:31][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 302.39999 L/hr with 2 decimals of accuracy
[18:54:32][I][ota:046]: Boot seems successful, resetting boot loop counter.
[18:54:36][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2172.00 pulses/min
[18:54:36][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 289.60001 L/hr with 2 decimals of accuracy
[18:54:41][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2196.00 pulses/min
[18:54:41][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 292.79999 L/hr with 2 decimals of accuracy
[18:54:46][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2196.00 pulses/min
[18:54:46][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 292.79999 L/hr with 2 decimals of accuracy
[18:54:51][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2292.00 pulses/min
[18:54:51][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 305.60001 L/hr with 2 decimals of accuracy
[18:54:56][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2328.00 pulses/min
[18:54:56][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 310.39999 L/hr with 2 decimals of accuracy
[18:55:01][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2340.00 pulses/min
[18:55:01][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 312.00000 L/hr with 2 decimals of accuracy
[18:55:06][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2340.00 pulses/min
[18:55:06][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 312.00000 L/hr with 2 decimals of accuracy
[18:55:11][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2292.00 pulses/min
[18:55:11][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 305.60001 L/hr with 2 decimals of accuracy
[18:55:16][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2316.00 pulses/min
[18:55:16][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 308.79999 L/hr with 2 decimals of accuracy
[18:55:21][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2328.00 pulses/min
[18:55:21][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 310.39999 L/hr with 2 decimals of accuracy
[18:55:26][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 2256.00 pulses/min
[18:55:26][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 300.79999 L/hr with 2 decimals of accuracy
[18:55:31][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 84.00 pulses/min
[18:55:31][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 11.20000 L/hr with 2 decimals of accuracy
[18:55:36][D][pulse_counter:159]: ā€˜Pulse Counterā€™: Retrieved counter: 0.00 pulses/min
[18:55:36][D][sensor:092]: ā€˜Pulse Counterā€™: Sending state 0.00000 L/hr with 2 decimals of accuracy

I currently have this sensor connected to a 160Psi pump

This say it pumpā€™s 8L/min, so I was hoping to see a figure around 8. is this right or have i messed this right up, this is my first EspHome project so please go easy.

Thank you in advance

1 Like

I had same bad thought about gas meter.
You see liter by hour at a T instant.
So 8l/min *60 = 480l/h max from pumps.

Draw a graph and add an utility meter in homeassistant like those:

Or directly in the esphome with something like this :

1 Like

@guyy I do not mean to cause you offense, but, this project is literally as easy as connecting a sensor to an ESP, and then copying and pasting code. If that is too complicated, perhaps you should investigate commercial solutions?

1 Like

@pmiles156 Everything looks great! Your pump pushes a maximum of 8L/min, which is 480L/hr. In operation, it looks like youā€™re actually getting around 305L/hr, so you can see that the manufacturer was a little bit optimistic - either that, or it is having to push water uphill, which always affects performance to some degree.

If you would rather see the speed per minute, just change your lambda like this:

    lambda: return x / 450.0;
    unit_of_measurement: ā€œL/minā€

Finally, if you want to see this data in a prettier way, just add a Gauge card to Lovelace, and select your flow meter sensor as the target entity. Set the min to 0 and the max to something like 500.

You will never see the flow rates declared for pumps. Once you add any pipework the flow rate reduces, even straight lengths due to friction losses. Bends, pipe material and diameter also have a dramatic effect on affecting flow rate, as does head pressure and what you are pumping into. There are tables on line for you to calculate this.

You need to calibrate what you are actually getting by filling vessels of known volume over time. Do not rely on pump ratings. That is only one factor.

You can read this and go from there, though a bucket and stopwatch is far simpler.

1 Like

Thank you for your replyā€™s I finally have this working, @ashscott thats exactly what I did, to work out that my system was generation 7 litres of water a min.

Also embarrassed to say but it might help others, the reason my reading was nowhere near 420 mark was the sensor was on the wrong way. eekā€¦

So I have my pump and sensor just setup in my kitchen sink just pumping water round with out any additional pipes. This will give me the MAX output of my system (7 litres an min) so when I do go to install it on my solar heater the readings should be right.

now to get utility meter working and get some stats.

Thank you for all your help

1 Like

hi, thanks
i am new to the esp.
can you direct me what should i buy , any easy guid you recomman.
Thanks.

All of that information is already in this thread.

You will need, at least:

  1. Wemos D1 Min or ESP32 or similar. You could even use an ESP32 based accessory like a smart socket if you were so inclined.
  2. USB cable for flashing and providing power to the device
  3. A water meter that delivers a pulse

Thatā€™s pretty much it.

The rest is just the ESPHome configuration and a front end to read/log the data in the format you want. Home Assistant would be a good choice.

Everything else is pretty much in this thread and thereā€™s plenty of help here if you get stuck.

1 Like

thanks, is that o.k :
wemos
https://m.banggood.com/Geekcreit-D1-Mini-V3_0_0-WIFI-Internet-Of-Things-Development-Board-Based-ESP8266-4MB-p-1264245.html?rmmds=search
usbcable - regular from android
water pulse:
https://m.banggood.com/YF-S201C-Black-Flow-Meter-Water-Flow-Sensor-Switch-Precision-Flowmeter-Turbine-Flowmeter-G12-DN15-p-1439149.html?rmmds=search
?

The D1 mini is correct. The flow meter looks ok, but you can never tell until you get it and play around.

thanks , do i need any other device to buy ?

I have a tip for anyone doing this.

Most of my flow meters are either YF-DN40 or YF-DN50. Where I live, these are crazy expensive. But I discovered something today.

They all work on the same principle - either a propeller with a magnet in one or more blades, or a propeller made of ferrous material. And however the internals look, they all use the same hall sensor, on the same board. If you pop open one of these devices, you will find a circular board with the code WT8-Y printed on it.

Why is that useful? Well, Iā€™ve had these deployed in the wild for a year now, and a few weeks ago I had my first failure, on a big DN50 which measures the rate water is coming from a dam about a kilometre down the mountain. Replacing the sensor would be a big job, so I tried everything else first - making sure the power supply was good, replacing the sensor cables, etc etc. Then I opened the sensor and saw that the gasket had failed and rain had penetrated inside and wet the board.

Which is also when I noticed that the board is standard. Before I deployed across the farm, I did experiments on my workbench with a small version of the sensor, and I remembered what it looked like inside. I scratched in a drawer and found the sensor, and it was a match. Swapping out the board and putting in a new gasket was childā€™s play.

So what Iā€™m saying is, if you deploy big like I did, and one of your flow rate sensors fails, buy the smallest, cheapest flow meter you can find and cannibalise the board. ESPHome does not care, and why should it? Itā€™s the exact same part, the only difference between the big and small sensors is the number of turns that equals a litre, and thatā€™s a setting you do in ESPHome anyway.

Anyway, thatā€™s all. Hope this tip saves you some money. Itā€™s a lot easier swapping a circuit board than replacing an inline water flow sensor.

9 Likes

Morning, guys

So Iā€™m trying to calculate my daily usage using utility meter in Home Assistant, would I need to create 2 sensors to display L/hr and L/min or is there a better way to get this working?

Water Flow Monitor

sensor:

  • platform: pulse_counter
    pin: GPIO5
    name: ā€œPulse Counterā€
    update_interval: 5s
    filters:
    • lambda: return (x / 450.0) * 60.0;
      unit_of_measurement: ā€œL/hrā€

Daily Water Flow Monitor

  • platform: pulse_counter
    pin: GPIO5
    name: ā€œDaily Water Counterā€
    update_interval: 1s
    filters:
    • lambda: return x / 450.0;
      unit_of_measurement: ā€œL/minā€

I canā€™t see why you couldnā€™t use both in one yaml. Have you tried to yet? Seems a pretty good way to get the data in different formats. I mean the only other thing I can think of is bringing Node-RED into it, which seems overkill for this.

Which utility meter are you using?

You could also use a Template sensor if the dual one gives you gyp.

1 Like

@pmiles156, I dug into this myself, and found that you do the config on the Home Assistant side. On the ESPHome side, you only need the sensor that returns in L/Hr.

Hereā€™s what you need to do.

First, edit your ESPHome node YAML so that you have just the sensor that returns L/Hr.

Then, go to HA and edit your config.yaml file. You must add a Riemann sum integral sensor, see here: https://www.home-assistant.io/integrations/integration/

Mine looks like this:

sensor:
  - platform: integration
    source: sensor.flow_rate_southgate
    name: RSI Southgate

Now, I should mention that the default time unit is per hour, thatā€™s why you could leave the ESPHome sensor returning per hour. If you have ESPHome returning something else, youā€™ll need to add the relevant unit_time argument here.

Next, you must add a Utility Meter in your config.yaml. Mine looks like this:

utility_meter:
  southgate_flow_hourly:
    source: sensor.rsi_southgate
    cycle: hourly
  southgate_flow_daily:
    source: sensor.rsi_southgate
    cycle: daily
  southgate_flow_weekly:
    source: sensor.rsi_southgate
    cycle: weekly
  southgate_flow_monthly:
    source: sensor.rsi_southgate
    cycle: monthly

So you see I have added hourly, daily, weekly, and monthly. This is likely overkill for you, and probably for me too, but I am super stoked to get it working. Note that I am using the RSI sensor we created in the previous step as the source, not the ESPHome sensor.

And that should be that.

6 Likes

This is excellent. Itā€™s been a puzzle to me for a while.

On the ESPHome side, are you using:

  - platform: gpio
    pin: 
      number: GPIO34
      mode: INPUT_PULLUP
    name: "Water meter sensor"
    id: water_meter_sensor

or:

  - platform: pulse_counter
    pin: GPIO34
    name: "Water meter"
    id: water_meter_pulse_counter
    accuracy_decimals: 0
    update_interval: 10s
    unit_of_measurement: 'litres'

as the input to HA sensor.flow_rate_southgate?

If the latter, what do you have your update_interval set at? Does it make a difference?

1 Like