Grafana influx timepicker not correct

Hello!

I have a query that wont return correct values when using the time picker in grafana. If I select “today” or even

Only if I do this the values will return correct, what am I missing?

import "timezone"
option location = timezone.location(name: "Europe/Stockholm")

from(bucket: "homeassistant/autogen")
  |> range(start: 2023-10-10, stop: 2023-10-12)
  |> filter(fn: (r) => r["_measurement"] == "kWh")
  |> filter(fn: (r) => r["entity_id"] == "vattenberedare_energy"
    or r.entity_id == "inverter_ac_energy"
    or r.entity_id == "studioserver_energy"
    or r.entity_id == "pump_energy"
    or r.entity_id == "soluttag_energy"
    or r.entity_id == "tv_bank_energy"
    or r.entity_id == "shelly1pm_kyl_frys_energy"
    or r.entity_id == "inverter_500v_ac_energy"
    or r.entity_id == "shelly1pm_husbelysning_energy"
    or r.entity_id == "sovrum1_element_energy"
    or r.entity_id == "satoshi_energy")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: 1d, fn: last, timeSrc: "_start")
  |> difference(nonNegative: false, columns: ["_value"])
  |> filter(fn: (r) => r._value < 300)
  |> filter(fn: (r) => r._value > 0)

if I try below the values will be recorded 24h from the time now() so that will be wrong I guess
|> range(start: -1d, stop: now())

if I try below the values will be wrong, (lower values from a forever increasing counter)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

also if I add below to the query without the specified timerange in the first example I will get “no data”
import “timezone”
option location = timezone.location(name: “Europe/Stockholm”)

also I checked the timezone in the browser that shows correct, it is almost like the grafana time picker wont collaborate with the time picker in the flux query??

Welcome @Mattie

To have the Grafana time picker determine the time range to use in your Influx query, this is the only way to do it:

Can you further explain this? I have many applications with an ever increasing counter and Grafana’s time picker works fine for me.

if I try below the values will be wrong, (lower values from a forever increasing counter)

Sorry for the late reply, the only explanation I can give right now is that the time and date in grafana doesn’t seem to be in sync with the time and date in influx somehow. I’m using aggregate window and I’m guessing that the start and stop of those Windows is messing up the output.

So the only way I can get correct values is if I’m writing the time and date manually in each query. So I’m wondering what the main difference is between for example 2023-01-01 - 2024-01-01
And if I set the exact same date in grafana. It should not be different right?