Consider points outside of time range


I’m new to influxdb (and grafana) and I’m trying to create my first dashboard.

I would like to have a graph of temperatures and I have many sensors that collect data. Some are sending data really often and some others not really.

(Data are sent from home assistant to influxdb then visible in a graph in grafana)

So I did my first request:

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["entity_id"] == "something" or r["entity_id"] == "something_else")
  |> filter(fn: (r) => r["_field"] == "value")
  |> map(fn: (r) => ({ _value: r._value, _time: r._time, _field: r["friendly_name"] }))
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

and I can get a graph (yay) like that:

As you can see I have many problems ^^

  • some sensors are just showing one point (even having data from past/future): If there is a existing point in the past or in the future I would like to draw the graph instead of just showing one point.
  • If the timerange is from something in the past to now, I would like to consider the last point as the current value and then draw the graph as I get the last point now.

I’m searching on google but I can’t really find something that is matching my needs. I already tried with the createEmpty: true as a param in the aggregateWindow but it does not work as expected as I’m seeing a graph with 0 value between every point (the graph has no sens at the end).
I also saw the fill(usePrevious: true) but it does not seems to make any difference (or I’m using it in a wrong way).

Could you please help me to fix those problems ?

I’m not sure about the category in which I must put that topic, if it’s not the right one, just tell me and I’ll try to move it.


Hello @X4V1,
To me it looks as though those sensors only have one point and they each represent a different series which is why you’re not seeing a line for each sensor.
Fill previous won’t make a difference if you don’t have null values to fill.
You could consider pivoting the data first. Then this would create null spaces then you could fill.
But I’m not sure how grafana handles graphing pivoted data.

    |> pivot(rowKey: ["_time"], columnKey: ["sensor"], valueColumn: "_value")
    |> fill(usePrevious: true)

Let me know if that helps.