How to display the 'current' value with Flux?

Hello. I’m new to Grafana and Influx, but am using them with openHab for device state history. In the screenshot below, I’m attempting to graph my living room lights which can be any brightness level from 0-100. Every 30m, and on every state change, openHab stores the state of the switch. While I can see those states on the graph, I cannot figure out how to “extrapolate” the most recent value to “now”. You can see on the graph that the line does not extend all the way to the right edge. I’ve seen other posts that say “change it to ‘Current’” but I don’t see that option anywhere.

Grafana 9.0.4
InfluxDB 2.3.0

@utdrmac Welcome to the Grafana forum.

Maybe try adding this statement in your Flux query?

|> fill(usePrevious: true)

Hi @grant2, thanks for the reply but that didn’t seem to make any difference. I tried that in the InfluxDB UI explorer-thingy and adding that didn’t change the output.

you are asking to get data between the moment where data is written in base and now.
But there is no data during this time since you collect it every 30 min.

if you wan’t your graph to go to the right edge you have to get data during this time.
in order to do that you could use aggregation function to get mean of data every 30 min (with flux), or maybe use default value in grafana.

In my point of view, you want to display false data (none existing data)

I don’t want false data, I want the “current data” or the “last data point”. The lights turned on at 10:35AM. A data point was saved due to state change of the switch. It is now 10:48AM. The lights are still on but there is no explicit data point saved because the switch state hasn’t changed, nor has the 30m timer fired off. I want the graph to show the “current data” or “most recent data point” which is that the lights are on (10:35AM). Just extend the latest data point until the next point is collected.

If your data is boolean, have you considered using a State Timeline? I believe there are a few options in there that can allow you to achieve what you have described.

Example of mine here: Best way to display open/closed for doors and windows - #5 by grant2

1 Like

I think this is a very valid question. Suppose OpenHAB didn’t save the status at 30min intervals then you would have a serious problem on your hands. (Have a look at fill(previous) should find most recent value, even if outside query time range · Issue #6878 · influxdata/influxdb · GitHub).
If believe OpenHAB saves the status every 30min because of this issue. Luckely it does that so the function last() will be able to give you what you need after you set the time interval to (now-31min) or something similar.