Water and Gas in Practice: Pulses, m³, Leak Alarms, and Safe Measurement

Module 17 · Lesson 9

Water and Gas in Practice: Pulses, m³, Leak Alarms, and Safe Measurement

The module's title promises electricity, water, and gas. So far, water and gas have mostly shown up as categories on the Energy Dashboard. This lesson gets practical: how to read a water meter and a gas meter, how to convert pulses, how to detect continuous flow, and what you absolutely must not touch on a gas line.

Plan on about 75 to 90 minutes. By the end of this lesson you'll have a map of data sources for water and gas, working examples for an ESPHome pulse meter, a utility_meter, a continuous-flow alarm, and a fallback plan for when a sensor fails. The closing mini project is in Lesson 10.

Safety rule
A gas line, and any work on a utility-owned water meter, is not a DIY workshop project. Don't open, unsolder, or modify a gas meter. If you're unsure, call a licensed professional or your utility. Home Assistant measures and warns; it doesn't replace certified metering or a service call.

Why water and gas are different from electricity

With electricity, it's easy to get W and kWh straight from an outlet. With water and gas, what you usually have is volume: gallons, liters, or cubic meters. Cost and billing don't come from one simple number the way they do with electricity, especially with gas, where the bill accounts for heating value, not just volume.

Water: usually gallons, liters, or m³; pulses from a reed switch or an optical read; a continuous-flow alarm is one of the most useful automations you can build

Gas: usually m³ or cubic feet; pulses only if the meter has a documented pulse output; absolutely no touching the seal or the housing

Electricity: W and kWh; easier to measure locally; costs are easier to model, though they still don't replace your bill

Data sources: from a manual reading to a fully automatic one

Start with what you already have. Sometimes a few weeks of manually logging your water and gas meter readings in a helper or a spreadsheet is enough. Only after that should you invest in a pulse sensor, ESPHome, or an off-the-shelf sensor. Same rule as with electricity: question first, then measurement, then automation.

1. Manual reading: you log the meter's reading once a day or once a week; good enough for a trend

2. Reed switch: a magnet on the water meter's dial generates pulses; common on many residential water meters

3. Pulse output meter: a built-in pulse output on the device; you need to know the liters-per-pulse or m³-per-pulse factor

4. Optical reading: a camera or optical sensor reads the digits or dial; convenient, but sensitive to lighting and mounting

5. Manufacturer integration: some smart water meters or hubs expose an API, often cloud-based; check for reporting delays

Unavailable does not mean zero flow
If your water or gas sensor is unavailable, or hasn't updated in hours, that doesn't mean nothing is flowing. It might mean the sensor, the ESP board, or the network has failed. Automations must never treat missing data as a safe zero.

The water meter: pulses, liters, and the conversion factor

Before you wire up anything, find the pulse factor on the meter itself or in its documentation. Often it's 1 pulse = 1 liter, or 1 pulse = 10 liters. Without that number, your template sensor will lie to you with attractive-looking charts.

The conversion is simple: liters = pulse count × liters-per-pulse. Cubic meters = liters ÷ 1000. For the Energy Dashboard you'll generally want m³, with device_class: water and state_class: total_increasing.

# Illustrative ESPHome example: check your own pin and pulse factor
sensor:
  - platform: pulse_meter
    pin: GPIO5
    name: "Water Meter Pulses"
    unit_of_measurement: "L/min"
    id: water_pulse
    total:
      name: "Water Meter Total Liters"
      unit_of_measurement: "L"
      device_class: water
      state_class: total_increasing
    filters:
      - multiply: 1.0   # liters per pulse: REPLACE THIS

ESPHome Pulse Meter
pulse_meter measures frequency and can also track a running total. The multiply value has to match your water meter's actual pulse factor. After the ESP restarts, check whether the total comes back from restore state, and whether it's tracking correctly against the mechanical dial.

Template: liters to m³, with an availability guard

