InfluxDb downsampled data

I’m considering the move to InfluxDb (v1) from RR4J. I currently make use of charts, in the main UI and sitemaps, and analytics. I want to retain the RR4J functionality of downsampling historical data, but ideally I want to gain more control over this (e.g. temperature data I don’t need to retain granular information very long, where other measurements I have a desire to keep as-is).

As I understand it, this can be easily achieved with InfluxDb 1 through the use of retention policies and continuous queries to manage downsampling of measures.

What I can’t work out though is how openHAB is able to access historical data. Is there a naming convention or other concept that enables openHAB to access downsampled data points?

Maybe Influx V2 is something for you then. There, you can set the retention period and create downsampling rules.

import "timezone"
import "date"

option task = {name: "Einspeisung", every: 1d}

option location = timezone.location(name: "Europe/Berlin")

from(bucket: "openHAB")
    |> range(start: date.add(d: -1d, to: today()), stop: date.truncate(t: today(), unit: 1d))
    |> filter(fn: (r) => r["_measurement"] == "Einspeisung_kWh")
    |> filter(fn: (r) => r._field == "value")
    |> aggregateWindow(every: 1d, fn: last, createEmpty: false)
    |> to(bucket: "openHAB_history")

In this case, the downsampled data in the second bucket cannot be accessed directly from openHAB. But with a scipt:

#!/bin/bash

curl -s -X POST “http://192.168.178.26:8087/api/v2/query?org=my_organisation” 
-H “Authorization: Token 7topsecrettoken==” 
-H “Content-Type: application/vnd.flux” 
–data ’
from(bucket:“openHAB_history”)
|> range(start: -365d)
|> filter(fn:(r)=>
r[“item”] == “Gaszaehlerstand” or
r[“item”] == “Stromzaehler_kWh” or
)
|> filter(fn:(r)=> r[“_field”] == “value”)
|> difference(nonNegative: true)
|> sum()
|> group(columns: [“item”])
|> keep(columns: [“item”,“_value”])
’