Calculating power consumption within a query

i have solar energy and want to calculate the power that i consumed myself.
the following information are available:

  1. power i exported to the grid (summed total)
  2. power my solar energy produced (summed total)
  3. current power production
  4. current power from or to the grid (export to grid: negative value, import from grid: positive value).

what is the easiest way to get what i want with a flexible v.windowPeriod?

in my overview dashboard i take the first two values, “aggregateWindow” them over a fixed duration and calculate kWh of it, which i can then substract from each other (aggregateWindow with duration of (e.g.) 60m for produced solar power, select last value, get the difference and i have the kWh for one dataseries; from this result i substract with the same function the exported power and get the power i consumed on my own).
that is fine for a fixed known timeperiod.

but with changing v.windowPeriod I can’t calculate the kWh for that period. I expected to get my desired value by
|> aggregateWindow(every: v.windowPeriod, fn: last,timeSrc: “_start”)
|> map(fn: (r) => ({_value:r._value/v.windowPeriod*60.0, _time:r._time, _field:“kWh”}))
but that doesn’t work because calculation is not possible with a duration.

Any ideas? Can anyone understand what i try to explain? :wink:

kind regards,

Hi, not sure i completely understand, but you can always convert a duration to a number using something like uint(v: v.windowPeriod). That number is in nanoseconds, so to convert to seconds, you would divide by 1000000000.

thanks, that seems to do the trick!
now i can take the next step, thanks a lot!

kind regards,