Water Consumption

Hello,

I’m currently using Tasmosta with a water flow sensor (that is connected to my main analog meter), and I have the total consumption (very acure) with the analog meter.
I’ve made a rule on Tasmosta that saves the value from time to time, so when the power goes down or it reboots I have the last value.
Now I want to move to ESPHome, the hardware part is done (is the same :P), and I’m using the following code:

  - platform: pulse_meter
    pin: 14
    name: "Water Meter"
    id: water_meter
    unit_of_measurement: "l/min"
    icon: "mdi:water"
    total:
      name: "Water Total"
      id: water_total_id
      unit_of_measurement: "l"

Have not tested with the sensor, but looks OK.
Now my issue is how to save the total consumption?
I want to store the value on ESP so if HA is not available it keeps track of the usage, my goal is that this value is the same as the one shown on the meter, and from my use, if the ESP does not reboot/looses power it is.
I don’t know if is there any function to store before reboot and recall after boot?
Since it will send to HA, it might ask HA each time it reboots the last value send and update the local value?
But what happens if it boots and HA is not avaiable?
Please share your thoughts about this :).

Thanks!

I have a watermeter (and gas) using basically the same.
Value’s are saved to HA though, except for when running updates, HA never goes ofline on my end (runs on a PI-4). Been runing this for two months, and i don’t have any noteworthy deviations …
My meter works with a reed switch, so i added a debounce filter to filter out the occasional errors when flow rate was low.

You could add a global and use a lambda to save the value to said global:

 globals:
   - id: total_water
     type: float
     restore_value: true
#     initial_value: xxx.xx  <- put your current meter value here if you want

Add a simple lamba to your pulse_meter

       on_value:
              then:
                 lambda: |-
                   id(total_water) += 0.5;  <== My meter gives a pulse every 0.5l hence the += 0.5

However, this will write to your esp’s flash allot, and i would advise against it though…

can be easily mitigated by using a sane flash write interval:

# Example configuration entry
preferences:
  flash_write_interval: 1min

https://esphome.io/components/esphome.html#adjusting-flash-writes

esphome also shouldn’t write to flash at all if the values are not changed. Something that could come in handy in such a use case.

True, just remember when the water is runing, that value changes every couple seconds.
I guess it’s you choice. I have a very stable HA and Wifi, so no issue on that end for me.
If you use a sane flash interval it will work long time i am sure.
Just wanted to point it out