Using ESPhome to build a water flow rate meter

hi all im triying to create a water flow sensor
Just to be sure… if the manual says 595 pulse x min
the flow meter works and send signals … but not accurated

If im not wrong.
595 pulses per liter of water from the manual

"filters:

lambda: return (x+4)/10/60;
lambda: return (x+4)/10/60;
x= 595
(595+4)/10 = 60 / 60 = 1 Lt…

option with multply

platform: pulse_counter
pin: x
unit_of_measurement: “l/min”
name: “Liter per minute”
filters:
multiply: 0.001680672269
total:
unit_of_measurement: “l”
name: “Total no of Liter”
filters:
multiply: 0.001680672269
option with Lambda
sensor:

platform: pulse_counter
state_class: measurement
name: “Sensor agua”
id: flujo_agua_test
pin:
number: GPIO15
mode: INPUT_PULLUP
update_interval: 1s
unit_of_measurement: “L/min”
icon: “mdi:water”
filters:
lambda: return (x+4)/10/60;
Its not very accurate in my case:(

Stream range: 2~50L|MIN$5%

Specification

Model: YF-B10

Interface size: G1

Rated voltage: DC3.5~24V

Inner/Outer Diameter: 24.38mm/32.9mm

Thread length: 13mm

Material: Stainless steel

Water pressure resistance: >1.75MPa

Output pulse high level: >DC4.7V (input voltage DC5V)

Output pulse duty cycle: 50%10%

Insulation resistance: >100M2

Stream range: 2~50L|MIN$5%

Airtightness: close each hole, add 1.7Mpa water pressure test for 1 minute without leakage and deformation Stream pulse characteristics: F=(10*Q-4)÷5%, F is the frequency Q is L/Min, that is, 595 pulses per liter of water

This config works almost perfect for me.
595 pulse and F=(10*Q-4)

sensor:

  • platform: pulse_counter
    state_class: measurement
    name: “Sensor agua”
    id: flujo_agua_test
    pin:
    number: GPIO15
    mode: INPUT_PULLUP
    update_interval: 1s
    unit_of_measurement: “L/min”
    icon: “mdi:water”
    filters:
    • lambda: return x/ 595;
      total:
      unit_of_measurement: “l”
      name: “Total no of Liter”
      filters:
      • lambda: return x/ 595;

Any answer? looks a good sensor due his 1L to 30l range

This looks like an AI bot response. Did you use ChatGPT or similar to reply here?

The format, specific kind of politeness, adjectives used and inclusion of generic advice are all typical of an AI bot.

Helllo @parautenbach, partly ChatGPT, but I really took time to read and answer Kiloptero’s question. I have a long active thread on this topic with ChatGPT 4 Plus. I’m not just pasting what it spits out, I take time to read and challenge every output and review it to make sure it might help. English is not my first language, so it helps to double check my answers are written with a good English syntax. And not everyone have a paid subscription to ChatGPT.

For anyone wondering why the post was deleted:

Where does this misinformation that a esp32 isn’t 5V tolerant come from and why are you even spreading it? :right_anger_bubble:

Thank you :handshake:

Which doesn’t contain the information about 5V tolerant GPIOs anymore in more recent revisions according to the CEO of Espressif :page_facing_up:

  • When asked why this information is not in the datasheet, he responded

“the reason is too many users took it to mean that the chip is 5 V tolerant. When we say 5 V tolerant, we are only referring to the IOs. So some users mistook this to make that they can power the chip entirely off the 5 V supply. The correct usage is to use 5 V open for these 5 V tolerant pins, and only via only drain configuration.”

I have setup as per your instructions, however the above sensor (binary_sensor.water_flow_on_off - as I have named it) is always off.
I think is to do with point 5 above.

@donparlor - How do you ensure that binary_sensor.water_flow_on_off is set up to detect water flow?

Many thanks.

Just a follow up on my original question - @donparlor will really appreciate your help.

This binary sensor is setup in configuration.yaml

As soon as your flow sensor is above 0 (this sensor is inside your ESPHome configuration and mine is named sensor.debit_d_eau_instantane), it will trigger the binary sensor as being ON.

@donparlor - thank you that worked great!!

The next issue (and the final one) is that I cant get any values for the Cost of last Shower sensor.

I have the previous sensors (Duration of last water usage and Volume of last water usage) working perfectly and showing the correct values:

image

and

image

However the Cost of last shower is always Unknown:

image

The sensor for that is in HA entities:

And the code for that is:

- platform: template
  sensors:
      cost_of_the_last_shower:
        friendly_name: "Cost of the Last Shower"
        unit_of_measurement: '$'
        value_template: >
          {{ (states('sensor.volume_last_water_utilization') | float * 0.90) | round(2) }} #change the multiplier (0.01) by your local cost of energy to heat up 1 litre of water to you tank set temperature

I have tried and checked and double check all but I cant get it to display any values at all.

Do you have any ideas?

Hello @MnM,

Your cost_of_the_last_shower sensor seems well structured, my only concern is where you put it inside your configuration.yaml file. This should be below your sensor: section.

sensor:
  - platform: template
    sensors:
        cost_of_the_last_shower:
          friendly_name: "Cost of the Last Shower"
          unit_of_measurement: '$'
          value_template: >
            {{ (states('sensor.volume_last_water_utilization') | float * 0.90) | round(2) }}

Beside that, the only difference would be the format display of your Last Water Usage Volume, number is displayed with a dot (.) while mine is with a coma (,), but I guess it’s just a regional setting and won’t affect the output of the value_template calculation.

Check at the location of your cost_of_the_last_shower sensor sensor and let me know if you respect the position below your sensor section.

Hi @donparlor - thank you for getting back to me.

I have all 3 sensors defined in a sensors.yaml file using sensor: !include sensors.yaml statement in configuration.yaml file

- platform: template
  sensors:
    duration_of_last_water_usage:
      friendly_name: "Duration of Last Water Usage"
      unit_of_measurement: "sec"
      value_template: >
        {% set t = states('sensor.duration_of_last_water_usage') | float if states('binary_sensor.water_flow_on_off') == 'off' else now().timestamp() - states.binary_sensor.water_flow_on_off.last_changed.timestamp() %}
        {{ t | round(2) }}

- platform: template
  sensors:
      volume_last_water_utilization:
        friendly_name: "Last Water Usage Volume"
        unit_of_measurement: 'L'
        value_template: >
          {{ (states('sensor.total_water_use_in_l') | float - states('input_number.starting_water_volume') | float) | round(2) }}

- platform: template
  sensors:
      cost_of_the_last_shower:
        friendly_name: "Cost of the Last Shower"
        unit_of_measurement: '$'
        value_template: >
          {{ (states('sensor.volume_last_water_utilization') | float * 0.90) | round(2) }} #change the multiplier (0.01) by your local cost of energy to heat up 1 litre of water to you tank set temperature

Just as an additional hardware suggestion if not already mentioned in these 300+ responses:
https://www.amazon.com/DAE-AS200U-75P-Couplings-Measuring-Gallons/dp/B01DAZOQO2?pd_rd_w=hEP26&content-id=amzn1.sym.5a5ce87a-6e3e-461e-8699-23c0adbf7599&pf_rd_p=5a5ce87a-6e3e-461e-8699-23c0adbf7599&pf_rd_r=DTA5W1R81NKX4ZGPS92E&pd_rd_wg=9YCLu&pd_rd_r=5271f89b-1508-4d10-9381-50e43b8108d8&pd_rd_i=B01DAZOQO2&ref_=pd_bap_d_grid_rp_0_20_t&th=1
Works great and the sensor is already miunted in the device itself

@alexxed

This config works for you?
Flow pulse characteristics (6.6*Q) Q=L/Min±3%
= filters:
- lambda: return (x / 396); # 396 = 6,6 * 60

I am not using this approach with sensors.yaml, I guess you did it correctly but I can’t confirm. My best guess is that it’s a syntax issue… It’s working in my system.

Not sure if it helps:

I tested my flow_meter ( YF-B10 G1 1") with water buckets and stopwatch and came up with the following formula:

- platform: pulse_counter
   id: my_flow_meter
   unit_of_measurement: 'L/min'
   pin: GPIO19
   name: 'Grundwasser liter/min'
   filters:
      - lambda: return x / 554.0;

Hi - Does anyone have a starting point for the YF-DN50 2" flow sensor or already use one please?

I managed to find a data sheet HERE

I had this from a user a few years ago but unsure on its accuracy;

    pin: GPIO32
    name: "Pump Flow"
    update_interval: 60s
    icon: "mdi:gauge"
    filters:
     - lambda: return (x / 12.5) * 0.264172;
    unit_of_measurement: "gpm"

most of these flow meters need to be installed vertically. this greatly helps with accuracy.

Hi,
I’m also using the YF-DN50 to measure the water flow in my pool filtration system.

In “your” data sheet, you read that Frequency (Hz) = 0.2 * Flow (l/min)
In other data sheets, you can find that 12 pulses = 1 liter. Those 2 formulas are contradictory.
Indeed:
12 pulses = 1 liter
12 pulses / second = 1 liter / second = 60 liter / minute
1 pulse / second = 5 liters / minutes
Frequency (Hz) = 5 * Flow (l/mn)

So, I disregarded the first formula and assumed the second is correct.

Here is the code I use:

sensor:
  - platform: pulse_counter # in pulse / mn
    pin: GPIO8
    name: "Water flow"
    filters:
    # 12 pulses / liter
    - multiply: 0.005 # 1/12 * 60 / 1000
    - round: 2
    unit_of_measurement: "m3/h"

I believe the filters - multiply is more efficient than the filters - lambda but both are working well.

BTW, I’m feeding the YF-DN50 only 3.3V, directly from the esp32. It looks like it is working as expected :slight_smile:

hi i have the same flowmeter as you are using but I don’t get it to show correct value in one minute I manage to fill 8L white the below flow
ccuracy
[18:57:14][D][pulse_counter:174]: ‘Vannforbruk’: Retrieved counter: 5113.02 pulses/min
[18:57:14][D][sensor:094]: ‘Vannforbruk’: Sending state 12.91167 L/min with 2 decimals of accuracy

i will be grateful if you can point me in the correct direction