Hi,
I’m trying to generate daily kWh bar graphs from my minute-by-minute power (watt) data.

I’m integrating as others have done in the past. Note the power data is stored in Influx, and it’s in watts as one data point per minute.

SELECT integral("value") /(1440) FROM "autogen"."data" WHERE ("topic" = 'power1') AND $timeFilter GROUP BY time(24h) fill(none)

I thought I have to divide the integral by (60 minutes * 24 hour = 1440). But that gives me kWh values that are about twice what they should be. I’m having trouble working out what the division should be. Can someone explain to me what the division value should be?

I feel dubious about the use of “integral” for this - you have Watts, measured
once per minute. That’s either going to be an instantaneous measurement (such
as “7.8 Watts right now, no idea what it was 5 seconds ago”), or it’s going to
be an average over the previous minute (such as “468 Joules used in the past
60 seconds = an average of 7.8 Watts”) - which it is depends on the instrument
making the measurements.

If you want to convert Watts (measured once per minute) back into Joules (or
kiloWatt-hours; same thing except for a multiplication factor of 3.6 x 10^6)
then I think you need a simple “sum” operator:

assume this pattern repeats (mysteriously) 12 times to create 1 hour’s data.

The sum of the above 5 values is 47.3; multiply this by 60 (seconds) to get
2838 Joules (or Watt-seconds). Since the pattern repeats 12 times in an hour,
multiply by 12 to get 34056 Joules of energy used in that hour.

34056 Jouleṡ ÷ 3.6 x 10^6 = 9.46 x 10-³ kWh

So, I think you should be using “sum” to add up the Watt power values, and
then dividing by ( 3.6 x 10^6 ) ÷ ( 60 x 12 ) = 2500 to convert into kWh.

Note that 2500 is approximately twice 1440 (which is what you’re dividing by
at present), hence explaining the values you’re currently getting as being
about twice what you expected.

[EDIT: wrote this before seeing @pooh 's response above]

Maybe this is bad advice, but have you considered using sum() instead of integral()? If you have regularly spaced values that should not lead to any loss in fidelity, while making the calculation more straightforward. Then your divisor should (I think) be 60000.

[EDIT 2; to clarify the 60000:
If you have constant consumption of 1000 Watts, over the course of an hour you would consume 1 kWh of energy. In this situation, the way you’re storing data, you’d have 60 readings at 1000 each, which would sum to 60000. So that’s your scaling factor to get from a sum of readings in Watts (at 60x sample rate per hour), to a total in kWh.]

Note that whatever approach you use, you should not be dividing by 24. The fact that there are 24 hours in each of your aggregation periods isn’t a factor in your calculation - unless you want to calculate average power, as opposed to total energy in the period.

Aha, good point - my factor of 12 was because I had produced imaginary numbers
spanning a 5-minute period, therefore I multiplied by 12 to get an hour.

However, I managed to explain the approximate 2x difference in expected and
observed readings with my calculation - how does this work with yours?

60000 ÷ 1440 = 41.67

I wonder how we get back to the OP’s expected energy measurements.

@automategraphs - can you give us a representative sample of 1 hour’s
measurements from your data store (so, 60 1-minute readings in Watts),
together with what you believe the correct kWh value should be?

My take is that using integral() added an extra factor 60 (with respect to a simple sum()) since it defaults to a “per second” integration - while @automategraphs had values at 1-minute spacing. And taking it all together, the ratio between 41.67 and 60 is close to that factor 2…