template:
  - sensor:
      - name: "Total Water Usage"
        unique_id: water_meter_total
        unit_of_measurement: "m³"
        device_class: water
        state_class: total_increasing
        availability: >
          {{ states('sensor.water_meter_total_liters') not in ['unknown', 'unavailable', 'none'] }}
        state: >
          {{ (states('sensor.water_meter_total_liters') | float / 1000) | round(3) }}

A utility_meter for water and gas

Just like with electricity, utility_meter gives you daily and monthly usage. The source should be a rising m³ total, or a well-configured periodic source. Don't build a monthly analysis on top of a sensor that resets erratically or disappears for hours at a time.

utility_meter:
  water_usage_daily:
    source: sensor.water_meter_total
    cycle: daily
  water_usage_monthly:
    source: sensor.water_meter_total
    cycle: monthly
  gas_usage_daily:
    source: sensor.gas_meter_total
    cycle: daily
  gas_usage_monthly:
    source: sensor.gas_meter_total
    cycle: monthly

A continuous-flow water alarm

This is one of the most genuinely useful automations in the whole house: catching a small, continuous flow at a time nobody should be using water. It could be a leak, a running toilet, or a tap left open. Before you send a dramatic notification, spend a week just observing: watering the garden and taking a bath will also generate flow.

template:
  - binary_sensor:
      - name: "Water Continuous Flow"
        unique_id: water_continuous_flow
        device_class: problem
        availability: >
          {{ states('sensor.water_meter_flow_lpm') not in ['unknown', 'unavailable', 'none'] }}
        state: >
          {{ states('sensor.water_meter_flow_lpm') | float > 0.3 }}
        delay_on: "00:30:00"
        delay_off: "00:05:00"

automation:
  - alias: "Water: suspected continuous flow"
    mode: single
    triggers:
      - trigger: state
        entity_id: binary_sensor.water_continuous_flow
        to: "on"
    conditions:
      - condition: state
        entity_id: input_boolean.auto_water_leak_alarm
        state: "on"
    actions:
      - action: notify.mobile_app_your_phone
        data:
          title: "Water"
          message: "Continuous flow detected for over 30 minutes. Check a tap, the toilet, or for a leak."

False alarms
Filling a bathtub, a sprinkler system, washing the car, and weekend guests are all classic sources of false alarms. That's why delay_on is set long, and why the input_boolean lets you disable the alarm while you're away or watering the garden. Start with a week of notifications before you escalate to anything more aggressive.

The gas meter: what you may and may not do

Gas isn't the same as electricity from an outlet. You don't open the housing, you don't remove seals, you don't drill into it, and you don't tape a magnet onto a meter you don't fully understand "just to try it." If your gas meter has a manufacturer-documented pulse output and the installation is done by a licensed professional, you can collect pulses much like you would with water. Otherwise, stick with a manual reading and your bill.

No unauthorized interference
Tampering with a gas meter on your own can be dangerous and can violate your utility agreement or local regulations. Home Assistant is often perfectly well served by a monthly reading entered by hand, or an official pulse add-on installed according to its documentation. Safety matters more than a good-looking chart.

m³ of gas is not the same as billed energy

With gas, volume in m³ doesn't convert to cost as directly as kWh does with electricity. Your utility bills you for energy, often in therms or kWh, factoring in heating value, temperature, pressure, and various correction factors. An m³ sensor in Home Assistant is great for tracking usage trends, but it doesn't replace the line item on your bill.

Volume: what you typically measure locally: a rising m³ total

Billed energy: what you actually pay for; depends on correction factors and your supply agreement

The model in HA: you can assume an approximate cost per m³, for orientation only, with a clear note that it's a model

template:
  - sensor:
      - name: "Estimated Daily Gas Cost"
        unique_id: gas_cost_daily_estimate
        unit_of_measurement: "USD"
        availability: >
          {{ states('sensor.gas_usage_daily') not in ['unknown', 'unavailable', 'none']
             and states('input_number.gas_price_per_m3') not in ['unknown', 'unavailable', 'none'] }}
        state: >
          {{ (states('sensor.gas_usage_daily') | float
              * states('input_number.gas_price_per_m3') | float) | round(2) }}

