Detecting a slow water leak

I am using an ESPhome magnetic sensor on my water meter to measure water usage.

I also created this automation to detect if the water is running for 10min continuously:

alias: Safety / Water / Flow 10min Warning
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.watermeter_flow
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: 0
conditions: []
actions:
  - action: notify.notify
    metadata: {}
    data:
      message: Water flow has been detected for more than 10 minutes continuously.
      title: Potential Water Leak!
mode: single

That works well but not for small leaks. I currently have a small water leak (probably broken water inlet valve of my washer) and the washer fills slowly but continuously.

It seems that the ESP device in this case does not keep the flow rate constantly at a low rate but in bursts, like so:

How can I best detect a water leak based on this signal?

If I try to work with averages over a certain amount of time I will get the wrong results because an intended water flow would trigger as well.

Only these tiny jumps once in a while are “unintended”.

Garbage in = Garbage out. You need to fix your ESPHome sensor. Share the device config.

Some of the water meters use an algorithm something like “no 1 hour period with no flow over the last 24 hours” to indicate a possible leak.

That flow looks like it could be a toilet tank with a more modern valve. They don’t allow very low flow, but will flow when the level drops some amount (to make it more obvious).

Most water meters can’t detect very low flow rates at all, let alone accurately.

No, this is not a mistake in the ESPhome sensor. It’s a general question, how would I detect a leak (within home assistant) using a sensor like this?

Nevertheless, esphome yaml

esphome:
  name: watermeter
  friendly_name: watermeter

esp8266:
  board: d1_mini
  restore_from_flash: true

preferences:
  flash_write_interval: 60min

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxx"

ota:
  - platform: esphome
    password: "xxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.222.14
    gateway: 192.168.222.254
    subnet: 255.255.255.0

substitutions:
  volume_unit: 'gal'
  i2c_scl: GPIO5  # D1
  i2c_sda: GPIO4  # D2
  hide_magnetic_field_strength_sensors: 'false'
  hide_half_rotations_total_sensor: 'false'

packages:
  meter:
    url: https://github.com/tronikos/esphome-magnetometer-water-gas-meter
    ref: main
    file: esphome-water-meter.yaml
    refresh: 0s

How could I implement an automation like that?

I believe it’s really the washer because if I shut off the water, flow remains at zero for long time.
It’s just that the flow is so slow that it’s detected in bursts.

I think these water meters are actually pretty accurate and can detect low rates. Keep in mind they have the “leak detector”, a small wheel that spins on a leak, included.
I tested this once with a faucet that was just slowly dripping. Put my cellphone on the meter. With the naked eye, couldn’t see any movement but waching the video at 10x speed one could see the wheel spinning.
And, this wheel is just connected to the nutating disc which is measured using the sensor above. So, I would say, in principle it’s accurate enough to detect leaks as slow as slow dripping

It’s simply question how you read the pulses.
If water meter for example outputs one pulse per liter and you have a flow of 3l/h, it means you get one pulse every 20min.
If you update the value once an hour, you get 1 reading of 3l/h.
If you update the value once a minute, you get 57 readings of 0 and three readings of 60l/h.

Not to forget interferences, usually some filtering is needed.

other option is to use a pressure sensor like this one
https://es.aliexpress.com/item/1005005510454084.html

the problem is only you can track changes on the pressure when you are not using water

that if you don’t close the main valve you just read the water pressure that distributor supplies at that moment…

The magnetometer sensor you are using reads the strength of the field around your meter. As water flows through your water meter, your sensor will output a sine wave signal as the magnet ges closer and then further away from your sensor. One period of the sine wave will be one displacement of the water meter’s volume.

The ESPHome code you are using simplifies the sine wave down to counting “half-periods”. So it will increment a counter when the sine wave is at its max reading, and then increment it again when the sine wave is at is minimum reading. If the water meter is rotating slowly and the sine wave is (for example) slowly decreasing away from its maximum reading and heading towards the minimum reading, your sensor is reporting no information to HA.

A few options to consider:

  • Make your own ESPHome code to switch measurement methods to a different method. This will be very complex but will be the most accurate way to get the answer you want.
  • Create a new sensor in HA that averages out the pulses. Then you can trigger an automation if that average value is above zero but below some larger value for an extended period of time.
  • Create an automation or a binary trigger-based sensor that will turn on if you get so many .06 gal/min pulses (without any larger pulse).
1 Like

Good considerations. I was lazy to dig what type of sensor is used here.
I think in certain cases it could be more practical to have two logical sensors, one to count pulses for regular flow and another to analyze the pulse (I don’t know the code OP is using and what is implemented there).

@mekaneck is right, there are no pulses, it’s a nutating disk (as I explained in my first answer to my post). I also explained that I fully understand why this happens: When there is a slow leak, the threshold will just cause discrete “spikes”.

Thank you for clarifying!

Yes, my question is more a home assistant question … I am not a pro and hence my question how to achieve this in HA.

  • Create a new sensor in HA that averages out the pulses. Then you can trigger an automation if that average value is above zero but below some larger value for an extended period of time.

This was exactly part of my original question. How would this work in HA?

  • Create an automation or a binary trigger-based sensor that will turn on if you get so many .06 gal/min pulses (without any larger pulse).

Similar here, how would I build such an automation in HA?
For example, how do I trigger exactly on such pulses? How do I count them? And how do I “filter” out larger pulses/consumptions? (Note: larger consumers are not pulses, they would indeed result in a continuous “flow”)

For the average, you can use a statistics helper. The various characteristics you can choose from are defined here, you probably want average_step with a max_age set to the time period you want to look at, and also use hold_last_sample.

For a notification automation, you could use a numeric_state trigger, and set both above and below to the values you want. You can also set the for option to a time period you want the value to be within for.

The trigger-based binary template sensor option could be fairly complicated. You first need to decide what the threshold is between a leak and no usage, or between a leak a normal usage. How little time between pulses is “normal” and how much time between pulses is “no leak”? Could then keep track of the pulses in an attribute, reset the count when normal or no-leak conditions are detected, and finically set the state to ON when the number of pulses reaches a certain count. You could also do this in an automation with several input helpers to keep track of everything.

Finally, another option would be to skip the flow rate signal entirely and instead focus on the meter reading (you should have a sensor that is always increasing, probably in units of gallons). If this value creeps up slowly over time, you know you have a leak. You could use a derivative helper, or a statistics helper with a state characteristic of change, and a window (or max_age) of however long you want to consider.