-
Notifications
You must be signed in to change notification settings - Fork 0
JDBC Persistence
- Introduction
- Features
- Installing JDBC Persistence
- Configuring JDBC Persistence
- Database Table Schema
- Number Precision
- Rounding results
This service allows you to persist state updates using one of several different underlying database services.
The JDBC Persistence Service is designed for a maximum of scalability. It is designed to store very large amounts of data, and still over the years not lose its speed.
The generic design makes it relatively easy for developers to integrate other databases that have JDBC drivers.
It can act as a replacement for the MySQL-Persistence bundle (with additional configuration in openhab.cfg
).
Currently the following databases are supported and tested:
General:
- Writing/reading information to relational database systems.
- Database Table Name Schema can be reconfigured after creation.
- JDBC drivers are not contained within the bundle and must be downloaded and added separately to your
${openhab.home}/addons
directory.
For Developers:
- Clearly separated source files for the database-specific part of openHAB logic.
- Code duplication by similar services is prevented.
- Integrating a new SQL and JDBC enabled database is fairly simple.
- For installation of this persistence bundle, please follow the same steps as if you would install a binding.
- Copy the database-specific driver JAR file (see below) to your
${openhab.home}/addons
directory. - Place a persistence file called
jdbc.persist
into the${openhab.home}/configuration/persistence
folder. This has the standard format as described in Persistence. - In
openhab.cfg
changepersistence:default
parameter tojdbc
:
persistence:default=jdbc
If you are migrating from the MySQL persistence bundle to the JDBC persistence bundle, follow these steps:
- For installation of this persistence bundle, please follow the same steps as if you would install a binding.
- Copy the database-specific driver JAR file (see below) to your
${openhab.home}/addons
directory. - Remove the MySQL persistence bundle from your
${openhab.home}/addons
directory. - In your
${openhab.home}/configurations/persistence
directory, rename yourmysql.persist
file tojdbc.persist
. - In your
openhab.cfg
file, add or change these configuration items:
persistence:default=jdbc
jdbc:tableNamePrefix=Item
jdbc:tableUseRealItemNames=false
jdbc:tableIdDigitCount=0
Database | Tested File | Repository |
---|---|---|
Derby | derby-10.11.1.1.jar | Maven |
H2 | h2-1.4.189.jar | Maven |
HSQLDB | hsqldb-2.3.3.jar | Maven |
MariaDB | mariadb-java-client-1.2.0.jar | Maven |
MySQL | mysql-connector-java-5.1.36.jar | Maven |
PostgreSQL | postgresql-9.4-1201-jdbc41.jar | Maven |
SQLite | sqlite-jdbc-3.8.11.1.jar | Maven |
You can configure the persistence service in JDBC Persistence Service section in openhab.cfg
.
############################ JDBC Persistence Service ##################################
#
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
jdbc:url=jdbc:postgresql://192.168.0.1:5432/testPostgresql
#
# required database user
jdbc:user=test
#
# required database password
jdbc:password=test
#
############################ JDBC Persistence Service ##################################
#
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
jdbc:url=jdbc:postgresql://192.168.0.1:5432/testPostgresql
#
# required database user
jdbc:user=test
#
# required database password
jdbc:password=test
#
# for Migration from MYSQL-Bundle set to 'Item'.
jdbc:tableNamePrefix=Item
#
# for Migration from MYSQL-Bundle do not use real names.
jdbc:tableUseRealItemNames=false
#
# for Migration from MYSQL-Bundle set to 0.
jdbc:tableIdDigitCount=0
############################ JDBC Persistence Service ##################################
# I N S T A L L J D B C P E R S I S T E N C E S E R V I C E
# To use this JDBC-service-bundle (org.openhab.persistence.jdbc-X.X.X.jar),
# a appropriate JDBC database-driver is needed in OpenHab addons Folder.
# Copy both (JDBC-service-bundle and a JDBC database-driver) to your OpenHab '[OpenHab]/addons' Folder to make it work.
#
# Driver jars:
# Derby: derby-10.11.1.1.jar http://mvnrepository.com/artifact/org.apache.derby/derby
# H2: h2-1.4.189.jar http://mvnrepository.com/artifact/com.h2database/h2
# HSQLDB: hsqldb-2.3.3.jar http://mvnrepository.com/artifact/org.hsqldb/hsqldb
# MariaDB: mariadb-java-client-1.2.0.jar http://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
# MySQL mysql-connector-java-5.1.36.jar http://mvnrepository.com/artifact/mysql/mysql-connector-java
# PostgreSQL:postgresql-9.4-1201-jdbc41.jar http://mvnrepository.com/artifact/org.postgresql/postgresql
# SQLite: sqlite-jdbc-3.8.11.1.jar http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
#
# Tested databases/url-prefix: jdbc:derby, jdbc:h2, jdbc:hsqldb, jdbc:mariadb, jdbc:mysql, jdbc:postgresql, jdbc:sqlite
#
# derby, h2, hsqldb, sqlite can be embedded,
# If no database is available it will be created, for example the url 'jdbc:h2:./testH2' creates a new DB in OpenHab Folder.
#
# Create new database, for example on a MySQL-Server use:
# CREATE DATABASE 'yourDB' CHARACTER SET utf8 COLLATE utf8_general_ci;
# D A T A B A S E C O N F I G
# Some URL-Examples, 'service' identifies and activates internally the correct jdbc driver.
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
# jdbc:url=jdbc:derby:./testDerby;create=true
# jdbc:url=jdbc:h2:./testH2
# jdbc:url=jdbc:hsqldb:./testHsqlDb
# jdbc:url=jdbc:mariadb://192.168.0.1:3306/testMariadb
# jdbc:url=jdbc:mysql://192.168.0.1:3306/testMysql
# jdbc:url=jdbc:postgresql://192.168.0.1:5432/testPostgresql
# jdbc:url=jdbc:sqlite:./testSqlite.db
# required database user
#jdbc:user=
jdbc:user=test
# required database password
#jdbc:password=
jdbc:password=test
# E R R O R H A N D L I N G
# optional when Service is deactivated (optional, default: 0 -> ignore)
#jdbc:errReconnectThreshold=
# I T E M O P E R A T I O N S
# optional tweaking SQL datatypes
# see: https://mybatis.github.io/mybatis-3/apidocs/reference/org/apache/ibatis/type/JdbcType.html
# see: http://www.h2database.com/html/datatypes.html
# see: http://www.postgresql.org/docs/9.3/static/datatype.html
# defaults:
#jdbc:sqltype.CALL = VARCHAR(200)
#jdbc:sqltype.COLOR = VARCHAR(70)
#jdbc:sqltype.CONTACT = VARCHAR(6)
#jdbc:sqltype.DATETIME = DATETIME
#jdbc:sqltype.DIMMER = TINYINT
#jdbc:sqltype.LOCATION = VARCHAR(30)
#jdbc:sqltype.NUMBER = DOUBLE
#jdbc:sqltype.ROLLERSHUTTER = TINYINT
#jdbc:sqltype.STRING = VARCHAR(65500)
#jdbc:sqltype.SWITCH = VARCHAR(6)
# For Itemtype "Number" default decimal digit count (optional, default: 3)
#jdbc:numberDecimalcount=
# T A B L E O P E R A T I O N S
# Tablename Prefix String (optional, default: "item")
# for Migration from MYSQL-Bundle set to 'Item'.
#jdbc:tableNamePrefix=Item
# Tablename Prefix generation, using Item real names or "item" (optional, default: false -> "item")
# If true, 'tableNamePrefix' is ignored.
#jdbc:tableUseRealItemNames=
jdbc:tableUseRealItemNames=true
# Tablename Suffix length (optional, default: 4 -> 0001-9999)
# for Migration from MYSQL-Bundle set to 0.
#jdbc:tableIdDigitCount=
# Rename existing Tables using tableUseRealItemNames and tableIdDigitCount (optional, default: false)
# USE WITH CARE! Deactivate after Renaming is done!
#jdbc:rebuildTableNames=true
# D A T A B A S E C O N N E C T I O N S
# Some embeded Databases can handle only one Connection (optional, default: configured per database in packet org.openhab.persistence.jdbc.db.* )
# see: https://github.com/brettwooldridge/HikariCP/issues/256
# jdbc.maximumPoolSize = 1
# jdbc.minimumIdle = 1
# T I M E K E E P I N G
# (optional, default: false)
#jdbc:enableLogTime=true
The service will create a mapping table to link each item to a table, and a separate table is generated for each item.
The item data tables include time and data values. The SQL data type used depends on the openHAB item type, and allows the item state to be recovered back into openHAB in the same way it was stored.
With this per-item layout, the scalability and easy maintenance of the database is ensured, even if large amounts of data must be managed. To rename existing tables, use the parameters jdbc:tableUseRealItemNames
and jdbc:tableIdDigitCount
in the JDBC Persistence Service section of openhab.cfg
.
Default openHab number items are persisted with sql datatype double
. Internally openHab uses BigDecimal
. If better numerical precision is needed, for example set jdbc:sqltype.NUMBER = DECIMAL(max digits, max decimals)
in the JDBC Persistence Service section of openhab.cfg
, then on java side the service works with BigDecimal
without type conversion. If more come decimals as max decimals
provides, this persisted value is rounded mathematically correct. The sql types DECIMAL
or NUMERIC
are precise, but to work with DOUBLE
is faster.
The results of database queries of number items are rounded to three decimal places by default. With jdbc:numberDecimalcount
in the JDBC Persistence Service section of openhab.cfg
decimals can be changed. Especially if sql types DECIMAL
or NUMERIC
are used for jdbc:sqltype.NUMBER
, rounding can be disabled by setting jdbc:numberDecimalcount=-1
.
###Linux / OS X
###Windows
- Cosm Persistence
- db4o Persistence
- Exec Persistence
- InfluxDB Persistence
- JDBC Persistence
- JPA Persistence
- Logging Persistence
- mapdb Persistence
- MongoDB Persistence
- MQTT Persistence
- my.openHAB Persistence
- MySQL Persistence
- rrd4j Persistence
- Sen.Se Persistence
- SiteWhere Persistence
- AlarmDecoder Binding
- Anel Binding
- Arduino SmartHome Souliss Binding
- Asterisk Binding
- Astro Binding
- Autelis Pool Control Binding
- BenQ Projector Binding
- Bluetooth Binding
- Bticino Binding
- CalDAV Binding
- Comfo Air Binding
- Config Admin Binding
- CUL Binding
- CUL Intertechno Binding
- CUPS Binding
- DAIKIN Binding
- Davis Binding
- Denon Binding
- digitalSTROM Binding
- DMX512 Binding
- DSC Alarm Binding
- DSMR Binding
- eBUS Binding
- Ecobee Binding
- EDS OWSever Binding
- eKey Binding
- Energenie Binding
- EnOcean Binding
- Enphase Energy Binding
- Epson Projector Binding
- Exec Binding
- Freebox Binding
- Freeswitch Binding
- Frontier Silicon Radio Binding
- Fritz AHA Binding
- Fritz!Box Binding
- FS20 Binding
- Global Cache IR Binding
- GPIO Binding
- HAI/Leviton OmniLink Binding
- HDAnywhere Binding
- Heatmiser Binding
- Homematic / Homegear Binding
- HTTP Binding
- IEC 62056-21 Binding
- IHC / ELKO Binding
- ImperiHome Binding
- Insteon Hub Binding
- Insteon PLM Binding
- IPX800 Binding
- IRtrans Binding
- jointSPACE-Binding
- KNX Binding
- Koubachi Binding
- LCN Binding
- LightwaveRF Binding
- Leviton/HAI Omnilink Binding
- Lg TV Binding
- Logitech Harmony Hub
- MailControl Binding
- MAX!Cube-Binding
- MAX! CUL Binding
- MiLight Binding
- MiOS Binding
- Modbus TCP Binding
- MPD Binding
- MQTT Binding
- MQTTitude binding
- Neohub Binding
- Nest Binding
- Netatmo Binding
- Network Health Binding
- Network UPS Tools Binding
- Nibe Heatpump Binding
- Nikobus Binding
- Novelan/Luxtronic Heatpump Binding
- NTP Binding
- One-Wire Binding
- Onkyo AV Receiver Binding
- Open Energy Monitor Binding
- OpenPaths presence detection binding
- OpenSprinkler Binding
- OSGi Configuration Admin Binding
- Panasonic TV Bindung
- panStamp Binding
- Philips Hue Binding
- Piface Binding
- pilight Binding
- Pioneer-AVR-Binding
- Plex Binding
- Plugwise Binding
- PLCBus Binding
- Primare Binding
- Pulseaudio Binding
- RFXCOM Binding
- RWE Smarthome Binding
- Sager WeatherCaster Binding
- Samsung AC Binding
- Samsung TV Binding
- Serial Binding
- Sallegra Binding
- Satel Alarm Binding
- Sinthesi Sapp Binding
- Snmp Binding
- Somfy URTSI II Binding
- Sonos Binding
- Squeezebox Binding
- Swegon ventilation Binding
- System Info Binding
- TA CMI Binding
- TCP/UDP Binding
- Tellstick Binding
- TinkerForge Binding
- Tivo Binding
- VDR Binding
- Velleman-K8055-Binding
- Wago Binding
- Wake-on-LAN Binding
- Waterkotte EcoTouch Heatpump Binding
- Weather Binding
- Wemo Binding
- Withings Binding
- XBMC Binding
- xPL Binding
- Yamahareceiver Binding
- Zibase Binding
- Z-Wave Binding
- Asterisk
- Google Calendar
- Linux Media Players
- ROS Robot Operating System
- Telldus Tellstick
- Zoneminder
- Wink Hub (rooted)
- Wink Monitoring
- Transformations
- XSLT
- JSON
- REST-API
- Security
- Service Discovery
- Voice Control
- BritishGasHive-Using-Ruby
- Dropbox Bundle
A good source of inspiration and tips from users gathered over the years. Be aware that things may have changed since they were written and some examples might not work correctly.
Please update the wiki if you do come across any out of date information.
- Comfo Air Binding
- Ecobee Examples
- Nest Examples
- Rollershutter Bindings
- Squeezebox
- WAC Binding
- WebSolarLog
- Alarm Clock
- Convert Farenheit to Celcius
- The mother of all lighting rules
- Reusable Rules via Functions
- Combining different Items
- Items, Rules and more Examples of a SmartHome
- Google Map
- Controlling openHAB with Android
- Usecase examples
- B-Control Manager
- Spell checking for foreign languages
- Flic via Tasker
- Chromecast via castnow