InfluxDB2: Data storage

Tags: #<Tag:0x00007f4348339900> #<Tag:0x00007f4348339838> #<Tag:0x00007f43483396f8>

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.


rule "Set Temperature - Thermal collectors"
    Item Collector_Temp changed  or
    Time cron "0 0 * * * ?" //everyHour
    //Server URL
    val url = "http://<InfluxDbServerIp>:8086/api/v2/write?org=YouOrganization&bucket=YourBucket&precision=s"

    val timestamp = Collector_Time.state
    //alternatively using the system time
    //val timestamp = now.toInstant.getEpochSecond()

    //Using InfluxDB line protocol (
    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)

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


1 Like


thank you for the quick hint!
Now I recognized, that I should have also change the InfluxDB config file (services/influxdb.cfg), as the documentation denotes:
InfluxDB (0.9 and newer) Persistence - Configuration. This file changed kind of massively regarding to V1.8.

With doing so I can still use the Persistence Configuration file as got used to doing with Influx DB V1.8. It’s like magic!

Best regards