Create daily, monthly, yearly reports for energy consumption

After a long while i got two meters running measuring electrical power and gas consumption. They do it using a total counter, so the graph in HA dashboard will constantly rise up.

What i like to know is my relative consumptions per day, per current month and current year to have an indication how much is used. Therefore it would be great to have a line showing the estimated maximum, given by hand or value 12 month ago, to compare with them.

I have a similar question and so far I have not found a solution. When I add a statistics card I’m not able to select “Mean” for the energy meter reading.
However, I have to say that I wrote the integration myself and I import hourly statistics from the energy company into the statistics module: WienerNetzeSmartmeter/ at f28a0242519fec540ca91e6c0fcfd2ad201debc3 · reox/WienerNetzeSmartmeter · GitHub
So the question is: Is the mean not available because I miss to import it (I only import state and sum, and only hourly) or because this is generally not supported right now?

I tried the utility meter hint from Total Average Daily Power Consumption - #6 by tom_l but that does not work, because the sensor entity itself has no state - as the data is only imported into the statistics.

Is there anything I could do to still get the daily average?

That is not true. Each utility meter creates at least one (more if tariffs are used) sensor with a state that records the total for the defined cycle.

As I wrote on the other topic, what is the average of a totalising sensor?

It has no useful meaning. You can get the total for the day, the mean of that is just half the total for the day, which has no practical use at all.

You can calculate the mean of each daily total over a week. That would show your average use per day over a 7 day period.

To do that is a bit trickier. If you feed the raw total energy sensor to the stats sensor it counts up all day, ruining your average. So you need to record the daily total with a (time) triggered template sensor, just before midnight. Feed that triggered sensor that holds each daily maximum to a statistics sensor that gives you the 7 day average.

Yes, but as the sensor the utility meter is using has no state but only statistical data, it does not work.
The issue is, that I cannot set the state in that particular sensor, otherwise the values are duplicated in the statistics and I get weird results. (See also this question: SensorEntity: Insert historical statistics data but also keep sensor up-to-date)
Furthermore, the issue I have is, that the energy consumption is imported with 24h+ delay.
Maybe it is a different problem then.

I get your point, and maybe the question was ill-posed from the beginning.
What I want (and I think was also requested in the other topic) is the average consumption per day over a period of time. This is also a value I get on my energy company’s invoice. There they give me a total consumption, i.e., 2000kWh/a and from that they calculate 2000kWh/a / 365d/a = 5.48kWh/d.

So maybe I could rephrase the question: Is it possible to calculate the total consumption over each 24h in a period of time and get the average of that figure, given that I only import historical data into the statistics using homeassistant.components.recorder.statistics.async_import_statistics and thus the state of the energy sensor is always zero?

Oh the sensor you are feeding the utility meter.

A sensor without a state?

What the heck creates that?

The integration I linked above :sweat_smile:

As far as I understood this thread Import old energy readings for use in energy dashboard, the only way to import historical data is either by messing with the database directly or use the statistics of the sensor but never touch the state on the sensor. I tried to set the state accordingly, but this just triggers the statistics again and I get to negative consumptions and other weird things.
Or maybe I’m doing it all wrong…

You linked to another post that linked to two other posts. I lost track there.

I had another look. I have no idea how to help you with that particular case, sorry.

ah sorry… yes, too many intertwined posts…
The most recent one is this one here SensorEntity: Insert historical statistics data but also keep sensor up-to-date where I explain my thoughts on the problem with setting no state.
I guess the ultimate problem is, that HA is not meant to be used with historical data, but only with live data. If the time of insertion into the database is not the time of measurement, everything gets really messy.

regardless, thanks for investigating!

Hi, I am working with @reox on above mentioned integration, which merely is polling a Smartmeter data from one of our local energy providers via an API, which - unfortunately - is unreliable and reports data every now and then up to 48 hours too late. We would like to implement a custom import for the data, s.t. our HomeAssistant integration update does not trigger an update to the point in time the update is called.

on sensor update on 05.01.2023: API responds with data from 03.01.2023 and potentially 04.01.2023
on update we save the values stored on 03.01.2023 (or potentially 04.01.2023) as values for 05.01.2023 in Home Assistant, since we cannot a) override the value’s timestamp and b) cannot override an already stored value (e.g. API is missing data on day X, but on day X+2 we get more accurate data which we would like to update manually)

What we want to achieve is

Fetch data from API on 05.01.2023
Assume we get data back for (A) 04.01.2023, (B) 03.01.2023, (C) 02.01.2023
We would like to store the data as follows in Home Assistant
None → 05.01.2023
(A) → 04.01.2023
(B) → 05.01.2023
(C) → 05.01.2023
instead of (A) → 05.01.2023

Is this achievable somehow in Home Assistant?