Getting gas consumption data persistent

Hi everyone,

I’m pretty new to HA and right now i’m a little lost between helpers, templates and everything, so i need a little help to get things going.

I installed a tasmota counter device to my gas meter (D1 mini with reed sensor on a elster BK-G4 MT) and it showed up in HA as sensor.tasmota_counter_C1. In order to make it work as a suitable source for the energy dashboard i defined a template sensor:

- sensor:
  - name: gas_verbrauch
    state: | 
      {{(states('sensor.tasmota_counter_c1') | float(0) * 0.01)}}
    state_class: total
    device_class: gas
    unit_of_measurement: m³

That worked fine, but now i have the problem, that a power loss on the tasmota counter resets the counter value to zero. I could save the counter value on the ESP periodically, but that’d brick it sooner or later and if i save less in order to save the flash memory i still have some kind of data loss.

So i came up with the following idea:

  • In HA have an buffer counter that reflects the state of the tasmota counter sensor
  • Also have an offset value
  • If the tasmota counter is lower than the buffer counter (e.g. after blackout) increase offset value by buffer counter
  • use offset value + tasmota counter for energy dashboard

Unfortunately i am pretty unsure if that’s a good idea to realize in HA, and if so, how to do it properly. Can you help me out? Any thoughts welcome.

Thanks in advance

This should be total_increasing.

That will mean HA will only consider values that increase (so a reset to zero for instance, will basically be ignored).

so simple…
Thanx a lot!