Daily power consumption from watts

Hi, i’m using HomeAssistant with Sonoff / Tasmota devices for measure power usage.
I created graph for curent power usage in Watts. But i’m not able to create daily usage from these data.

If there is avg power consumption 4W in 2019-04-04, then it should be 0.1 kWh per day, but it not in my bar graph.

Can you help me with this?

To get from your example of 4W to 0.1kWh per day I presumed you multiplied by 24 to get Watt Hours then divided by 1000 to get kWH, so 0.096kWH. Not surprisingly you need to perform the same calculation in the query, so multiply by 0.024 instead of dividing by 1000.

Oh, that’s really work.
I use that method for another measurement, for what i have already summarized daily power consumption.

But in this case, it not work, or already summarized daily power bad. :confused:

Not sure exactly what you expect to see when you draw a graph with a point on the graph every few minutes but group it over 24 hours. Are you wanting to see the kWH usage over the last 24 hours at each point on the graph?

I wanna make graph with daily power usage:

I have had a chance to do some experiments and it seems to be working as expected for me. To make it simpler to see what is going on, can you remove the multiplier and just put the single channel on, the same as the one you show the line graph for. Then the bars should show the average value of the line over each period.

[Edit] Just looked at the last graph you posted and that is ok isn’t it?

Are you sure that is the correct & accurate way to convert power to energy.
The method I use (rightly or wrongly) is to use node-RED to calculate the W/seconds (joules) by multiplying the time between data points by the power, divided by 3600000.

I save that value to influx database.
Then, to calculate the the energy used per day, per hour or over any other time period, I simply sum() the values together.

I’ve compared the results with the values recorded in emoncms, and they appear to be accurate.

   // Find time since last datapoint update
   // note - msg.time is a epoch timestamp fed in via flow
   var updateTime = msg.time;
   var lastTime = flow.get('lastTime2')||updateTime;
   var t = updateTime-lastTime;
   // Get the values
   var solar=msg[1];
   var divert=msg[2];
    // Energy calculations
       var calSolar = (t*solar)/3600000;
       var calDivert = (t*divert)/3600000;

Measuring the average power over a period and multiplying it by the time should give the same result.

How is ‘average’ calculated - adding together the values of the datapoints, divided by the number of datapoints?

Yes, so provided the samples are regular and close enough together then you get a good average. If you think about it your algorithm is scaling each one and then adding them up, which is just a scaled version of the average. Provided the samples are regular then it amounts to the same thing.

Yes, but the samples are rarely regular (at least not for me), they should arrive every 5 seconds, but there is always small discrepancies, which considering there is 17,280 samples in 24hrs, the errors would add up.

Actually they wouldn’t, the more samples the more the errors will average out. Unless the variation in interval is somehow correlated with the power.

You could try it yourself by adding code into your algorithm that just adds up all the power readings for the day, then at the end divide by the number of samples to give you the average watts, and multiply by 24 to give you Watt Hours.

Well, running both calculations, I get very different results;

The top row is the way which I calculate energy, ‘Usage’ = 6.00kWh
The bottom row is the calculation as described above = 6.55kWh

Both running over the same time period - today so far.

Is the second one from adding up all the raw power values and taking the average? Not using your ones that include the time between samples.

It’s using the raw power values.

What is the sum of the power values and how many samples is that?
Also how are you setting up msg.time?

No idea without further work, but I’m using 5 second samples on this query;


msg.time is the time which the sample arrives in node-RED, and is generated via my spectacularly popular node-red-contrib-rf-decode :wink:

What period is that over? The 24 suggests it is a full day, but you said it is over the day so far.

Aaah! yes Colin, as usual, you are right!
Correcting the query to a common time period does result in a similar value…
But, energy is not usually calculated over 24hrs, it’s usually per day. ie from midnight to midnight, how can that be accommodated in the query, as it’s hardcoded to a set number of hours.