Build a cheap water and gas usage sensor using ESPhome, a proximity sensor and a TCRT5000 Infrared Reflective Sensor and integrate it into Home Assistant
In this project I share a walkthrough on how you can build a water and gas usage meter using ESPHome that integrates with your Home Assistant.
I live in Belgium and the water meter I have is a Sensus 520 which has a small spinning wheel with a metal plate.
The solution to read it was by using either a reflective sensor or a proximity sensor.
The implemenation I went for was a proximity sensor LJ18A3-8-Z/BX-5V
1 spin of the wheel will result in a pulse, every pulse being equal to what has been defined by your meter.
Note: make sure to position the sensor a bit on the side of the wheel, so it only covers half the wheel. This ensures it measures the pulses. If you cover it completely, it will always detect the wheel and won't register any pulses. You can easily test it when you let some water flow and see the sensor light blinking.
The gas meter I use has a reflective mirror on one of the fractional numbers of the meter.
In my case it is located on the last number around the number 6.
1 spin of the last rotary dial will result in 0.01 m³ of gas consumption.
The reading of this spin is done with a TCRT5000 Infrared Reflective Sensor
To mount it on the gas meter display I had a housing 3D printed: https://www.thingiverse.com/thing:3923960
For the readability of the meter I have aligned is as you can see on the picture below, making sure the infrared and the phototransistor are well aligned with the rotary dial containing the small mirror.
To finetune the TCRT5000 you adjust the potentiometer until the 2nd led light goes out. It will light up when the mirror passes by on the rotary dial. (of course best to have some gas consumption ongoing while adjusting ;-))
As ESP32 board I used an AZDelivery ESP32 Dev Kit C V4 board
- The TCRT5000 runs on 3V
- The proximity sensor runs on 5V
graph LR
A[Proximity Sensor] -- brown wire --> B(5V pin)
A -- blue wire --> C(GND pin)
A -- black wire --> D(GPIO13 pin)
graph LR
A[TCRT5000 Sensor] -- VCC --> B(3V pin)
A -- GND --> C(GND pin)
A -- D0 --> D(GPIO36 pin)
The code I have added will make your sensors available for integration into Home Assistant
- energy-meter.yaml : the main sensor configuration
- common/base.yaml : time configuration
- common/base_global.yaml : some other global esphome code I use for all my devices
- In your configuration.yaml file, add the following:
utility_meter:
water:
source: sensor.water_used
util_water_usage_quarter_hourly:
source: sensor.water_used
cycle: quarter-hourly
util_water_usage_hourly:
source: sensor.water_used
cycle: hourly
util_water_usage_daily:
source: sensor.water_used
cycle: daily
util_water_usage_monthly:
source: sensor.water_used
cycle: monthly
util_water_usage_yearly:
source: sensor.water_used
cycle: yearly
gas:
source: sensor.gas_used
util_gas_usage_quarter_hourly:
source: sensor.gas_used
cycle: quarter-hourly
util_gas_usage_hourly:
source: sensor.gas_used
cycle: hourly
util_gas_usage_daily:
source: sensor.gas_used
cycle: daily
util_gas_usage_monthly:
source: sensor.gas_used
cycle: monthly
util_gas_usage_yearly:
source: sensor.gas_used
cycle: yearly
- Reboot Home Assistant
- Go to your Settings > Dashboards > Energy
- Add your gas and water sensor to the dashbaord
- Give Home Assistant a couple of hours and it will show you the data in the Energy Dashboard
As we have added the gas and water meter in the Utility Meters, we can also set their display values.
This can be done by calling the calibrate service:
This will show the meter values in HA as they are on your physical meters!
type: vertical-stack
cards:
- square: false
columns: 2
type: grid
cards:
- type: entity
entity: sensor.gas
- type: entity
entity: sensor.water
- type: energy-date-selection
- type: energy-gas-graph
title: Gas
- type: energy-water-graph
title: Water