Fill MySQL database with OpenHAB

Tags: #<Tag:0x00007f6188d229b8> #<Tag:0x00007f6188d22878>
  • Platform information:

    • OS: Linux - Ubuntu
    • openHAB version: 2
  • Issue of the topic:
    I’m working on OpenHAB and I’m looking to save all items values for each value change. I have already followed a tutorial (openHAB2 & MySQL persistence setup): MySQL is well installed on the PC, the database is well created. Nevertheless, it remains completely empty. Does anyone have a solution?

  • Configurations:
    MySQL Persistence
    JDBC Persistence MySQL


# the database url like 'jdbc:mysql://<host>:<port>/<database>' (without quotes)

# the database user

# the database password

# the reconnection counter

# the connection timeout (in seconds)

# Use MySQL Server time to store item values (=false) or use openHAB Server time (=true).
# For new installations, its recommend to set "localtime=true".
# (optional, defaults to false)


# for Migration from MYSQL-Bundle set to 'Item'.

# for Migration from MYSQL-Bundle do not use real names.

# for Migration from MYSQL-Bundle set to 0.


// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
	// if no strategy is specified for an item entry below, the default list will be used
	//everyMinute	: "0 * * * * ?"
	//every5Minutes : "0 */5 * * * ?"
   	//everyHour   : "0 0 * * * ?"
   	//everyDay    : "0 0 0 * * ?"
   	default = everyChange

 * Each line in this section defines for which item(s) which strategy(ies) should be applied.
 * You can list single items, use "*" for all items or "groupitem*" for all members of a group
 * item (excl. the group item itself).

//Items {
    // persist all items once a day and on every change and restore them from the db at startup
    //* : strategy = everyChange, everyDay, restoreOnStartup
    //* : strategy = everyChange, everyDay

    // additionally, persist all temperature and weather values every hour
    //   gTemperatur* : strategy = every5Minutes, restoreOnStartup
  • Errors:
    Error: Could not get valid data from REST API
    at Request.request [as _callback] (/root/.vscode/extensions/openhab.openhab-0.5.1/serverJS/src/ItemCompletion/ItemCompletionProvider.js:168:18)
    at Request.self.callback (/root/.vscode/extensions/openhab.openhab-0.5.1/serverJS/node_modules/request/request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request. (/root/.vscode/extensions/openhab.openhab-0.5.1/serverJS/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:182:13)
    at IncomingMessage. (/root/.vscode/extensions/openhab.openhab-0.5.1/serverJS/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:273:13)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1090:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Are you sure about the IP? seems your MySQL Database machine has a public ip address, which is fine, but at least unconventional in question of openHAB installations.

Did you change anything other than url, user and password in mysql.cfg? If yes, please consider to change it back to ensure the binding is working with default values.
Maybe switch to jdbc persistence, which is the newer persistence service.

You’ve disabled all items in mysql.persist, so there will be no persistence at all. To log all changes, the mysql.persist file should look like this:

Strategies {
	everyMinute	: "0 * * * * ?"
   	default = everyChange

Items {
    // persist all items on every change
    * : strategy = everyChange

You could shorten this file to

Strategies {
   	default = everyChange
Items {

So as the default strategy is everyChange, this should suffice to persist every change, but the former file is more clear :wink: