Track diff between sensor's value between today and yesterday for thirty days (or forever)

I am getting total power consumption on a sensor and it is just rising. Yesterday’s value was 500, today is 600 etc. I want to track these differences (600 - 500 = 100) in a new sensor maybe and show a graph for the last 30 days.

I thought about using “history_stats” (History Stats - Home Assistant) but I have to set “state”.

Ideas?

Donot fully understand this, you want to show today vs. yesterday, get that, have that too
But then? Yesterday vs. Yesterday -1 ? etc.?

yes. I want to be able to show how much was spent yesterday, day before, two days before etc.

and a source of data is sensor.power_used which is just a number rising and rising.

Still not clear, compare today with yst, today with ystd -1, today with ystd-2
or today with ystd, ystd with yst -1, ystd -1 with yst -2, etc.

I think this will give what you want:
In configuration.yaml create a Utility meter with this code:

utility_meter:
  util_power_used_monthly:
    source: sensor.power_used
    name: Power this month
    cycle: monthly

And then add a Statistics Graph Card to your Front end with this code:

chart_type: bar
period: day
days_to_show: 30
type: statistics-graph
entities:
  - sensor.power_this_month
stat_types:
  - change

That will give you a bar type graph that shows the power usage for each day for the last thirty days.
You can see the values when you hover over the bar chart.

1 Like

thanks. actually Statistics Graph Card was absolutely enough. it survives restarts, looks nice, shows most of the info I need.