Energy total of the last 365 days

I am not really interested in the energy consumption of the last day, week or month. It changes to much during the year and during the day.

What I really want to see is what happend the last 365 days. Or the moving average of that time. Is it going up or down is usefull information for me.

Is there any way to extract that information, to calculate it or to show it?

1 Like

Hi Dolleman,

Did you get this running? I was googling for exactly the same question and come to your message. Did you solve it?

Regards,

Bert

Energy Dashboard – Calendar Icon – This Year

You can then easily switch between years too.

I’m afraid that is not the solution.
This year gives you the energy used from januari 1st. And is increasing every day.
What I want is energy used the last 365 days.
That number should be constant from day to day.

You can download the data via the 3 dots menu now too, if you don’t like how it displays it.

I think you are missing the idea, brooksben11 We want (correct me if I’m wrong, Dolleman) the an entity or counter on our dashboard that gives the usage in the last 365 days. So every day, the oldest day drops out the window, and a new day (yesterday) comes in. So is there a way to do e.g. the calculation “Electricity meter value of March 20th 2024 - Electricity meter value of March 20th 2023” and display it in a card? And tomorrow it should show “Electricity meter value of March 21st 2024 - Electricity meter value of March 21st 2023”, etc.

Regards,

Bert

There’s not really any way to extract long term statistics into entities.

You could do this if you had the full years worth of data in your recorder, then you could create a statistics sensor that would give you the change over the last 365 days, but assuming you’re keeping a reasonable purge window (~10 days), there’s no way to get an entity to show the change over the last 365 days, if that information is only in LTS.

Actually I guess a statistics card could show this on the frontend from LTS, but it can’t be added to an entity.

That is correct @brjhaverkamp.
This number is a constant if your energy consumption stays the same.
If the number drops, you are saving energy, if it is rising you are using more.
The reason that I want this is that I’m not really interested in the absolute consumption. I want to know if the things I do are posive or negative.

Hi Dolleman,
Good news. It took a while, but I finally got it working! First of all, I needed to migrate my historical data from Domoticz to Home Assistant. No use trying calculating the past 365 days usage if you only have a month of data :-).
I got it working with a sql entity.
I currently have this in my configuration.yaml:

sql:
  - name: electricity delivered 1 usage past year
    query: >
      SELECT
        (SELECT statistics.state FROM "statistics" 
        WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.dsmr_reading_electricity_delivered_1')
        ORDER BY created_ts DESC
        LIMIT 1)-
        (SELECT statistics.state FROM "statistics" 
        WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.dsmr_reading_electricity_delivered_1')
        AND start_ts<= strftime('%s', 'now', '-365 day')
        ORDER BY created_ts DESC
        LIMIT 1) AS pastyear
    column: "pastyear"

This gives me en entity with the usage over the past 365 days. You can adapt this to the P1 meter readings, or any other entity and other time frame easily.

Hope this works for you as well!

1 Like