OH3: Influxdb, continuous query output linked to item

Hello,

My continuous query is creating a daily difference in Influxdb (= working good).
To visualize I created an Item in openHAB3 with the same name as the influxdb series. The link is working, you can see in the log (graph) if you click ont that item in OH3.
But, the actual value from the item (typically the last value in the series) is not ‘correct’ showing. Is this normal behaviour?

A related question:
I migrated from OH2.5 and I see a difference in the persistence while transfering my database.
In OH2 there were only the time and value item in a serie.
In OH3 the persistence added a tag (item) with the item name.
Is this needed? Or related to my question above? Because when using a continuous query the item tag is copied from the original series into the new series and new linked item.
Via Python script I can add this tag if needed.

Kind regards, Hans

You’d probably have to show more of how you achieve this as this is the first time I’ve heard of anyone doing such a thing.

But if you are expecting the Item to update just because InfluxDB’s data is changing then that’s the source of the confusion. openHAB doesn’t watch InfluxDB for changes. You’d need to write something to push the results of the continuous query to the openHAB Item, probably though openHAB’s REST API.

I can’t answer the rest. I stopped using InfluxDB after moving to OH 3. I don’t need it any more and eliminating InfluxDB and Grafana offered a chance to greatly simplify my deployment (went from five docker containers to two for my home automation).

Hmmm, that’s probably the problem, influxdb is changing the data without notifying openhab.

I’m using influxdb since openHAB2.5, and have no reason to stay with influxdb if there is a good alternative. Please let me know.

Let’s explain a bit what I’m doing.
I have some basic series like energymeter download, energymeter upload, solar production, gas consumption. From this series I can calculate my other series like own consumption, daily energy consumption, daily energy production… in Influxdb or Python code if the calculation is complicated and can’t be done with a query.

Example : I only monitor my gasmeter reading and put every increasing measurement into a series. This is the start for the other calculations. The daily consumption is derivated from a continuous query at midnight. In this query is a spread(value) function which calculates the daily (max-min) consumption and put this into a new series. To display I need to link it to an openHAB item.

When I started with openHAB I did everything with rules, every midnight I calculated the daily consumption and updated this value into te correct series. A lot of code and work to maintain. I realized all this code could be replaced by a simple continuous query.

With my migration to openHAB3 I was re-thinking and optimizing my setup and the way it works. During the years you learn and the unnessesary primitive workarounds stay in your code all messing it up.
Now I started from scratch and was trying to “keep it simple”.

Is there somewhere any best way of working, or best practice guide for setting up persistence in OH3?
How do you calculate time series from other series?

Regards, Hans

It depends on what you want out of persistence. For me I was just using it to drive a few Grafana charts. OH 3 has really good built in charting and I don’t care about the decimation that rrd4j does so I got rid of Grafana, Gradana Image Renderer, and InfluxDB an now just use rrd4j and the charting built into OH 3.

It’s important to understand what Persistence is and what it isn’t. Persistence

  • is a way to save the states of your Items based on some strategy
  • is a way to use the historic states of your Items in rules
  • is a way to summarize historic states of Items (minSince, maxSince, averageSince, etc.) for use in rules
  • is going to present the database in a way that is common among all the various supported databases which all can behave very differently; therefore the interactions are very basic
  • is not a way to have a database drive openHAB Item states
  • is not a way to let openHAB create and use custom database queries

Persistence is created by and for openHAB’s use. If you have data being added to the database or modified in the database outside of openHAB, openHAB does not know anything about it and isn’t going to be able to do anything with it. You’ll need to create some script or something outside of openHAB to process the data and push it to openHAB. Using openHAB’s REST API is usually the best way, though MQTT is also another good option. You could also set up rules that run periodically and poll the database using executeCommandLine.

When I need to do something like that I do it in rules. Though I pretty much don’t need to do anything more than a simple calculation to estimate my power bill based on the kWh used since the start of the billing period which is pretty easy to do in rules.

Thanks for your explanations.
I now understand the behaviour, was thinking before that openHAB was more integrated with influxdb.
Kind regards, Hans