Hi everyone,
after searching without finding any result I decide to write down my solution for storing fetched data into the InfluxDB2 database using InfluxDB line protocol and OpenHAB’s HTTP actions.
For doing so, I add a simple rule for each data point I wanted to store in InfluxDB.
InfluxDb.rules
rule "Set Temperature - Thermal collectors"
when
Item Collector_Temp changed or
Time cron "0 0 * * * ?" //everyHour
then
//Server URL
val url = "http://<InfluxDbServerIp>:8086/api/v2/write?org=YouOrganization&bucket=YourBucket&precision=s"
//Timestamp
val timestamp = Collector_Time.state
//alternatively using the system time
//val timestamp = now.toInstant.getEpochSecond()
//Data
//Using InfluxDB line protocol (https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/)/line_protocol_tutorial/
val data = "Collector_Temp,Sensor=Collector temperatur=" + (Collector_Temp.state as Number).toString.replace(' °C','') + " " + timestamp
//Header information
val headers = newHashMap("Authorization" -> "Token <YoutAuthenticationToken>")
//Send HTTP post Request
sendHttpPostRequest(url, "text/plain", data, headers, 5000)
end
In the above snipped I changed the following user specified values:
- <InfluxDbServerIp>
- YouOrganization
- YourBucket
- <YoutAuthenticationToken>
I would prefer a more convenient way for storing my data, unfortunately, I did not build a whole understanding of persistence in Openhab till now.
Maybe one will have a hint or o better solution for doing this. If so, I am glad to hear about it.
Best regards
Stephan