Using ESPhome to build a water flow rate meter

Hi, this makes very good sense. I will do that too. Thank you!!!

I do a compile using esphome addon and and then I upload using usb by connecting the esp8266 to the RPi4 on one of the USB ports. After the first upload, uploading later can be done by OTA as you suggest @DeeBeeKay

Uploading via usb via a virtual machine on esxi is a “challenge”…

Been following this project and finally today ordered this
https://www.electronicscomp.com/sensors-module/sensors/water-flow-rain-drop-sensor/0.75-inch-brass-water-flow-sensor-sen-hz43wb
will use this sensor in the inlet line to detect that water supply has started as an added protection to my pump running dry. I have this pump connected to a smart switch based on esphome as an automation to start when level indicated by level sensors is true and the time is 5 AM or 17 PM. water timings change so I will add the flow sensor in the logic too.

1 Like

HI, I am in the phase of trying…

I have the D1 mini uploaded with the compiled firmware. I can see it got an IP adress and it is an “integration”:


But I do not see the device “online”…

my home assistant is on a segment 192.168.4.0/24 and the esphome is on 192.168.6.0.24 and they can reach each other (hence it got discovered - and other device like tasmota work fine this way).

What is wrong?

Edit: this is hte logging of the esphome via usb:
[21:02:51][C][wifi:415]: WiFi:
[21:02:51][C][wifi:283]: SSID: ‘IOTDOM’
[21:02:51][C][wifi:284]: IP Address: 192.168.6.6
[21:02:51][C][wifi:286]: BSSID: 70:4C:A5:72:C9:23
[21:02:51][C][wifi:287]: Hostname: ‘watermeter’
[21:02:51][C][wifi:291]: Signal strength: -56 dB ▂▄▆█
[21:02:51][C][wifi:295]: Channel: 11
[21:02:51][C][wifi:296]: Subnet: 255.255.255.0
[21:02:51][C][wifi:297]: Gateway: 192.168.6.1
[21:02:51][C][wifi:298]: DNS1: 90.145.32.32
[21:02:51][C][wifi:299]: DNS2: 90.145.32.33
[21:02:51][C][logger:175]: Logger:
[21:02:51][C][logger:176]: Level: DEBUG
[21:02:51][C][logger:177]: Log Baud Rate: 115200
[21:02:51][C][logger:178]: Hardware UART: UART0
[21:02:51][C][captive_portal:169]: Captive Portal:
[21:02:51][C][ota:029]: Over-The-Air Updates:
[21:02:51][C][ota:030]: Address: watermeter.local:8266
[21:02:51][W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 7 restarts
[21:02:51][C][api:095]: API Server:
[21:02:51][C][api:096]: Address: watermeter.local:6053
[21:04:43][I][ota:046]: Boot seems successful, resetting boot loop counter.
[21:04:58][D][api:067]: Disconnecting aioesphomeapi (192.168.1.142)
[21:04:59][D][api.connection:583]: Client ‘Home Assistant 0.114.0 (192.168.1.142)’ connected successfully!

EDIT:
got it working! Had to tweak pihole, my DNS servers, etc… I think using DNS is not very handy and just another weak link in this chain… but I have now “some” sensor in my hass:

Thanks till so far!

EDIT:

one more thing…

why is is keeping to say “offline”?

EDIT: used this and solved:

{
  "status_use_ping": true
}

Hi, I have this YF-B6 flowmeter:

F=6.68Q ± 5% (Q=L/min)

I am having a hard time to get this into the formula like:

filters:
      - lambda: return (x+8)*10; #Flow pulse: F=(6*Q-8)±3% with Q=L/min
    unit_of_measurement: "L/hr" 

Could someone help me out what to put there?

My simple logic says, 1 L/min: F * 60 thus 6.68*60=400…

would that mean I need:

filters:
      - lambda: return (x/400)*60; #Flow pulse: F=(6.68*Q)±5% with Q=L/min
    unit_of_measurement: "L/hr"

I created and will monitor… but would really like some professional feedback :slight_smile:

sensor:
  - platform: pulse_counter
    name: "Water Flow Hoofdkraan hr"
    id: flow_hoofdkraan_hr
    pin: D7
    update_interval: 5s
    filters:
    - lambda: return (x / 400.0) * 60.0; #Flow pulse: F=(6.68Q)±5% with Q=L/min
    unit_of_measurement: "L/hr"
  - platform: pulse_counter
    name: "Water Flow Hoofdkraan min"
    id: flow_hoofdkraan_min
    pin: D7
    update_interval: 5s
    filters:
    - lambda: return (x / 400.0); #Flow pulse: F=(6.68Q)±5% with Q=L/min
    unit_of_measurement: "L/min"
1 Like

hi, any pro feedback:-)?