The Energy Dashboard, and a water/gas view of your own

On the Energy Dashboard, add water and gas sources exactly as in Lesson 2: the correct device class, the correct unit, total_increasing, and an availability guard instead of float(0). On your own dashboard, keep a dedicated section: flow right now, usage today, usage this month, the continuous-flow alarm, and the time of the last update.

type: entities
title: Water and gas
entities:
  - sensor.water_meter_flow_lpm
  - sensor.water_usage_daily
  - sensor.water_usage_monthly
  - binary_sensor.water_continuous_flow
  - sensor.gas_usage_daily
  - sensor.gas_usage_monthly
  - input_boolean.auto_water_leak_alarm

Data freshness
Add a sensor or a card showing last_changed / last_updated. A local sensor that's been frozen for an hour isn't better than a cloud sensor just because it's local. For a leak alarm, freshness of the data is critical.

A fallback plan when a sensor fails

When an ESP board drops off, or a pulse meter goes quiet, don't let an automation run on "zero liters." Disable the flow-based alarm, send a notification that data is missing, and fall back to a manual reading until it's fixed. It's the same rule you practiced with electricity: unavailable is not a measurement.

automation:
  - alias: "Water: no data from the sensor"
    mode: single
    triggers:
      - trigger: state
        entity_id: sensor.water_meter_flow_lpm
        to: "unavailable"
        for:
          minutes: 15
    actions:
      - action: input_boolean.turn_off
        target:
          entity_id: input_boolean.auto_water_leak_alarm
      - action: notify.mobile_app_your_phone
        data:
          title: "Water sensor"
          message: "No data for over 15 minutes. The continuous-flow alarm has been disabled."

Hands-on checks

To do

☐ Read your water and gas meters by hand and log the current values.

☐ Find the pulse factor, or make a deliberate decision to stick with manual readings.

☐ If you have a safe pulse-based water setup: configure the m³ total with an availability guard.

☐ Add a daily and monthly utility_meter.

☐ Turn on the continuous-flow alarm as a notification first.

☐ Check for false alarms: the toilet, watering the garden, taking a bath.

☐ With gas: zero interference with the meter; only a legitimate, documented data source.

☐ Write down your fallback plan: what happens when the sensor goes unavailable.

Common mistakes

A wrong pulse factor: the charts look great, but usage is reported 10× too high or too low

Treating unavailable as zero: a sensor failure looks like savings, or like the absence of a leak

An alarm with no observation period: watering the garden triggers a panic every evening at 6

Tampering with the gas meter: a safety risk, and possible trouble with your utility

Gas cost from raw m³ alone: comparing an HA model against a billed energy figure with no correction factors applied

No last_updated on the dashboard: you have no way of telling whether the data is fresh

Key takeaways

Water and gas start as volume, not cost: liters or m³ don't convert to dollars as directly as W and kWh do.

Start manual, automate later: a few weeks of hand-logged readings can answer the question before you buy any hardware.

The pulse factor has to be exact: get it wrong and every downstream number, chart, and utility_meter is wrong too.

A continuous-flow alarm needs a week of observation: baths, sprinklers, and guests all look like a leak at first.

The gas meter itself is off-limits: measure only through a documented, professionally installed output, or stick to your bill.

Unavailable still isn't zero: a missing reading needs a fallback plan, not a silent assumption that nothing is flowing.

What to bring to Lesson 10

For the closing energy mini project, add water and gas to what you've already built: one water data source, whether automated or manually logged, a decision on whether the continuous-flow alarm stays on, and a clear statement of whether you're measuring gas locally or working only from your bill. You don't need full automation. You need an honest picture of the data.

This closes the gap the module's title promised
Electricity, water, gas, and solar: this lesson is where water and gas finally get the same practical treatment electricity got in the earlier lessons. As your own installation grows, come back and swap in your own entity names, factors, and thresholds.

Finished this lesson?