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.
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.
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.