WTH is it so difficult to get yesterday's total

I know it can be done, but WTH is it so difficult to get the last value of a total_increasing sensor before it is reset.

This could be added as an attribute to the sensor. Seems to me that adding this to the reset routine would be very easy.

This could be done for any sensor that is reset (statistics max sensor for instance).

For reference - 2022 WTH :frowning:
WTH - Why can I not get the last value of an incrementing sensor before it resets? - Archive / Month of “What the heck?!” 2022 - Home Assistant Community

[edit]
This note on the Statistics integration page - why is it so difficult :slight_smile:

As any measurement sensor has average, min, and max so each of these could have a ‘value before reset’ added as an attribute on reset.

If you create a daily resetting utility_meter on the specific sensor, it will have the attribute with the value for the previous period.

Yes, as I said you can (this only really works for utility_meter and is a bit of a hack for non utility meter sensors) but this WTH is why not, by default, add an attribute for resetting sensors of the last value before reset?

HA doesn’t know that a total_increasing or total sensor is resetting daily.
They could just go up indefinitely or reset weekly or monthly.
The resets are done by the integration providing the sensor, or in most cases the integration just pushes a new value through an API and some (cloud) service determines that there is a reset at 0:00. HA just receives a new value.

How does HA populate the last_reset attribute then? ( Sensor entity | Home Assistant Developer Docs)

last_reset is only needed for state_class: total. For state_class: total_increasing any value which is lower than the previous value is seen as a reset.
But also the last_reset needs to be provided by the integration. HA just receives a new value for that attribute from the integration. In case of an integration providing a sensor with state_class: total there is probably some code which provides a new timestamp for last_reset in case the new value seems to be reset (where this was not expected).

Of course an integration could also provide the previous value in an attribute, or maybe a separate sensor, but that would be something which needs to created for each integration.

Perhaps the solution then is a helper that can be triggered at a set frequency to collect a sensors previous value?

That would fix the WTH :slight_smile: