Water Meter using binary_sensor input

Hey All, I’ve been trying for a while to work this out but going round in circles.

I would like to calculate water usage per hour, day, week, etc…

I have modified a zigbee window sensor by extending the reed switch on some wires so I can insert into the water meter. This is all connected and working well. When the tap goes on, the meter goes around and the zigbee window sensor cycles around “open” and “close” as expected. I can see these on the timeline by looking at the sensor.

image

I have then created a counter to calculate a value rather than boolean state. My expectation is that this will create a new sensor called “sensor.mains_meter_usage_pulse_count” and sum the total state changes:

- platform: statistics
  name: Mains Meter Usage Pulse Count
  entity_id: binary_sensor.mains_water_pulse_on_off

Then I have configured “utility_meter” settings as below:

utility_meter:
  hourly_mains_water:
    source: sensor.mains_meter_usage_pulse_count
    cycle: hourly

  daily_mains_water:
    source: sensor.mains_meter_usage_pulse_count
    cycle: daily

  monthly_mains_water:
    source: sensor.mains_meter_usage_pulse_count
    cycle: monthly

The result doesn’t seem correct. When I turn on the tap I can see the state changing but the counter doesn’t increase and I assume this is why the utility meters don’t read correctly:

image

Clearly I’m doing something wrong but I can’t see it. I wonder if someone can see it and guide me.

Thanks in advance :slight_smile:

1 Like

Hi Stewart,

You are doing something that I am keen to do. It looks like you are almost there. I haven’t gotten to the hardware state yet so I can’t really help.

Perhaps this is useful:

If you can share the hardware you used that would be great.

Thanks for the pointer, I’ve followed the approach in the post and it’s working.

I have used the same sensors (Zigbee Xiaomi/Aqara door sensor) using ZHA and Ikea range extenders where needed. I have three sensors: Mains Water, Recycled Water and Gas. I had to take the sensor apart, de-solder the reed switch and extended it on some wires. In the water meters there is a hole on the side to insert the reed switch into and on the gas meter it needed placing just under the counter on the meter. All seem to be collecting data.

Next steps are to calibrate the counters and values to match the flow rates from the meters, for now I’m using 1 rotation per unit (either Litres or M3 for gas.

I’ve also setup “utility_meters” for each to track period stats and added the Gas metering to Home Assistant Energy. It would be great to be able to add both Mains and Recycled water to HA Energy but for now they are separate stats.

Thanks for the pointer and I’ll update this post soon with configuration specifics and pictures.

Here’s the code I’m using. Note that for now I’ve set the device_class to “gas” for everything as there isn’t a “water” option yet.

Add the Zigbee device and rename both the Name and Entity to something sensible eg: binary_sensor.gas_meter_pulse_on_off

Define a counter using HA —> Configuration —> Helpers —> Add Helpers —> Counter
counter.gas_counter

Create an automation to increment the counter when a pulse is seen from the binary sensor. Note that I wanted it to trigger for both open and close events so left the trigger state blank. I’ll revisit this when trying to calibrate counters to match the gas consumed.

- id: '1639558938199'
  alias: Increment Gas Counter
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.gas_meter_pulse_on_off
  condition: []
  action:
  - service: counter.increment
    target:
      entity_id: counter.gas_counter
  mode: single

Create a sensor using template:

template:
  - sensor:
    - name: "gas_usage"
      unit_of_measurement: "m³"
      device_class: gas
      state_class: measurement
      state: >
        {{ states ('counter.gas_counter') }}
      attributes:
        last_reset: '1970-01-01T00:00:00+00:00'

Then I added utility_meters to track metrics overtime:

utility_meter:
  hourly_gas:
    source: sensor.gas_usage
    cycle: hourly

  daily_gas:
    source: sensor.gas_usage
    cycle: daily

  monthly_gas:
    source: sensor.gas_usage
    cycle: monthly

  quarterly_gas:
    source: sensor.gas_usage
    cycle: quarterly

  yearly_gas:
    source: sensor.gas_usage
    cycle: yearly

Added everything to a Lovelace card to monitor the results:

I done the same for all three sources: Mains Water, Recycled Water and Gas. I’ll update the post further then I calibrate the counters.

1 Like

Thanks for the update,

I was playing aorund with my water meter, a reed switch and my multimeter and wasnt avle to find the the spot to get a pulse - it looks like either my reed is not sensitve enough or the target is not storng enough to close the reed. Anyhow the meter has its own “cyble” sensor that sits on the spinning sensor that I can use - but apprantly there are none in Australia at the moment due to shiping limitatins etc. So probably a project for the new year.

Just looking at your coundter incremnet - my gess is that you will be using a “pulse” as a full cycle of the switch though (i.e. when it returns to either on or off). Based on my research of my water meter which is clibrated to have a single “pulse” for each 1L of water.

Hello, I’m trying to do a similr thing but the water sensor always shows “unknown”
image

template:
    sensor:
      - name: water_usage
        unit_of_measurement: "l"
        device_class: gas
        state_class: measurement
        state: >
          "{{ states ('counter.water_counter') }}"
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

The counter works
image