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