How to store / query Influxdb from OH?

I try to make watering system for my garden. All hardware (rain sensor and valves) was installed and connected to RPi. Now I try to implement clever watering algorithm. I store information from rain sensor in Influxdb (using Influxdb binding). I’ve found information that I can query this database but there is no information how to do it, there is no example how to do it using this binding.
In my example I would get info from database when last rain took place etc.

I can use Influxdb REST API to get data but how to send GET request from rule using extend?


There is an issue already created to make sure this info gets included in the OH 2 docs. For now you can find it in the old OH 1.x wiki.

@rlkoshak isn’t it easier to use historicState or even previousState of a particular item?

Absolutely it is easier, but only assuming that all the data is being saved to InfluxDB via Items and Persistence. I interpreted OP’s article to mean that the rain sensor is being stored in InfluxDB outside of OH. In that case, one must use InfluxDB’s REST API to query for that data.

If I misinterpreted then yes, using historicState and previousState would be far easier.

For sure I plan to store information about values from rain sensor in Influxdb.
If there is a simpler method then of course I will use it.
Are all Item values saved by OpenHab and are available with the PersistenceExtension class?
Does OpenHab use internal database or PersistanceExtension will use InfluxDB? If yes are all PersistanceExtension methods are implemented for Influxdb?

I recommend reviewing the persistence docs, the InfluxDB+Grafana tutorial and the Persistence with Groups Design Pattern.

In OH, persistence saves the states of Items. There is a config that specifies what database is used, which Items are saved, and how to save the Item’s states (e.g. every change, every update, every minute, etc.).

But be aware that one does not interact directly with the database. One stores data into the database by changing or updating the state of the Item. One retrieves data from the database by calling one of the persistence methods on an Item.

In short, you can only work with Items. If you need to get at data that isn’t represented by an Item you must use some other way to get at the data, such as calling the REST API.

Tank you very much now situation is clear.