Extending "last" value to now

Hello. I’m new to InfluxDB. I’m using it with OpenHAB for data persistence of my home devices along with Grafana to plot some of the values. Specifically, I’m trying to make a graph of my living room lights, which are a dimmer. OpenHAB only saves the state of the switch when it changes. How can I write a query that propagates the latest value to the current time?

I don’t want to calculate values in-between either because it doesn’t make sense; Meaning a value of 100% at 3:30 and value of 10% at 4:00 should not generate a point of 55% at 3:45 because at 3:45, the lights were still at 100%.

Looking at this screenshot, you can see the line does not extend all the way to the right (ie: “now”). I know absolutely nothing about Flux language. I slapped this query from the example provided by Grafana and a tiny bit of exploring in the Influx UI.

from(bucket: "home_metrics")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "LivingroomLights_Dimmer" and r._field == "value")

Any help here would be appreciated! Thanks!

Hi @utdrmac Welcome to the Community Forum!

Your question sounds similar to a recent post (which BTW remains open). Take a look at the last comment over there with the square wave pix. So I guess you’d like the last reported value to be propagated forward?

Hello @utdrmac,
My first thought is to do:

import "experimental/array"

array.from(rows: [{foo: "bar", baz: 21.2, _time: 2022-07-30T00:00:00Z}, {foo: "bar", baz: 23.8, _time: 2022-07-31T00:00:00Z}])
|> range(start: 2022-07-29T00:00:00Z, stop: 2022-08-02T00:00:00Z)
|> aggregateWindow(every: 1d, fn: first, column: "baz")
|> group()
|> fill(usePrevious: true)