Using ESPhome to build a water flow rate meter

Hi, may I ask. What are the specs of that blue thing on your watermeter? Where did you buy it?

Thanks!

Other than it being 5V and 1 pulse per litre I have no specs. I bought it a few years ago from eBay. It no longer seems to be available.

The seller was diamondbfgltd.

Ive been following this project on and off for some time now.

Has anyone come up with a non invasive way to do the same ? Using an ultrasonic sensor ?

The ā€œbestā€ option so far seems to be using the TUF-2000M, but even that starts becoming cost prohibitive.

1 Like

I stumbled upon this thread and didnā€™t find a definitive answer for using this flow meter:

Model :YF-B5/B6
Rated voltage DC:5V
Water pressure resistance >1.75MPa
Operating voltage range DC5-15V
insulation resistance >100MĪ©
Accuracy [in 1~25LMIN]Ā±3%
Flow pulse characteristics (6.6*Q) Q=L/MinĀ±3%
Output pulse high level > DC 4.7V (input voltage DC 5V)
Output pulse duty cycle 50% Ā± 10%

sensor:
  - platform: pulse_counter
    pin: GPIO2
    unit_of_measurement: 'L/min'
    id: water_usage
    name: 'Current water usage'
    update_interval: 5s
    filters:
      - lambda: return (x / 396); # 396 = 6,6 * 60
  - platform: integration
    name: "Total Water Usage"
    unit_of_measurement: 'L'
    sensor: water_usage
    time_unit: min
  - platform: integration
    name: "Total Water MC"
    unit_of_measurement: 'mc'
    sensor: water_usage
    time_unit: min
    filters:
      - lambda: return (x / 1000);

In home assistant:

So far it looks like itā€™s displaying correct values, will leave it on for a longer period of time as I care about measuring cubic meters which I can cross reference with the analog clock.

5 Likes

Hi Folks,

For the first thanks all for posting a lot off useful information around.
But missing unfortunately some measurement around magnetic hall.
Therefore i have some question, might be dump but we will see :slight_smile:

My water operator installed at my house water meter with measurement addition which is not used by them.
Based on the technical documentation, there are 5 cables which are free to use (different use cases, flow direction, pulse measurment, reverse pulse measurment, fraud, etc )

White - generating pulses
Brown - GND

