Order of items returned

I have a valve which has two values (fields) associated: requested state and calculated state. The software extracting info from my home automation system and sending values to influx sends both values, regardless which value changes. The software also records which field’s value change triggered the write to the database into a tag named triggeringfield.

When simply querying data and graphing with Grafana, I have noticed that graphs are all messed up with back-and-forth lines:

image

Query used:

from(bucket: "hvac")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "valves")
  |> filter(fn: (r) => r["_field"] == "calculated")
  |> filter(fn: (r) => r["room"] == "bedroom")

Digging deeper, I found that indeed, the _time field does not seem to be in order.

This is - I am assuming - due to the additional triggeringfield making data end up in an other series and therefore an other table. Ok, so I drop the tag:

from(bucket: "hvac")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "valves")
  |> filter(fn: (r) => r["_field"] == "calculated")
  |> filter(fn: (r) => r["room"] == "bedroom")
  |> drop(columns: ["triggeringfield"])

The ordering does not change. There is a jump in the _time column, so its still not sequential.

Also, it looks like Grafana is simply using the order in which rows are returned to connect dots and not the actual _time values.

Questions (asks for suggestions):

  • how do I formulate a query that does not formulate data into tables first and not returns data I am currently not interested in, but just get the data sequentially, as it was written to Influx?
  • should I just simply do a sort(columns: ["_time"]) or is there a better way?
  • should I have the points are written differently, so the triggering condition would be delivered in a field rather than in a tag?

After thinking about it a bit more, I can answer my own question :slight_smile:. The triggering field should indeed be a field and not a tag, otherwise data will be in a different series.

Hello @mcfly9,
Nice! You’re correct.
Also you might have to use