Help with water sensor and statistics

I have a water meter which puts out a pulse every 1 gallon. This goes into my pi as a binary sensor pin 9. What I would like to do is create a script which if no one is home and water meter is putting out pulses for a specific amount of time will do an action. Assume when no one is home there should not be any water running. If water running then there is a leak.

I have created

sensor:
  - platform: statistics
    entity_id: binary_sensor.Watermeter
    name: watermeter

which creates a dashboard entry which counts the pulses correctly.

Side note: It actually counts each gallon as two pulses. The rising edge of the water meter is counted then the falling edge is counted. Since the pulse width from the water meter is variable depending on the speed of the dial (aka water flow fast or slow). Wonder if there is a way to only count the rising edge?
sidenote

I assume in order to do my automation i will have to do several steps.

  1. create a binary sensor which goes “on” when the meter puts out 2 pulses within 2minutes. Counting the pulses from binary_sensor.Watermeter. Then after a period of time reset this counter, thus taking the new binary sensor back to “off” again, let’s say after 1hr.

  2. use that new binary sensor as a condition statement. Also have a condition statement which looks at group.all_devices for when the state is away.

  3. Then do my actions.

Problem is I have no idea how to do the first item. When I call statistics from the automation.yaml it fails. I assume this will need to be created in the configuration.yaml. Then somehow call it from the automation.yaml?

Thanks for any pointers or help. Most water meters here in the USA have a pulsed output which goes to a reader. This is how the water company can remote read some of the meters. Would have thought there would be example code to do this on the forums. I can’t find any, unfort.

Jason S.

@JasonStroll , did you find a solution for your water meter? I am about to log my water meter and som tipping bucket sensors and wonder if HA has some kind of support for this functionality.

hey @JasonStroll, could you please provide your full code to make the water sensor work?
Where do you declare the pin number?
Also is it possible to make some calculations before the final amount is displayed?
(my flow meter produces about 225 pulses per liter, so i would like the amount of pulses divided by a number)

Thanks in advance

Hi Krash, I have a water flow meter, did you manage to get this to display in HA? I’m hoping i can get daily/monhtly usage. I’ve got my sensor setup via MQTT and its only doing counts or seconds at the moment.

Hey there,
I’m afraid I don’t have any progress on this project.

I tried setting it up wit a nodemcu chip running ESPeasy but I didn’t manage to get the chip to read the sensor unfortunately so I gave up.

I have managed to set it up with HA while connected directly to the RPi. I don’t have the exact code at the moment but I can paste it to you when I get home.
I disconnected it though because it just kept adding pulses to a counter and I think it slowed down my HA by creating very big DB files.

Here is a post with my code and further discussion

How did you manage it through mqtt?
Could you share some specifics of your set up?
What exactly is it reporting?

I’m using a sonoff basic with flashed tasmota firmware, i’m getting the a reading via MQTT: pulses in seconds i.e 0.101 each time water flows through. The issue is getting it to display in HA with daily/monthly consumption. MQTT seems to keep the last reading and posts the last flow rate in seconds.

Hmm…
From what i understand, it reports every 10 seconds, the number of pulses that were made, right?
I’ll have a go on your approach, see if I can figure out a way to set it up with sonoff.
Thanx for the info.