0

This is my query:

from(bucket: "power_monitor")
|> range(start: today())
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> keep(columns: ["_measurement", "_value", "_time"])
|> increase()
|> last()

It tracks the amount of energy used since the start of the day, except I think the timezone is wrong... it was working perfectly until ~8pm when all values were reset to zero.

Can I fix this in the query by adding a time offset? or set my timezone? I think I'd like the values to reset around 2am.

I got this from influx docs and added it to the query, but it doesn't seem to help (still all zeros):

import "timezone"
timezone.fixed(offset: -4h)
Progman
  • 16,827
  • 6
  • 33
  • 48
jpx
  • 123
  • 2
  • 9

2 Answers2

1

You need to set location option, ie.

import "timezone"

option location = timezone.fixed(offset: -4h) 

from(bucket: "power_monitor")
  ...

Or use location parameter of aggregateWindow function, ie.

from(bucket: "power_monitor")
  ...
  |> aggregateWindow(every: 1h, fn: mean, createEmpty: false, location: timezone.fixed(offset: -4h))
alespour
  • 397
  • 1
  • 5
  • 2
    setting timezone with fixed offset did not work, but setting via named location did! ie: `option location = timezone.location(name: "America/Toronto")`. – jpx Jul 17 '22 at 17:45
-1

I think I found a workaround, but accepted answer will be one which uses timezones and not experimental function.

workaround:

import "experimental"
starttime = () => experimental.addDuration(d: -6h, to: today())

from(bucket: "power_monitor")
  |> range(start: starttime())
  |> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
  |> keep(columns: ["_measurement", "_value", "_time"])
  |> increase()
  |> last()
jpx
  • 123
  • 2
  • 9