MQTT Sensor Gas Total_increasing keeps resetting

Hi, I seem to get lost - may need some help.
I have D1 mini running tasmota that includes a simple counter that counts revolutions on my gasmeter and adds 0.005 to a variable, that is then reported via MQTT.
It works perfect and sends an MQTT message on every half revolution (equal to 5 liters of gas) with the current counter state.
The D1 sends the following MQTT discovery message:
homeassistant/sensor/D849C_CNT/config

{
    "name": "Counter",
    "state_topic": "stat/D849C/STATE",
    "unique_id": "D849C_CNT",
    "value_template": "{{value_json.State.counter}}",
    "icon": "mdi:counter",
    "unit_of_measurement": "mÂł",
    "state_class": "total_increasing",
    "device_class": "gas",
    "device": {
        "connections": [
            [
                "mac",
                "D849C"
            ]
        ]
    }
}

and is properly recognized by HA. Status messages are also coming over just fine:
stat/D849C/STATE

{
    "State": {
        "binary": 0,
        "lLimit": 825,
        "uLimit": 862,
        "counter": 0.06,
        "max": 882,
        "min": 872
    }
}

I can also see the recorder is recording the history. But everytime I restart the D1 mini to see, if the sensor continues to sum up the readings it receives, it resets to 0 and starts all over again.
My expectation would be, that HA would just ignore the reset to 0 and add the new value to the last peak value before the drop with state_class: total_increasing.
My understanding of the docs and many similar questions in the forum is, that the combination of device_class:energy, state_class:total_increasing and unit_of_measurement:m³ should do the trick - but it doesn’t.
I already removed the device, checked for orphaned entities, purged the recorder, even ran Watchman from the HACS integration and then re-started the D1 to get it freshly registered - no improvement.
I’m out of ideas… help appreciated, tom


Screenshot of the history after my last trial-run: system cleaned up, D1 started at around 23:35, count increasing as expected, reset D1 at around 23:27, value falling to 0 and not continuing to rise like expected.

Your expectation is incorrect.

Home assistant just records what your sensor sends.

If you want an always increasing total, feed your sensor to a utility meter helper with no cycle set.

Thanks tom_I!
Then I was completely on the wrong track. I seem to have misinterpreted this sentence in the docs:

Statistics of the accumulated growth of the sensor’s value since it was first added is updated every 5 minutes.

If I get you correctly, “statistics” does not refer to the recorder in this context, but rather means and additional utility meter?
Will try to correct it with a utility meter later.

Thanks for the quick reply!

It refers to long term statistics, not the state value.

Works like a charm now - thanks for the nudge!

1 Like

It’s working for a few days now, but I have noted one thing, that is also reported in this thread:

The energy consumed via natural gas seems not to be added to the total consumption in the energy dashboard. It is displayed on the “Energy Distribution” card, but not added to the “Home” symbol, which I would interpret as the total.
Seems a Github issue was closed as “stale”, but it is still not working in V2023.8.0.
It’s strange that the the animation shows energy flowing from “Gas” to “Home” but it is not added.
(I did not upgrade to 2023.8.2 yet, because I’m waiting for my HA Yellow to arrive and for the patch of Zigbee2MQTT for the new entity naming policy).
image