2ndly… how can i make a total usage counter in Liters?

Howzit, greeting from Limpopo, I see you’re also South African.

I wish I could give you more explicit help, but the problem is the sensor I am using has exact data in the spec sheet saying that 27 rotations = 1L. That makes it super easy to do, because if you know this, then you just divide the incoming number of rotations by 27 and tadaaaaa you have litres. Which is what you’ll see if you scroll up and look at my yaml.

You, however, have a weird sensor that has a formula I don’t understand. What you want is to know how many revs = 1L. All I can suggest is mega googling on that sensor to see if someone has worked that out. Failing that, you are going to have to do the hardcore practical way.

This is the hardcore practical way. Configure your sensor with a very short update_interval. Then, pour a litre of water through it, and time how long it takes, while also keeping an eye on the data output. You want to know a) how long a litre takes to move through, and b) what the average pulses per minute were.

With those two pieces of information, you can calculate how many revolutions the sensor takes to pass 1L of water. I recommend you do it several times and average your results. And for better resolution, do it again with 2L, and with 5L. You’re not going to be perfectly accurate, but you’ll get within error bars of the truth.

EDIT: I forgot your second question. To do total litres you will need to configure a sensor in HomeAssistant, which I describe in this post: Using ESPhome to build a water flow rate meter

1 Like

A quick glace at the specs for that sensor shows that it gives you 6.68 pulses per litre, or explained the other way around, one pulse should be equal to 0.1497L.

@DeeBeeKay the formula is not weird, it just has the accuracy value tacked on the end in the spec listing.

Hi @sparkydave, thanks for that. Would you mind linking to the spec sheet? I haven’t had much luck googling it.

Click the link from Sender and it’s in the table below the item listing

I didn’t read all this tread. However one thing you have to have in mind.: This type of meter does need a minimal flow to start to measure. It means we have to have some fluid energy to make it running. If you look at the manufacture documentation, they states for a specific model: Flow rate: 5~200L/min. It means any flow below 5 L/min the meter will not “see”. The formule they gave you is valid only on 5-200L/min.

Question: does this solution also measure water pressure?
I’m asking because I see on the Amazon product listing below for the plastic Uxcell version of the YF-S201C the 5th bullet point says ‘Maximum water pressure: 1.75MPa…’

amazon listing

No it does not measure pressure

Great, thanks for quick reply @sender!

Hi, DeeBeeKay! What is the state of your project? I read the thread a month ago, but now it is a bit hard to keep track on the changes. Would you mind pointing me to the solution? If you found it, of course. So please let me know.

There is another project on github, if you are curious. I discuss it here: https://community.home-assistant.io/t/using-esphome-to-build-a-water-flow-rate-meter-j-pipe-github-version/239818

1 Like

hello, is it possible to display the meter in m³?
(I use TCRT5000)
Thanks

Hi @KameDomotics, if you can think of a formula that converts L/hr into cubic meters per hour, you can edit the lambda to display that data instead. Sadly I can’t, but I am not a clever man.

Litres, divide by 1000 = cubic metres.

The beauty of metric units.

Would anyone on this thread be willing to test our home water leak detection algorithm with your setup if you have this installed in your home?