Link an item to a database entry

Dear all,

I’m looking for a way to define an item/thing which gets its data from a database. E.g. a sensor records all 30 seconds a value in a influx database. Now I want an item which is linked to the database values (e.g. just reading the value also every 30 seconds). At the moment I use a php script which is reading the values from the database and sends the data to openhab via mqtt. But this is quite unconvient. Therefore I’m wondering if there is a binding avaible to link things /items directly to database values.

Thank you

Not that I’d know of. However I’d try a different solution:

  1. Update the value of your item with an shell script via the REST API
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$state" "http://$OHIP:8080/rest/items/$item/state"
  2. Persist the values with persistence from openHAB

:thinking: that would get the actual state of the item and not a persisted state (I.e. from the database). You would need a REST call from the persistence package, in there besides the persistence service and the item name also the requested timeframe has to be stated.
Using a rule one could also just request a historicState (read Here)

Dear all, thanks for your feedback, but it’s still not really what I’m looking for. But maybe what I’m searching is not available in OH. And yes I’m only interested in the actual value, and not in the history. The actual value of the sensor is used to control some functions inside rules.

To be more precise: The values which are stored in the influxdb belongs to a Battery Management System. I cannot change the software as it’s not open source and it cannot be configured to utilize MQTT, but it can be configured to store all values in a influxdb. Based on several values (State of Charge, Dis-/Charging current, system status, etc.) I control some elements of my smart home. As I can see all values are updated every 30 seconds, my script is also running every 30 seconds: Extracting the last entry from the database an sending the value via MQTT to OH. In OH the rules are triggered on every change. Now I want to get rid of any additional script, service, … with directly linking an item to the latest db entry.

Best Regards,

So you need datapoints from an influxDB which are NOT created by openHAB.
Please note that all persistence services in openHAB use a database created by openHAB. If you created an own database the specifications of naming datapoints etc migth not be inline with the way openHAB expects them. In other words openHAB can’t read your database.