Water Consumption - How I achieved it

I thought I would share my experience with setting up my second ever ESPHome integration.

The reason I’m sharing this is because despite the fact this has been done numerous times before, there were several hurdles that made this quite a challenge for me. Many solutions I saw didn’t quite achieve my objectives.

I have an Itron water meter. They are common. It has a spinning wheel with a metallic disc that can be used to detect when one litre of water is used:

Like many others, I decided on a cheap TCRT5000 line tracer module to detect the spinning wheel. Cheap and simple.

I found getting the positioning right and spending some time making sure the pulses are being detected is worth the time. I just loaded this config on my ESP8266 to experiment. Using GPIO2 means it would also flash the LED on my ESP8266 too.

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO2
      inverted: true
      mode:
        input: true
        pullup: true
    filters:
      - delayed_on: 10ms

When positioned correctly and adjusted, the module will fire and the logs show the pulse being detected when the water is running.

Now on to recording water consumption… My objectives for recording were:

  • Accuracy - I wanted confidence in my numbers. To me, an increasing number matching my water meter was ideal.
  • Persistence - My ESP8266 device and Home Assistant instance will restart all the time as I play with other things. I didn’t want any of that to affect my data wherever possible. Additionally, I didn’t want to rely on anything stored on the ESP8266 either.

I spent ages messing around with different sensors and settings, but when relying on the sensors created by the ESPHome devices, they would always reset to zero whenever there was any kind of reset. I appear to be mistaken that simply having a sensor with state_class: total_increasing in ESPHome config would mean that Home Assistant would simply add to the previously stored figure. I was hoping I could force the correct meter reading once and it would simply add on to the end of that. But that doesn’t work.

So after a lot of trial and error, here’s what my config looks like for my ESP8266 device:

sensor:
  - platform: pulse_meter
    name: "Water Flow Meter"
    id: "water_flow_meter"
    pin:
      number: GPIO2
      inverted: true
      mode:
        input: true
        pullup: true
    internal_filter_mode: PULSE
    unit_of_measurement: "L"
    icon: "mdi:pump"
    internal_filter: 100ms
    timeout: 1min
    total:
      name: "Water Consumption"
      id: "water_consumption"
      unit_of_measurement: "L"
      state_class: "total_increasing"
      icon: "mdi:water"

The Pulse Meter measures the rate of flow, and the sensor created in “total” will always be zero at boot but increase per litre of water used.

For persistance, I use utility_meter in Home Assistant configuration.yaml:

utility_meter:
  water_consumption_daily:
    source: sensor.water_consumption
    cycle: daily
  water_consumption_monthly:
    source: sensor.water_consumption
    cycle: monthly
  water_consumption_lifetime:
    source: sensor.water_consumption
    cycle: monthly

This gives daily/monthly totals, but it also gives a lifetime figure that will keep increasing. I just needed to set the initial value after I restarted Home Assistant. I did this using developer-tools/service:

service: utility_meter.calibrate
data:
  value: '743174'
target:
  entity_id: sensor.water_consumption_lifetime

Now I just compare the value of sensor.water_consumption_lifetime against my physical water meter to verify accuracy.

This is how I did it. It’s now working great. Given the effort it took just to get this, I figured I would share my experience. I’m always keen to learn better ways to do things, so happy to hear improvements :slight_smile:

6 Likes

Bedankt voor je bijdrage. Ben vertrouwd met ESPHome en DIY projectjes.
Daar ik dezelfde meter heb, heb ik een TCRT5000 module besteld nu Home Assistant sinds kort ook waterverbruik in het Energy dashboard heeft opgenomen.
Wordt vervolgd…

Thanks, I was just playing around with TCRT5000 yesterday but quickly realised it was actually a lot easier than I thought, so I decided to finish the whole integration with HA there and then, and your config ultimately allowed me to do just that in minutes rather than having to spend hours using the trial and error method (which I would normally do, except this was at my parents house I was visiting and time was limited :smiley: ).

This is my modified ESPHome config based on yours. The main addition is to add the device_class so that the sensor can be used as a water consumption sensor in the energy dashboard.

The rest is just cosmetic.

# ESPHome with TCRT5000 in liter-per-rotation dial on water meter
sensor:
  - platform: pulse_meter
    name: "Cold water - current water flow"
    pin:
      number: D7 # pin to which the D0 output of TCRT5000 is connected
      inverted: true 
      mode:
        input: true
        pullup: true
    internal_filter_mode: PULSE
    unit_of_measurement: "l/min."
    accuracy_decimals: 0
    icon: "mdi:gauge"
    internal_filter: 100ms
    timeout: 1min
    total:
      name: "Cold water - liters used"
      unit_of_measurement: "L"
      state_class: "total_increasing"
      device_class: WATER
      icon: "mdi:water-pump"