I just configured a water-meter with an ESP8266 and combined a few info gathered in the documentation and the forums.
I want my water meter in HA to show the total (in m3) I read on the physical water meter.
I found documentation on how to create an action to arbitrarily set the total to the value I read, which can for sure gets handy if for any reason the value in HA diverges from the physical water meter, or to preset the info without having to hard-code it at compilation time, making it dangerous to adapt each time I make a change or whenever ESPHome gets updated and I want to recompile with latest version (which happens every few weeks for sure).
I understand that ESPHome is supposed to be able to persist the total in flash so that it gets reset to that value if the board is rebooted for instance (taken for granted the previous value was indeed persisted, which happens every 5 minutes in my setup, if some changes happened, at least that what I understood).
So:
My current total is in phase with the physical reading
I made sure water was used and usage detected in HA
I waited (much) more than 5 minutes to be on the safe side
I reboot the device
Total is reset to 0
Somehow I miss something but don’t know what.
Here is the relevant part of the corresponding YAML, if that rings some bell.
You find such links in the official documentation of HA: Integrating your water usage - Home Assistant so I’m basically trying to follow the “guide”, but I’m open to any suggestion based on my requirements I listed.
I don’t really need all those sensors, but what’s interesting:
Total volume in m3, so that it’s usable in the Energy dashboard and easily comparable with the figures I read on my own
Debit: number of liters/min
Number of liters since last reset, always handy, (directly related to m3, or the other way around but handy anyway)
I suggest that you have one gpio connected sensor (meter or counter).
Make a template number to adjust total.
Make whatever template sensors if you want to see different formats (no-sense to me).
This results into two sensors, one for the water flow, the other one for the measure on total consumption, which is exactly what is expected from such a device, nothing more, nothing less.
What I figured out:
The globals water_meter_total is still an integer, even if displayed divided by 1000 to get m3
I have 4 counters, the inductive sensor is on the fourth one but that one measures deciliters (dl), so its value is naturally to be excluded when presetting the total counter
So now my ESP8266 is flashed with this strip-down (and much more meaningful) version, nice!
I install the device
I set the initial total value
Water has been used here and there and properly reported
It’s more than 45 minutes since the installation
I reboot the device by removing power supply and back
Result: total meter resets to 0. So it still doesn’t work!
That will basically reset your global to zero the first time the pulse_meter will return a value after boot (which will be zero), or am I missing something?
For ESP8266, restore_from_flash must also be set to true for states to be written to flash.
There’s not any other description of that flag, and logically it must be at the same level of flash_write_interval but no so looking around and trial and error because syntax/naming changed) I found this to work for the compilation at least:
Trying again, it resets to something else than 0 but does not reset to the final value I read prior to reboot, where I bumped it up the total counter to what I read. Looks like it was reset to the actual number of liters consumed and tracked by the inductive sensor only. But basically it starts working
(and for those reading and wondering how to use the action to preset the value, it’s hidden in the Developer Tools > Actions).
Glad! The real complexity with HA and ESPHome is that the documentation lacks some (more) examples and the examples found in the wild are often not up-to-date anymore, with the syntax/options/locations to edit sometimes having changed a lot.
I wrote this because if you have a look at what I posted first in my very first message, I configured it as a float. So I was just explaining my findings.
With ESPhome 2026.2.4 this did not work. when booting on_value executed first and wrote over the global variable before on_boot could restore the total.
My solution was to perform the initialization after boot in on_value when the value is 0 which it of course is only upon first triggering during bootup: