(this is just an example, I have more useful values I want to display as well ;-))

A bit more general the question would be: How can I do calculations with the historical data that Home Assistant has stored?

For the today part I’m experimenting with the Utility Meter - Home Assistant integration, but that seems a bit off since I’m measuring sunshine and rain and not some utilities.

I’ve seen this integration but I think it does not apply to my problem. As I read a state to track is needed (like “on”) - I do not have that. Also neither of the described 3 modes (time, ratio, count) seems to fit my scenario.

But maybe I’m reading it wrong. How can I use this integration to achieve what I want here?

Get sum for today, yesterday, last x hours from a sensor

I use it to track the number of hours per day that my HVAC system is either heating or cooling. Then I supply that daily information to the Utility Meter integration to get weekly/monthly/yearly values.

You can make the time range whatever you want provided you don’t exceed what’s available, for an entity’s history, in the database (typically several days worth of data).

I understand that this works in your case, because probably the HVAC has a status “cooling” or “heating” that the History integration can track over a free to define period of time.

But in my case all I have is a sensor with a steadily rising “total value” (see graph above). I can not see how I would use the History integration with this.

My mistake; you’re right. History Stats tracks a given value but you want to calculate the sum of values over a period of time.

I think the closest thing might be the Statistics integration. I think you would have to use max_age to restrict the time range (but it still might not meet all of your requirements).

No, the Riemann sum integral is kind of the other way round - it converts for example power (W) to energy spent (Wh) by integrating over time. I already have the integrated values, so to speak.

Hm I’ll take a look at the Statistics integration again. It seems it can give the min and max values, so for a sensor like mine (always just adding up) the calculation would be an easy “max - min” for the given time span. Maybe pushing the sampling size to something near infinity (instead of just the last 20 measurements) and setting max_age appropriately I could possibly get the “last x hours” and “today” values. No idea how to go about “yesterday” with this approach though.

As a side note, I just noticed that Home Assistant can do the “today” part in it’s own “Energy” tab:

It’s really strange how e.g. the new “Statistic Card”, that has been introduced with 2022.11, can return a value for today, yesterday etc., but the Statistic Integration only provides this “max_age”, which doesn’t help for yesterday or last month…

Did you find a solution for this?
I have a similar problem where my heating unit only supplies number of starts since it was installed and the total amount of time on in seconds since installed. It would be nice to combine these to produce how many starts and how much time spent on per hour and per day.