Using ESPhome to build a water flow rate meter

Hi, read the entire thread. I want to give it a go but need some startup push. Having a D1 mini, where do I start from there to get that up and running with what yaml? How do I get yaml onto that? And how do I hook it to homeassistant? Connecting a flow meter to gpio5 seems the most easy part :-). And powering D1 with usb or 5v is the other easy part :-).

Thanks in advance!

Thanks, but thats the same as sending me the link of this forumā€¦?

Read the getting started pages.

Not quiteā€¦ Esphome is incredibly well documented and thus easy to use. Follow that link, install the tool and check how to set up a pulse counter.

So, I run hass on esxi with 3 exisitng is use usb passthroughā€™s. If I wanted to use the plugin I would have to add an new passthrough to the D1 miniā€¦ would have to connect, stop hass, passthrough usb, start, etcā€¦ and every new D1 would mean the sameā€¦ Is that the only way or is there other options to connect to an esp8266?

They usually all use /dev/ttyUSB0, so only one passthrough would be used wouldnā€™t it?

Or use esphome on another computer?

I think I can only passthrough connected devices in esxi. Not ā€œ/dev/ttyUSB0ā€ onlyā€¦

When you say ā€œanother computerā€ can it be windows?

Hi @sender. I run hass on a RPI4, and I run esphome as a plugin inside it. I use esphome for the initial compile, and then I select the option to download the compiled binary file.

I flash that binary file onto whatever ESP device Iā€™m working with on a Windows machine, using an FTDI interface and the FlashESP8266.exe file that came with EspEasy (an alternative ESP firmware), because thatā€™s the method that works for me.

Itā€™s only ever necessary to do this once. After that, any updates or changes you make can be sent to the device via OTA update from within ESPhome.

Hope that helps.

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