Theoretically simple as that, this pulse add-on is giving 1 pulse per liter or 1 pulse per 10 liters, depends of the installation on this water meter (https://www.maddalena.it/en/products/communication-modules/quadraplus-trp/75)

I flash my esp8266 connected this magnetic pulse sensor to my GPIO and GND and has nothing in the measurement.

In general i`m confused how it should be connected from the electronic point of view.

When i used simple magnetic contracton with other esphome function it was reporting open/close door with connection to GND and GPIO, but here with this pulse_counter platform was not able to count anything using contracton or pulse meter.

therefore based on many posts here, of this sensor flow meter which using 3 cables i started to think, that i have to power up somehow GPIO to count it.
Therefore decided to connect 3.3 V to Pulse Output, GPIO to Common on Pulse Meter and GND of ESP8266 through 10k resistor to GND of ESP8266

ESP8266 | QUADRAPLUS TRP
GPIO12 -> Brown TRP
GND -> R10k to GPIO12
3.3V -> White TRP

But after that started to reset my esp8266 at every pulse received.
I changed then the connection and put this resistor between 3.3V(ESP8266) and GPIO12(ESP8266)

And started to receive some pulses but those looks like misscalculated.

Therefore any idea how to connect this properly ?

1 Like

Iā€™ve briefly checked the link and the data sheet but they arenā€™t mentioning this, I think: Normally the pulse output will close for a moment (so itā€™s open otherwise, meaning infinite resistance). Itā€™s also probably a dry contact (i.e. not directly connected to any other circuit). That means, set up your pulse counter with an internal pull-up resistor (the ESP8266 has one on pin 12). This will allow the the pin to be at 3.3v when open and 0v when closed and not floating.

Hi Pieter,

So yes when I was rotating simple magnet around this add-on I was able to receive signal open close.
As I said I used this GPIO12 pin which is mentioned as pulse_counter on esp, but nothing appeared.
As I said connected GND to Brown and GPIO12 to white which is described as pulse output.

Therefore Iā€™m little bit confused how to properly connect this.
Especially that Iā€™ve seen some of project which was used some pullup resistor some of them not.

Was trying to achieve similarly using 100k and 10k resistor connecting through 3.3V and nothing.

Normal short/close output working fine for different method on esphome.

Hello everyone, I intend to read my water meter as well, but the pulse generator gives me 360L / H on the nodemcu. Actually it should be 60 liters / h ā€¦ The meter measures with 1 pulse per liter. I test it with a 1L jar where I also have 60 seconds to test it. My esp config yaml ā€¦

sensor:
  - platform: pulse_counter
    name: "Flow rate"
    pin: GPIO2
    update_interval: 60s
    filters:
    - lambda: return (x / 1.0) * 60.0;
    unit_of_measurement: "L/hr"`

have you made sure the sensor flow is the right way?

In case anyone cares, the 10k resistor is meant to hold the input signal level high. When the magnet gets next to the sensor that input gets pulled low by the hall sensor, When the magnet goes away the resistor to 5v pulls the input high again. Since the D1 max input voltage spec is 3.6v, applying 5 volts for an extended time is likely to wear out your input if not kill it outright. Ideally the pullup resistor should be tied to a 3.3v supply. I would be interested in how long the device survives with 5v pullup. Please report if it dies.

2 Likes


So this should be the suggested wiring diagramā€¦isnā€™t it?

Thank you for that post !

which water flow sensor are you using ?
how to calculate the resistor and capacitor depending on VCC ? (ESP32 with ESPhome)
if VCC is 5V can I use the same PSU for Sensor & ESP32 ? (no idea of power consumption of YF-S401 Water Flow Sensor)

Thanks for all the input on this thread. I am trying to implement an automation that when a flow meter detects a massive flow (high gallons/min rate) from the livestock water line it will automatically close a valve since we are on a well. The livestock (cows, water buffalo, & pigs) can be tough on the infrastructure and there have been a few times a ruptured line can quickly drain our 5,000 gallon (18,9000 Liter) holding tank. It takes about 2 days to refill the water tank so every drop counts.

I am now getting my mind wrapped around on how to do the first part of measuring the flow. I currently am using a M5Stack ATOM Lite and a this DAE MJ-100a Flow meter for our livestock water line and have it showing in HA:

image

ESPHome and HA along with everything everyone has been sharing is making this much easier than expected. Now off to work on the second part and learn about relays to control the valve. Iā€™ll also be adding a water pressure sensor to monitor our water tank levels.

1 Like

Hi @kimocal , great to hear that itā€™s working for you. You donā€™t mention what valve youā€™re using, but I assume that itā€™s something that can be activated by a relay. The only thing to watch for is how much current it uses to move the valve - for water flow, it can sometimes be higher than you think, which means a 10A relay such as you commonly find in Sonoff devices, or standard hobby relays, might not be enough.

Youā€™ll have to check the spec sheet for the electronic valve youā€™re using. If it needs more than 10A, you can still use a relay to control a Contactor with sufficient amps. Contactors are like big relays, you can get them at an electric supply store, and they can be controlled with a small amount of current.

In any case, setting up a relay in ESPHome is very simple - see below.

switch:
  - platform: gpio
    name: "Valve Control" # or whatever you want to call it
    pin: GPIO12 # change for the actual GPIO you are using
    id: relay # optional, but useful if you're going to call this from a physical button

And thatā€™s it. ESPHome will do the rest, and itā€™ll show up as a switch entity in Home Assistant.

Thanks for the info.

I had originally bought a Shelly 2.5 and this 3 Wire AC/DC ball valve. After getting the Shelly and playing around I realize I hadnā€™t read the Shelly 2.5 DC wiring close enough. The Shelly outputs negative, and I need positive for that valve. So now I ordered some relay boards and will be using a 2nd M5Stack ATOM Lite. This way I can add the pressure sensor to monitor my water tank level and also add another flow meter to monitor all the ag water lines. The first Atom Lite is further away and will only be used for the flow meter on the livestock water line. The Shelly will be used for a future project or I just may return it.

EDIT

Valve wiring discussion here.

1 Like

Iā€™ve now needed another water meter and came across this. It has a dry contact reed switch that closes for each litre of water, making it nice and simple to implement and no scaling or calibration required.

Ebay water meter

1 Like

Used with a waterproof ultrasonic sensor
iā€™m using the dfrobot model:

  - platform: ultrasonic
    trigger_pin: GPIO 01
    echo_pin: GPIO 03
    name: "Ultrasonic Sensor"  
    pulse_time: 10us
    update_interval: 1s

    
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: 'ultrasonic water distance'
    id: dist2water
    unit_of_measurement: 'm'
    accuracy_decimals: 3
    update_interval: 2s
    pulse_time: 10us
    timeout: 2.0m
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this      
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: "Ultrasonic Sensor Level"
    unit_of_measurement: '%'
    accuracy_decimals: 3
    update_interval: 5s
    pulse_time: 10us
    timeout: 2.0m
    icon: mdi:water-percent
    filters:
      - lambda: return ((((x*100)-27)-(60-27))/(60-27))*-100;
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: "Ultrasonic Sensor Volume"
    unit_of_measurement: 'l'
    icon: mdi:cup-water
    accuracy_decimals: 2
    update_interval: 2s
    pulse_time: 10us
    timeout: 2.0m
    filters:
      - lambda: return ((((x*100)-27)-(60-27))/(60-27))*-70;
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements

youā€™re welcome
/LeFab

3 Likes

hi there. can you please help me with the total water usage? how can i achieve that? thank you.

See post above by DeeBeeKay

I finally got the rest of the parts to install it and am hoping to get it done this weekend. Then I can start tracking the water the livestock is using. Working on actionable notifications now for when it detects a high flow rate.

1 Like

Hi Fabien,

iā€™m very curious about your solution , you have been able to mesure water flow with only 1 JSN-SR04T ?

how do fix the sensor to your pipes?

thanks for sharing your code :slight_smile:

1 Like