diff --git a/fhem/CHANGED b/fhem/CHANGED
index aca0f2ad4..acd565cfc 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - change: 93_DbLog: V2.22.6 commandref revised
- new: 73_UpsPico: New module for UpsPico UPS from pimodules
- feature: LightScene: added traversalOrder attribute
- bugfix: 31_PLAYBULB: fix battery character value
diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm
index b4e261d6d..ecb0e6ba1 100644
--- a/fhem/FHEM/93_DbLog.pm
+++ b/fhem/FHEM/93_DbLog.pm
@@ -16,6 +16,7 @@
############################################################################################################################################
# Versions History done by DS_Starter & DeeSPe:
#
+# 2.22.6 22.09.2017 commandref revised
# 2.22.5 05.09.2017 fix Internal MODE isn't set correctly after DEF is edited, nextsynch is not renewed if reopen is
# set manually after reopen was set with a delay Forum:#76213, Link to 98_FileLogConvert.pm added
# 2.22.4 27.08.2017 fhem chrashes if database DBD driver is not installed (Forum:#75894)
@@ -149,7 +150,7 @@ use Blocking;
use Time::HiRes qw(gettimeofday tv_interval);
use Encode qw(encode_utf8);
-my $DbLogVersion = "2.22.5";
+my $DbLogVersion = "2.22.6";
my %columns = ("DEVICE" => 64,
"TYPE" => 64,
@@ -4457,22 +4458,79 @@ sub checkUsePK ($$){
DbLog
-
-
- Define
-
- define <name> DbLog <configfilename> <regexp>
+ With DbLog events can be stored in a database. SQLite, MySQL/MariaDB and PostgreSQL are supported databases.
+
+ Prereqisites
+
+ The Perl-modules DBI
and DBD::<dbtype>
are needed to be installed (use cpan -i <module>
+ if your distribution does not have it).
-
- Log events to a database. The database connection is defined in
- <configfilename>
- In contrib/dblog
an example configuration and scripts to create needed tables in the
- different databases are provided.
+ On a debian based system you may install these modules for instance by:
+
+
+
+
+ DBI | : sudo apt-get install libdbi-perl |
+ MySQL | : sudo apt-get install [mysql-server] mysql-client libdbd-mysql libdbd-mysql-perl (mysql-server only if you use a local MySQL-server installation) |
+ SQLite | : sudo apt-get install sqlite3 libdbi-perl libdbd-sqlite3-perl |
+ PostgreSQL | : sudo apt-get install libdbd-pg-perl |
+
+
+
+
+
+ Preparations
+
+ At first you need to setup the database.
+ Sample code and Scripts to prepare a MySQL/PostgreSQL/SQLite database you can find in contrib/dblog/<DBType>_create.sql
.
+ The database contains two tables: current
and history
.
+ The latter contains all events whereas the former only contains the last event for any given reading and device.
+ (see also attribute DbLogType)
+
+
+ The columns have the following meaning::
+
+
+
+
+ TIMESTAMP: | : timestamp of event, e.g. 2007-12-30 21:45:22 |
+ DEVICE: | : device name, e.g. Wetterstation |
+ TYPE: | : device type, e.g. KS300 |
+ EVENT: | : event specification as full string, e.g. humidity: 71 (%) |
+ READING: | : name of reading extracted from event, e.g. humidity |
+ VALUE: | : actual reading extracted from event, e.g. 71 |
+ UNIT: | : unit extracted from event, e.g. % |
+
+
+
+
+
+ create index
+ Due to reading performance, e.g. on creation of SVG-plots, it is very important that the index "Search_Idx"
+ or a comparable index (e.g. a primary key) is applied. A sample code for creation of that index is also available at the mentioned scripts in
+ contrib/dblog/<DBType>_create.sql
.
+
+ The index "Search_Idx" can be created, e.g. in database 'fhem', by these statements (also subsequently):
+
+
+
+
+ MySQL | : CREATE INDEX Search_Idx ON `fhem`.`history` (DEVICE, READING, TIMESTAMP); |
+ SQLite | : CREATE INDEX Search_Idx ON `history` (DEVICE, READING, TIMESTAMP); |
+ PostgreSQL | : CREATE INDEX "Search_Idx" ON history USING btree (device, reading, "timestamp"); |
+
+
+
+
+ For the connection to the database a configuration file is used.
+ The configuration is stored in a separate file to avoid storing the password in the main configuration file and to have it
+ visible in the output of the list command.
+
+
+ The configuration file should be copied e.g. to /opt/fhem and has the following structure you have to customize
+ suitable to your conditions (decomment the appropriate raws and adjust it):
- The configuration file should be copied e.g. to /opt/fhem and has the following structure you have to customize
- suitable to your conditions (decomment the appropriate raws and adjust it):
-
####################################################################################
# database configuration file
@@ -4482,7 +4540,7 @@ sub checkUsePK ($$){
# and write 'user => ""' respectively 'password => ""' instead !
#
#
- ## for MySQL
+ ## for MySQL
####################################################################################
#%dbconfig= (
# connection => "mysql:database=fhem;host=db;port=3306",
@@ -4513,59 +4571,23 @@ sub checkUsePK ($$){
- The configuration is stored in a separate file
- to avoid storing the password in the main configuration file and to have it
- visible in the output of the list command.
-
-
- DbLog distinguishes between the synchronous (default) and asynchronous logmode. The logmode is adjustable by the
- attribute asyncMode. Since version 2.13.5 DbLog is supporting primary key (PK) set in table
- current or history. If you want use PostgreSQL with PK it has to be at lest version 9.5.
+
+
+ Define
+
+
+
+ define <name> DbLog <configfilename> <regexp>
- The modules DBI
and DBD::<dbtype>
- need to be installed (use cpan -i <module>
- if your distribution does not have it).
+ <configfilename>
is the prepared configuration file.
+ <regexp>
is identical to the specification of regex in the FileLog definition.
-
- <regexp>
is the same as in FileLog.
-
- Sample code to create a MySQL/PostgreSQL/SQLite database is in
- <DBType>_create.sql
.
- The database contains two tables: current
and
- history
. The latter contains all events whereas the former only
- contains the last event for any given reading and device. (see also attribute DbLogType)
-
- The columns have the following meaning:
-
-
- - TIMESTAMP: timestamp of event, e.g.
2007-12-30 21:45:22
- - DEVICE: device name, e.g.
Wetterstation
- - TYPE: device type, e.g.
KS300
- - EVENT: event specification as full string,
- e.g.
humidity: 71 (%)
- - READING: name of reading extracted from event,
- e.g.
humidity
-
- - VALUE: actual reading extracted from event,
- e.g.
71
- - UNIT: unit extracted from event, e.g.
%
-
-
-
- The content of VALUE is optimized for automated post-processing, e.g. yes
is translated to 1
-
-
- The current values can be retrieved by the following code like FileLog:
-
- get myDbLog - - 2012-11-10 2012-11-10 KS300:temperature::
-
-
Example:
- define myDbLog DbLog /etc/fhem/db.conf .*:.*
- # log everything to database
+ define myDbLog DbLog /etc/fhem/db.conf .*:.*
+ all events will stored into the database
@@ -4577,8 +4599,21 @@ sub checkUsePK ($$){
This check reports some important settings and gives recommendations back to you if proposals are indentified.
(Available for MySQL, PostgreSQL)
+
+ DbLog distinguishes between the synchronous (default) and asynchronous logmode. The logmode is adjustable by the
+ attribute asyncMode. Since version 2.13.5 DbLog is supporting primary key (PK) set in table
+ current or history. If you want use PostgreSQL with PK it has to be at lest version 9.5.
+
+
+ The content of VALUE will be optimized for automated post-processing, e.g. yes
is translated to 1
+
+
+ The stored values can be retrieved by the following code like FileLog:
+
+ get myDbLog - - 2012-11-10 2012-11-10 KS300:temperature::
+
+
-
transfer FileLog-data to DbLog
There is the special module 98_FileLogConvert.pm available to transfer filelog-data to the DbLog-database.
The module can be downloaded here
@@ -4587,7 +4622,9 @@ sub checkUsePK ($$){
Forumthread .
-
+
+
+
Set
@@ -5284,22 +5321,83 @@ sub checkUsePK ($$){
DbLog
-
-
- Define
-
- define <name> DbLog <configfilename> <regexp>
+ Mit DbLog werden Events in einer Datenbank gespeichert. Es wird SQLite, MySQL/MariaDB und PostgreSQL unterstützt.
+
+ Voraussetzungen
+
+ Die Perl-Module DBI
und DBD::<dbtype>
müssen installiert werden (use cpan -i <module>
+ falls die eigene Distribution diese nicht schon mitbringt).
-
- Speichert Events in eine Datenbank. Die Datenbankverbindungsparameter werden
- definiert in <configfilename>
.
- In contrib/dblog
sind eine Beispielkonfiguation und Scripts zum Anlegen der benötigten Tabellen
- der verschiedenen Datenbanktypen bereitgestellt.
+ Auf einem Debian-System können diese Module z.Bsp. installiert werden mit:
+
+
+
+
+ DBI | : sudo apt-get install libdbi-perl |
+ MySQL | : sudo apt-get install [mysql-server] mysql-client libdbd-mysql libdbd-mysql-perl (mysql-server nur bei lokaler MySQL-Server-Installation) |
+ SQLite | : sudo apt-get install sqlite3 libdbi-perl libdbd-sqlite3-perl |
+ PostgreSQL | : sudo apt-get install libdbd-pg-perl |
+
+
+
+
+
+ Vorbereitungen
+
+ Zunächst muss die Datenbank angelegt werden.
+ Beispielcode bzw. Scripts zum Erstellen einer MySQL/PostgreSQL/SQLite Datenbank ist in contrib/dblog/<DBType>_create.sql
+ enthalten.
+ Die Datenbank beinhaltet 2 Tabellen: current
und history
.
+ Die Tabelle current
enthält den letzten Stand pro Device und Reading.
+ In der Tabelle history
sind alle Events historisch gespeichert. (siehe auch Attribut DbLogType)
+
+
+ Die Tabellenspalten haben folgende Bedeutung:
+
+
+
+
+ TIMESTAMP: | : Zeitpunkt des Events, z.B. 2007-12-30 21:45:22 |
+ DEVICE: | : Name des Devices, z.B. Wetterstation |
+ TYPE: | : Type des Devices, z.B. KS300 |
+ EVENT: | : das auftretende Event als volle Zeichenkette, z.B. humidity: 71 (%) |
+ READING: | : Name des Readings, ermittelt aus dem Event, z.B. humidity |
+ VALUE: | : aktueller Wert des Readings, ermittelt aus dem Event, z.B. humidity |
+ UNIT: | : Einheit, ermittelt aus dem Event, z.B. % |
+
+
+
+
+
+ Index anlegen
+ Für die Leseperformance, z.B. bei der Erstellung von SVG-PLots, ist es von besonderer Bedeutung dass der Index "Search_Idx"
+ oder ein vergleichbarer Index (z.B. ein Primary Key) angelegt ist.
+
+ Der Index "Search_Idx" kann mit diesen Statements, z.B. in der Datenbank 'fhem', angelegt werden (auch nachträglich):
+
+
+
+
+ MySQL | : CREATE INDEX Search_Idx ON `fhem`.`history` (DEVICE, READING, TIMESTAMP); |
+ SQLite | : CREATE INDEX Search_Idx ON `history` (DEVICE, READING, TIMESTAMP); |
+ PostgreSQL | : CREATE INDEX "Search_Idx" ON history USING btree (device, reading, "timestamp"); |
+
+
+
+
+ Der Code zur Anlage ist ebenfalls mit in den Scripten in
+ contrib/dblog/<DBType>_create.sql
enthalten.
+
+ Für die Verbindung zur Datenbank wird eine Konfigurationsdatei verwendet.
+ Die Konfiguration ist in einer sparaten Datei abgelegt um das Datenbankpasswort nicht in Klartext in der
+ FHEM-Haupt-Konfigurationsdatei speichern zu müssen.
+ Ansonsten wäre es mittels des list Befehls einfach auslesbar.
+
+
+ Die Konfigurationsdatei wird z.B. nach /opt/fhem kopiert und hat folgenden Aufbau, den man an seine Umgebung
+ anpassen muß (entsprechende Zeilen entkommentieren und anpassen):
- Die Konfigurationsdatei wird z.B. nach /opt/fhem kopiert und hat folgenden Aufbau, den man an seine Umgebung
- anpassen muß (entsprechende Zeilen entkommentieren und anpassen):
-
####################################################################################
# database configuration file
@@ -5339,78 +5437,24 @@ sub checkUsePK ($$){
####################################################################################
-
- Die Konfiguration ist in einer sparaten Datei abgelegt um das Datenbankpasswort
- nicht in Klartext in der FHEM-Haupt-Konfigurationsdatei speichern zu müssen.
- Ansonsten wäre es mittels des list
- Befehls einfach auslesbar.
-
- DbLog unterscheidet den synchronen (Default) und asynchronen Logmodus. Der Logmodus ist über das
- Attribut asyncMode einstellbar. Ab Version 2.13.5 unterstützt DbLog einen gesetzten
- Primary Key (PK) in den Tabellen Current und History. Soll PostgreSQL mit PK genutzt werden, muss PostgreSQL mindestens
- Version 9.5 sein.
-
- Die Perl-Module DBI
und DBD::<dbtype>
- müssen installiert werden (use cpan -i <module>
- falls die eigene Distribution diese nicht schon mitbringt).
-
-
- Auf einem Debian-System können diese Module z.Bsp. installiert werden mit:
-
-
-
-
- DBI | : sudo apt-get install libdbi-perl |
- MySQL | : sudo apt-get install [mysql-server] mysql-client libdbd-mysql libdbd-mysql-perl (mysql-server nur bei lokaler MySQL-Server-Installation) |
- SQLite | : sudo apt-get install sqlite3 libdbi-perl libdbd-sqlite3-perl |
- PostgreSQL | : sudo apt-get install libdbd-pg-perl |
-
-
-
-
-
- <regexp>
ist identisch wie FileLog.
-
- Ein Beispielcode zum Erstellen einer MySQL/PostgreSQL/SQLite Datenbank ist in
- contrib/dblog/<DBType>_create.sql
zu finden.
- Die Datenbank beinhaltet 2 Tabellen: current
und
- history
. Die Tabelle current
enthält den letzten Stand
- pro Device und Reading. In der Tabelle history
sind alle
- Events historisch gespeichert. (siehe auch Attribut DbLogType)
-
- Die Tabellenspalten haben folgende Bedeutung:
-
-
- - TIMESTAMP: Zeitpunkt des Events, z.B.
2007-12-30 21:45:22
- - DEVICE: name des Devices, z.B.
Wetterstation
- - TYPE: Type des Devices, z.B.
KS300
- - EVENT: das auftretende Event als volle Zeichenkette
- z.B.
humidity: 71 (%)
- - READING: Name des Readings, ermittelt aus dem Event,
- z.B.
humidity
-
- - VALUE: aktueller Wert des Readings, ermittelt aus dem Event,
- z.B.
71
- - UNIT: Einheit, ermittelt aus dem Event, z.B.
%
-
-
-
- Der Wert des Readings ist optimiert für eine automatisierte Nachverarbeitung
- z.B. yes
ist transformiert nach 1
-
-
- Die gespeicherten Werte können mittels GET Funktion angezeigt werden:
-
- get myDbLog - - 2012-11-10 2012-11-10 KS300:temperature
-
+
+ Define
+
+ define <name> DbLog <configfilename> <regexp>
+
+
+ <configfilename>
ist die vorbereitete Konfigurationsdatei.
+ <regexp>
ist identisch FileLog der Filelog-Definition.
+
+
Beispiel:
define myDbLog DbLog /etc/fhem/db.conf .*:.*
- Speichert alles in der Datenbank
+ speichert alles in der Datenbank
@@ -5421,8 +5465,23 @@ sub checkUsePK ($$){
Dieser Check prüft einige wichtige Einstellungen des DbLog-Devices und gibt Empfehlungen für potentielle Verbesserungen.
(verfügbar für MySQL, PostgreSQL)
-
+
+ DbLog unterscheidet den synchronen (Default) und asynchronen Logmodus. Der Logmodus ist über das
+ Attribut asyncMode einstellbar. Ab Version 2.13.5 unterstützt DbLog einen gesetzten
+ Primary Key (PK) in den Tabellen Current und History. Soll PostgreSQL mit PK genutzt werden, muss PostgreSQL mindestens
+ Version 9.5 sein.
+
+
+ Der gespeicherte Wert des Readings wird optimiert für eine automatisierte Nachverarbeitung, z.B. yes
wird transformiert
+ nach 1
.
+
+ Die gespeicherten Werte können mittels GET Funktion angezeigt werden:
+
+ get myDbLog - - 2012-11-10 2012-11-10 KS300:temperature
+
+
+
FileLog-Dateien nach DbLog übertragen
Zur Übertragung von vorhandenen Filelog-Daten in die DbLog-Datenbank steht das spezielle Modul 98_FileLogConvert.pm
zur Verfügung.