Sending custom data to MySQL database


I would like to send a custom data to MySQL database from rules.

I’m building a custom web page that receives and sends data over Openhab API and for example i have a rule that if something is below some value it stores that notification into database so i could output it on my custom webpage.

Is that somehow possible to do?

With best regards,

Something like this?

Number myNotificationItem (gMySQLPersistencePolicy)

and then a rule that updates this item everytime the “something” is below “some value”:

rule "test"
       Item mySomethingItem changed
     if (mySomethingItem.state < somevalue)  {
              myNotificationItem.postUpdate(mySomethingItem.state as Number)

Then “myNotificationItem” will be updated with the value of myNotificationItem everytime it’s below your “somevalue” threshold. And this item can then be read in the mysql db based on the gMySQLPersistencePolicy you have defined.

I don’t think there is any way to get the necessary libraries into the scope of Rules so you can create the JDBC connection to your MySQL DB from the rules directly. So, if Alpoy’s solution will not work, you will need to develop an external script or service that OH can send the updates to and that script will save the data into your database structure.

You can use the Exec binding, executeCommandLine Action, to call a script that will save one value per call or set up a service with a REST API or MQTT interface that runs and OH sends messages to.