Using ESPhome to build a water flow rate meter

hello everybody,

I bought the YF-B1 sensor

I’ve been struggling to figure out how to calculate the Liters/min and Liters/hour.
According to the datasheet F=11*Q

What are the two columns with numbers ???
Does it mean 2 liters > 22 pulses, 2.1 liters > 23.1 pulses ???

So far I have the following code for liters/hour but am not quiet sure if it’s right.

  - platform: pulse_counter
    pin:
      number: 4
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/hour'
    id: water_usage
    name: "Instant water flow"
    update_interval: 5s
    filters:
      - lambda: return (x / 660);   # 660 = 11 * 60 min  

Is this correct ?

Anyone please ??
I need to finish the project and have the wife happy …

I think that’s what the datasheet is saying.

Hi!!
I have bought for my installation a sensor similar to yours but the exact model is the following YF-B10 and I can’t understand what would be the necessary adjustment to calibrate this sensor, that is, the lambda that I have put, could you help me?

I’ll post the specs here.

(6 * Q-8) Q= L/Min ±5%

What would be the setting for my sensor. Thank you, I hope it arrives so I can configure it.

Maybe you could try the following:

sensor:
  - platform: pulse_counter
    pin:
      number: 4
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: water_usage
    name: "Instant flow rate"
    update_interval: 5s
    filters:
      - lambda: return 6 * (x / 396) - 8;

Let me know if it returns correct values.

2 Likes

Ok, Thank you.

I am waiting for it to arrive, I have the board ready and with the configuration ready to load. And when it arrives I will try to imitate your config, I found it very interesting.

Greetings!

1 Like

I have been looking at the whole post, I am waiting for a sensor with similar characteristics to the one used by you (@NoGrout , @donparlor ) and it is very long and difficult to understand, there is the possibility of sharing the complete code, that is, everything that refers to this automation, sensors, automations, input_numbers, binaries etc… thanks!

Hello valsergi, despite many attempts and the help of Donparlor, I have not managed to get consistent data. I’ve been using the energy_water module since a recent update, unfortunately the data isn’t consistent either. I had many other occupations in the meantime, and I left this function aside. I remain very interested in this subject.

1 Like

Hi @NoGrout, I just wanted to say that it is possible you have a bad sensor. Do you have a second one you could test with?

I mention it only because I have had to replace them in the past.

I installed a YF-B10 into my primary heating loop and connected it to ESPHome.

Works brilliantly, giving me the flow rate of the water around my central heating loop. The only downside is that it’s incredibly noisy and the house travels through the water, so we can hear it everywhere!!!

I’m going to have to remove it as it’s driving us all mad :slight_smile:

1 Like

And could you tell me what formula you used to correctly manage the liters / min so that when mine arrives, adjust it. User @donparlor provided me with the following information, is it correct? is it the same as yours?

filters:
- lambda: return 6 * (x / 396) - 8;

Hello! thank you for this idea. it is indeed a possibility, unfortunately I do not have a valve in advance

Nop. Wrong values!!!

Thank´s

  • lambda: return (x / 396);
1 Like

This is the worst Home Assistant Community thread I have encountered over quite some time…

I don’t own one and can’t help with a definitive answer, but if I were you I would try to feed a known amount of water through the sensor. You can try a test setup with some pipes, a container and duct tape. Next, just count the total amount of pulses you get and compare that to the data sheet. Hopefully you will be able to make sense of it this way.

For pulse counting, you might find a configuration similar to this useful: esphome-projects/heizungsregelung_energy_heat.yaml at a60d405d0b8d1bdb1633e93fe9e6549a68f4be97 · ThomDietrich/esphome-projects · GitHub

How so, specifically?

3 Likes

Hello, I just bought this sensor: “YF-B10”:
https://es.aliexpress.com/item/1005004653846502.html

According to the formula provided by the buyer:
F = (8 * Q-4) ± 5%, f is the frequency q is l/min, that is, 476 pulses per liter of water

This would be:
l/min
filters:
- lambda: return (x / 476) ;

l/hour
filters:
- lambda: return (x / 476) x 60;

Hello, I have YF-B10 with Flow pulse characteristics: (6*Q-8) Q=L/Min±5%.
Could you help me with lambda?
Somewhere I find

  • lambda: return (x / 396); # (6*Q-8) Q=L/Min±5%
    or
  • lambda: return (x / 373); # (6*Q-8) Q=L/Min±5%

Regards,

people just need to understand that an “esp32” or “esp8266” isnt the board they are using. They are using a development board that has an esp32/8266 on it. Which development board they’re using, thats the key to finding the correct pinout. There are all sorts of varieties of develpment boards and versions. Some have more or fewer pins and which pins on the development board go to the internal esp chip, they aren’t all the same. D1 on one development board may go to GPIO4 on one but on another board it may go to GPIO5. That website only references a couple of common boards and its worthless if your using an Adafruit board, AZ-Delivery board, and many more that arent the same. Look at YOUR board and then look up a pinout for that specefic board.

1 Like

Hi everyone,
Thanks so much for this amazing thread, so useful!

I’ve setup a water meter with a sensor ref FS300A G3/4. It works well and looked accurate but yesterday I compared it to our main water meter from the water company and the sensor was quite different (4.765 cubic meters at the meter vs 5874.0 liters at the sensor). The official water meter is quite old and I’m not sure it’s working very well.

Where did I get this wrong?

The documentation (e.g. here) is generally that Pulse frequency (Hz) / 5.5 = flow rate in L/min. Although in a some places it’s 5.0 (e.g. here) instead of 5.5, or even 6.

To throw another spanner in the mix, if I measure 1 liter from the tap with the same sensor (also a FS300a but a different one on a different pipe) then I get 384 pulses for a liter quite consistently. (over six tries it varied from 376 to 387 but usually right on 384).

Here’s my code on the sensor via ESPHome:

sensor:
  - platform: pulse_counter
    name: "Pulses"
    id: pulse_irrigation
    pin: 19
    update_interval : 5s
  
  - platform: pulse_counter
    name: "Flow rate"
    id: water_pulse_irrigation
    pin: 19
    update_interval : 5s
    accuracy_decimals: 2
    unit_of_measurement: "Liters/hour"
    filters:
    - lambda: return x / 330 * 60;  #330 is 5.5*60 and then times 60 to get per hour https://www.hotmcu.com/g34-water-flow-sensor-p-311.html
    total:
      name: "Water volume"
      unit_of_measurement: "L"
      filters:
        - lambda: return x / 330;

In terms of hardware, I plugged the sensor to a 5v supply directly, the ground of esp32 and pin 19 of the esp32. I didn’t use a resistor.

Thanks for the advice!
John

1 Like