Updated InfluxDB binding with tags

Is it feasible to deliver the update with OpenHAB 2.5? Having tags would add a lot of value to the InfluxDB persistence binding. I am happy to help by testing things with my dockerized OpenHAB/InfluxDB environment.

Thanks @dominikkv for you work! Finally got to installing it right now and it works really nicely.

For anybody searching for a migration strategy for the “replace _ with .” problem: I just grabbed a simple bash script to do this:

 foreach olditem in $( influx -database openhab_db -execute 'show measurements' | grep -E '[_]' ); do echo "select * into \"${olditem//_/.}\" from ${olditem}"; done

The output I pasted back into influx, double checked the new measurements were there, then did the same with

foreach olditem in $( influx -database openhab_db -execute 'show measurements' | grep -E '[_]' ); do echo "drop measurement ${olditem}"; done
1 Like

Okay, after running a few days I noticed one problem. Somehow .averageSince() doesn’t work anymore.

This debug rule:

rule "debug output"
        Time cron "0 * * * * ?"

produces only this log output:

 2019-12-02 18:13:00.002 [DEBUG] [ersistence.influxdb.internal.InfluxDBPersistenceService] - Got a query for historic points!
 2019-12-02 18:13:00.002 [DEBUG] [ersistence.influxdb.internal.InfluxDBPersistenceService] - Query: SELECT * FROM "openhab_db"."autogen"./.*/ WHERE item = 'PresenceCountdown' AND time > 1575305880s  LIMIT 2147483647
 2019-12-02 18:13:00.028 [DEBUG] [ersistence.influxdb.internal.InfluxDBPersistenceService] - Returning query() with 985 items
 2019-12-02 18:13:00.030 [ERROR] [thome.model.rule.runtime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'debug output': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

but when ask the persistence over HTTP I get meaningful data:

kandre@mainframe(pts/7) ~ % curl 'http://openhab.ak-online.be/rest/persistence/items/PresenceCountdown?starttime=2019-12-02T18:18:00'

Does anyone have an idea if this is caused by the InfluxDB binding or where I could find more debugging information?

Hey @klaernie,

this is an exception thrown in your rule. Your log says that the InfluxDB binding has provided 985 data points, and that you have an error in your logInfo() call. Try something like this:

logInfo("debug", "Average: {}", PresenceCountdown.averageSince(now.minusMinutes(15)));

Thanks for your rename script!

@martingruening, I don’t think it’l made it into 2.5, as M6 has already arrived, wich will be the last milestone. But you can use the jar I have provided.

@all: Good news - PR is ready: https://github.com/openhab/openhab2-addons/pull/6507

Thanks for your feedback, and sorry again that it took so long :slight_smile:



@dominikkv Could you change the way Color items are written? I just tried to graph an RGB lamp’s brightness, and it took me a while to find out why Grafana didn’t want to deliver data for it :wink:

From my user perspective I would expect that the binding writes three or six values into InfluxDB:

  • either HSB values into (H,S,B)
  • or the RGB into fields (R,G,B)
  • or possibly both together.

Maybe to keep backwards-compatibility the field value should be still written like it currently is.

From my personal view I’d like the HSB approach best, as openHAB uses it internally, so conversion is lossless and it supports the use case: “Show me a graph of the lamp’s brightness”.

Else I can report everything still working fine, once I discovered that during the 2.5 upgrade the 1.14 bundle got activated and was messing with my setup.

Well, it wasn’t the weekend which brought time to try out your new addon-version, it was actually only happening right now.
Having just installed and configured my items, I want to confirm that everything works as expected, based on your documentation.
I am sending items into InfluxDB, they get mapped to measurements based on the group they belong to and have tags added, based on the per-item definitions.

@dominikkv: Thank you very much for making this possible! My InfluxDB set up is becoming way clearer and better usable through this.
If you don’t hear anything more from me, that means I am a happy user who did not find any problems with the add-on.
And all the best for 2020!

@dominikkv Will your version of the Persistence service work with InfluxDB 2.0?

No it doesn’t.
The protocol and drivers for 2.0 are different.
I started on a module with 2.0 APIs (look at this message).
But this is a very preliminary work that has been paused from the last months.
I’ve I get some guidance and support I will try to continue on it.

1 Like

@dominikkv: sadly your PR was closed by Kai Kreuzer. What does it actually mean? More work on your side to be done :(?

Also it would be cool, if one could enable “auto-tagging” based on the current timestamp. Means: putting a tag for the current month, year and maybe week number. Since otherwise it’s almost impossible to perform grouping with influxdb in Grafana. E.g. to graph the power consumption sum on a week, month or year basis.

You can group your data by time without tags.

I do it this way.

A new version of the addon has been integrated into master branch and will be available in OH 3.0.
It was originally a new addon for InfluxDB 2.0 but finally, it has been refactored and it’s a rewrite of the previous addon that supports both versions and incorporates @dominikkv work with tags.


That could be a starter, thanks! I was just reading about that there’s currently no way to group by month or year - only per days. So it’s always about the last n days and not about concrete and exact months. E.g. “show me the sum of consumption of january” (exactly 01.01.-31.01.) would be easier then to create graphs showing the totals over a year per month.

And that are great new @lujop, thanks :D!

while you wait for OH 3.0, you can directly send data to InfluxDB from OH instead of using persistence which allows you to put in any tags you want. Or course you can’t retrieve them from persistence then either, but if you normally look at the data through Grafana, this can work. Example here.

Can the new binding be tested/usef with openHAB 2.5 or is it only compatible with 3.0?

I am using OH 2.5.4 plus the JAR of the updated add-on (which was shared in this comment of this thread) and it works.

As far as I understand this PullRequest, the binding was massively rewritten to support both InfluxDB v1 and v2.

I don’t want to migrate to the older jar-Version and than migrate again once the new binding is released officially.

Hi, my contribution it’s only compatible with 3.0 because it uses new new openhab interfaces instead of eclipse smarthome ones.

It should be able to backport to 2.5 because it doesn’t use any feature only available for 3.0.
But some work to change packages and test it would be needed.

1 Like

i am updating openhabian from 2.4 to the current version incl. influx and grafana and now i am being asked to keep current version of influx or to install maintainers version. what should i do here ?

Configuration file '/etc/influxdb/influxdb.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
Y or I  : install the package maintainer's version
N or O  : keep your currently-installed version
  D     : show the differences between the versions
  Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** influxdb.conf (Y/I/N/O/D/Z) [default=N] ?


Here is your answer.

thanks :see_no_evil: