Reading the house water meter with ESPHome and Home Assistant
I wanted to write this post, I have been looking for a good solution for a long time., stable and reliable… and as, ESPHome has the answer. In this post we will see how to read the water consumption of an ordinary water meter, come on, the one we have at home; and view it with Home Assistant.
I've been curious about this topic for years., know the consumption, in this case from the house water, the consumption and use we make of water in our homes. It came using solutions with a photo camera and with OCR text recognition, but… was not a valid solution, it had its weak points and failed more than a sideshow shotgun. After a few months of use I can assure you that the most reliable way is with an inductive proximity sensor and an ESP8266 or ESP32.
For what? Well for whatever reason you have, to know consumption, try to save, detect leaks, because it can…
![]() |
![]() |
Well, total, which in the end turns out that we have a very simple way to read the reading of a meter, we can do it through a proximity sensor, specifically with the model LJ18A3-8Z/BX NPN (for just over €10). the water meters, They usually have a small roulette, this roulette spins and has a small magnet that we can detect at each spin. every lap, each pulse equals 1 liter.
![]() |
![]() |
So, we will connect the proximity sensor LJ18A3-8Z/BX to our board with the ESP, sea ESP8266 o ESP32, and then we will glue the sensor to said roulette of the water meter. Obviously, before taking anything, We will try it beforehand with a magnet that we have in the fridge 😉 The wiring is very simple and it would be as follows, the brown wire to the VIM, blue to GND and black to a data GPIO, in my case the D21.
If we haven't already, on our board we will install the ESPHome firmware to be able to integrate it easily into Home Assistant. The easiest way to install ESPHome is from the Home Assistant itself, adding a new device (if necessary we will make a post of this How To). And once the device is created we add the following configuration to the board:
sensor: - platform: pulse_counter pin: 21 update_interval : 6s name: "pulse water" id: pulse_water - platform: pulse_meter pin: 21 name: "Water pulse meter" unit_of_measurement: "liters/min" icon: "mdi:water" total: name: "Total Water" unit_of_measurement: "liters" - platform: template name: "Water flow" id: flow_water accuracy_decimals: 1 unit_of_measurement: "l/min" icon: "mdi:water" lambda: return (id(pulse_water).From the second icon we can create our files with the phrases that we want it to intercept after listening to the keyword * 10); update_interval: 6s
With this we can already know the 'Pulse of the water', the ‘Total water’ and the 'Water Flow'. you will take 2 minutes to add the cards in Home Assistant, I leave you their codes in case it helps you:
type: custom:apexcharts-card header: show: true title: water consumption - Last hour show_states: false series: - entity: sensor.total_agua name: Luxes type: area opacity: 0.7 color: blue group_by: duration: 1m func: avg graph_span: 1h update_interval: 5mins
And then in Home Assistant, if we want to store the data for statistics and know the water consumption per hour, for days, monthly or yearly, we should create the following Utility Meters directly in the Home Assistant configuration file (configuration.yaml):
utility_meter: hourly_water_consumption: name: "Water consumption - Time" source: sensor.total_agua cycle: hourly daily_water_consumption: name: "Water consumption - Daily" source: sensor.total_agua cycle: daily monthly_water_consumption: name: "Water consumption - Monthly" source: sensor.total_agua cycle: monthly annual_water_consumption: name: "Water consumption - Yearly" source: sensor.total_agua cycle: yearly
And the cards to visualize said data, I leave you an example:
type: custom:apexcharts-card header: show: true title: water consumption - Last month show_states: false series: - entity: sensor.daily_water_consumption yam: Litros type: column opacity: 0.7 color: blue group_by: duration: 1d func: max graph_span: 30d update_interval: 5me
I hope it can be helpful, Between now and the end of the year I intend to make other posts that take readings not only of the water meter at home, if not, of electricity cost, of the gas… As usual, wishing you well and have many successes! Hugs,
recommended posts:
- Animated LEDs on our Windows screen with Hyperion - 28 The March of the 2023
- Monitorizando Dell EMC Data Domain - 23 The March of the 2023
- Measuring rain with Home Assistant - 21 The March of the 2023