Rolling 30 day energy usage

Hi
I can currently get my energy usage from MQTT and show daily, weekly and monthly sensors for gas and electricity but they reset each new day/week/month. I’d like to be able to create a sensor that shows the last 30 days of usage. Does anyone have any ideas on how I could do this?

Thanks!

My current thinking is to have 31 entities, one for each day and just before the day resets update the relevant entity for the day. Then I can have one sensor that adds up all 31 entities. Does anyone else have any ideas?

Is this what you are looking for?

I have looked at that but it looks like that just adds up the sensor values and resets them back to zero at the end of each period

I see I didn’t understand you first post. Your looking to drop day 32, not a reset.

Unfortunately I don’t know of a solution.

Did you find a way to do this? I am looking to create something similar (in my case use of solar energy on rolling last 14 days)
I could see a “dumb method” with an automation every day at 23:59 to add day one and drop day 32, but that would mean a lot of coding for something so basic.

In the meantime, I’ll try if the statistics integration could work:

sensor:

  - platform: statistics
    name: "Solar production over 7 days"
    entity_id: sensor.total_yield
    state_characteristic: change
    precision: 2
    sampling_size: 2000
    max_age:
      hours: 168

No. I gave up on the idea in the end