Openhab, Grafana & InfluxDB2 - State Timeline & Status History for Simple motion sensors

Openhab, Grafana & InfluxDB2 - State Timeline & Status History for Simple motion sensors

Hi i was hoping someone could help a newbie out.

Im playing around with Grafana trying to make a “graph” that looks like the following:


Link to this here

For example the query i have is the following:

from(bucket: "openhabdb")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["item"] == "Room1Eye" or r["item"] == "Room2Eye")
  |> filter(fn: (r) => r["_field"] == "value")
  |> map(fn: (r) => ({
      _time: r._time,
      _value: if r._value == 1 then "Detected" else if r._value == 0 then "Not Detected" else "Unknown",
      item: r.item
    }))

Its pulling the necessary data and all seems ok, i can see it, like so:

But i cannot make the visualization the same as in the example above! I try for many hours and i cannot get the blocks to be wide like that, i dont want those thin lines, even though the sensors catch for 4second movements.

I know there was a way to do it with the Discrete Panel, but its discontinued.
I have more sensors to add later, but im trying 2 for now. Also if the one sensor gets no movement for the 6hr chart, the whole sensor disappears from the chart until there is movement.

If anyone can offer a more efficient way of my query as well, that would be great.

Please someone can help me? I appreciate it

Welcome @jt2a to the Grafana forum.

What do you have in the Query options section? Please post a screenshot if you can.

1 Like

I created this using some test SQL data. Are you sure you are using the Status History visualization and not the State Timeline?

hi @grant2

I tried to do it your way.
Basically mine was still on State Timeline yes, however when i change it to Status History, as you can see below in the short video gif:
2024-10-20_1

It eventually shows the states as bigger blocks, but only when i change the time to last 5min, or last 15min, as i increase it to 24hrs, it creates thinner and thinner lines.
I even changes the Max Data Points to different values and it didnt do much of a difference. do you know how i can make it look like yours without the changing of the timeline compromising the width of the blocks?

Does turning on this toggle help?