Esphome configuration help

So i felt confidant enough to actually try my first esphome project.
i followed some instructions i found online and tried to make a “stupid” water flow sensor.
for starters i was willing to setle for a “binary sensor” to just let me know if the water were “running” or “not running”.
so i got this sensor of AliExpress, and combined it with an esp8266 board i had from another project. its a simple sensor with 3 wires and a “spin module” to sense the flow. the sensor gets its power from the 5V and G pins of the esp8266, and “data” wire is connected to pin 13.

i use esphome addon with home assistant, and added these lines to the “standard code”:

binary_sensor:
  - platform: gpio
    pin: 13
    name: "water flow"
    device_class: running
    filters:
      - delayed_off: 1s

the sensor shows up in home assistant, and when blowing air into the sensor i can see the state changing to “running”.
here are the problems:

  1. without the “- delayed_off: 1s” code, i can see the state changing rapidly (running/not running), several times, for as long as the inner sensor is spinning (while air is being blown).
    is that normal?
  2. sometimes the state stays in “running” state, though nothing is making the sensor spin (no air nor water is passing through the sensor).
    that can not be “normal”, as it misses the whole sensor idea…
    I don’t have enough experience to understand if its something to do with my configuration, execution, of maybe a bad sensor?
    i know this kind of sensor can give accurate water consumption (or spose to…) but for now, i like to better understand what did i do wrong, with the steps i took.
    any help and pointers will be appreciated.
    cheers

Well done for getting this far. You have a flow sensor; the sensor is designed to generate a single “on” (the circuit is made) moment during a rotation. The idea is that you then use a pulse meter sensor platform in ESPHome to allow you to count the number of rotations per second.

The final bit is to then write a little formula that calculates the amount of water flow from the rotations per second.

If you just want a binary on/off, then you could then write a template that is “off” when rotations are zero and “on” when rotations are >0.

I suspect you might find if you look up the sensor on these forums that you might need a pull-up resistor to ensure you do not get spurious “bouncing”. I hope I have your sensor correct!

1 Like

here is my complete config in Esphome, i have X1 3/4 flowmeter and X4 1/2 flowmeter.

Be carefull of the “Q” parameter that is given for 3/4 or 1/2 flowmeter, not the same…

to resume for you (because i have a display in my config and a temp sensor attached to the 3/4 flowmeter

sensor:
  - platform: pulse_counter
    pin:
      number: D6
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: main_water_flow_meter
    name: "Débit d'eau instantané général"
    update_interval: 5s
    filters:
      - lambda: return (x / 396); # 396 = 6,6 * 60
  - platform: integration
    name: "Index Eau compteur général en M3"
    id: index_eau_compteur_general_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return ( id(index_compteur_eau).state + (x / 1000));
  - platform: integration
    name: "Eau total au général en M3"
    id: eau_total_general_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total au général en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_general_litre

if you look at the pulse_sensor Q=6.6 for my sensor, so 6.6 x 60s = 396 and you will add the good pulse with x / 396, so look at the seller description to find the good “Q” number for your flowmeter.

Enjoy

2 Likes

thank you @JulianDH for the explanation. that make sense as a behavior for a “pulse meter”, and same goes for the pointers to the right info. i’ll probably use your template idea for the “on\off” state as further indication, while using @Olivier974 code to play around with the other info the sensor can provide.

If i understood correctly, @Olivier974 had made a perfect example, that works fine for my sensor “as is”.
im sure ill have to tweak if further than the “pin number”, to get accurate measurements.
for example, this line in the code does not validate for my config:

- lambda: return ( id(index_compteur_eau).state + (x / 1000));

if its not too much trouble, i would love some more elaborate explanation for @Olivier974 code.
what every sections does, and more explanation for the “Q” parameter your refer to.
what exactly am i looking for, and how do i implement it in the code.
thank you for your help
cheers

sorry you can deleted the “index_compteur_eau” its the number of my flowwater counter on the road, because i want to follow my total water consumption and when you start your flowsensor, you start from “0” and actually my index is 188. So i create a number sensor like this in EspHome :smirk:

number:
  - platform: template
    name: "Index compteur d'eau"
    id: index_compteur_eau
    optimistic: true
    unit_of_measurement: 'm³'
    min_value: 188.3
    max_value: 500
    step: 0.1

so you can select the real value that is display on your main water counter of your local water provider, mine is outside my house, near the road.

for Q, if you look at the documentation of your seller : there is nothing.

I dont know which one you buy? 1/2 3/4%? mine 1/2 Q is 11 and mine 3/4 Q is 6.6,

perhaps you have to ask the seller…

Thanks man

if i understood you correctly, you refer to the width (diameter) of the faucet\pipe, as the pulse counter for the difference between the 3/4" and 1/2" will change as well. further more, it is possible that different sensor are using different “counters”, so yours is not necessarily uses the same inner components as my 3/4 (guess i will start with your setup, and work my way through).
i think i will need to measure it myself. is that an option? if so, what would be the best way of doing it?
can i pour 1 litter on water and check the “overall” reading is correct, and change the values accordingly?
ill keep playing with it to further figure it out.

cheers

yes its exactly that! the pulse counter mesurement is x turn every minute.

my G3/4 as a Q value of 6.6, so try with this.

And manualy mesure 1L of water and look at your sensor value. But it will be more precise with 5 or 10 liters.

Or galons if you dont use metric system.

how you fix it?