Hi again @fe-hicking
I am afraid I led you down the wrong path, and there is a better way to do it. No need for window()
or spread()
functions. Just aggregateWindow
every 1 month and then the difference()
function, which sorta does the same thing as spread()
in this case (since, just before the difference()
function, we are (in the aggregateWindow
function) downsampling the data by grouping the data into fixed windows of time and applying an aggregate or selector function to each window.
Try this:
from(bucket: "homeassistant")
|> range(start: -12mo, stop: -1d)
|> filter(fn: (r) => r["_measurement"] == "tasmota")
|> filter(fn: (r) => r["_field"] == "Total")
|> filter(fn: (r) => r["host"] == "192.168.0.42")
|> aggregateWindow(every: 1mo, fn: sum)
|> difference()
|> yield(name: "sum")
With my data, I am getting something like this in Grafana:
I believe that if you expand your host to query more than just the office (and include living, kitchen, etc.) then you should get stacked bars like the example below (from play.grafana.org), but not sure.