diff --git a/fhem/CHANGED b/fhem/CHANGED
index 5ea1e9e6b..b958deb38 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,7 @@
# 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.
+ - feature: 93_DbLog: new attr DbLogValueFn propagated as device specific
+ attribute if DbLog is used
- bugfix: 70_ZoneMinder: json parsing - again
- bugfix: 89_FULLY: Support for Fully version 1.33
- feature: 22_HOMEMODE: v1.4.10 add support for PET
diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm
index 32d45d87a..ecaadff5b 100644
--- a/fhem/FHEM/93_DbLog.pm
+++ b/fhem/FHEM/93_DbLog.pm
@@ -5,12 +5,13 @@
# written by Dr. Boris Neubert 2007-12-30
# e-mail: omega at online dot de
#
-# modified and maintained by Tobias Faust since 2012-06-26
+# modified and maintained by Tobias Faust since 2012-06-26 until 2016
# e-mail: tobias dot faust at online dot de
#
-# reduceLog() created by Claudiu Schuster (rapster)
+# redesigned and maintained 2016-2019 by DS_Starter with credits by: JoeAllb, DeeSpe
+# e-mail: heiko dot maaz at t-online dot de
#
-# redesigned 2016-2019 by DS_Starter with credits by: JoeAllb, DeeSpe
+# reduceLog() created by Claudiu Schuster (rapster)
#
############################################################################################################################################
@@ -28,7 +29,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern by DS_Starter:
our %DbLog_vNotesIntern = (
- "4.1.1" => "25.05.2019 fix ignore MinInterval if value is \"0\", Forum: #100344",
+ "4.2.0" => "25.07.2019 DbLogValueFn as device specific function propagated in devices if dblog is used ",
+ "4.1.1" => "25.05.2019 fix ignore MinInterval if value is \"0\", Forum: #100344 ",
"4.1.0" => "17.04.2019 DbLog_Get: change reconnect for MySQL (Forum: #99719), change index suggestion in DbLog_configcheck ",
"4.0.0" => "14.04.2019 rewrite DbLog_PushAsync / DbLog_Push / DbLog_Connectxx, new attribute \"bulkInsert\" ",
"3.14.1" => "12.04.2019 DbLog_Get: change select of MySQL Forum: https://forum.fhem.de/index.php/topic,99280.0.html ",
@@ -260,6 +262,7 @@ sub DbLog_Initialize($)
addToAttrList("DbLogInclude");
addToAttrList("DbLogExclude");
+ addToAttrList("DbLogValueFn:textField-long");
$hash->{FW_detailFn} = "DbLog_fhemwebFn";
$hash->{SVG_sampleDataFn} = "DbLog_sampleDataFn";
@@ -1229,7 +1232,6 @@ sub DbLog_Log($$) {
last;
}
}
- # Log3 $name, 5, "DbLog $name -> verbose 4 output of device $dev_name skipped due to attribute \"verbose4Devs\" restrictions" if(!$vb4show);
}
if($vb4show && !$hash->{HELPER}{".RUNNING_PID"}) {
@@ -1246,9 +1248,17 @@ sub DbLog_Log($$) {
my $now = gettimeofday(); # get timestamp in seconds since epoch
my $DbLogExclude = AttrVal($dev_name, "DbLogExclude", undef);
my $DbLogInclude = AttrVal($dev_name, "DbLogInclude",undef);
+ my $DbLogValueFn = AttrVal($dev_name, "DbLogValueFn","");
my $DbLogSelectionMode = AttrVal($name, "DbLogSelectionMode","Exclude");
my $value_fn = AttrVal( $name, "valueFn", "" );
+ # Funktion aus Device spezifischer DbLogValueFn validieren
+ if( $DbLogValueFn =~ m/^\s*(\{.*\})\s*$/s ) {
+ $DbLogValueFn = $1;
+ } else {
+ $DbLogValueFn = '';
+ }
+
# Funktion aus Attr valueFn validieren
if( $value_fn =~ m/^\s*(\{.*\})\s*$/s ) {
$value_fn = $1;
@@ -1375,8 +1385,34 @@ sub DbLog_Log($$) {
if ($DoIt) {
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME} = $now;
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE} = $value;
+
+ # Device spezifische DbLogValueFn-Funktion anwenden
+ if($DbLogValueFn ne '') {
+ my $TIMESTAMP = $timestamp;
+ my $EVENT = $event;
+ my $READING = $reading;
+ my $VALUE = $value;
+ my $UNIT = $unit;
+ my $IGNORE = 0;
+ my $CN = " ";
+
+ eval $DbLogValueFn;
+ Log3 $name, 2, "DbLog $name -> error device \"$dev_name\" specific DbLogValueFn: ".$@ if($@);
+
+ if($IGNORE) {
+ # aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $DbLogValueFn
+ Log3 $hash->{NAME}, 4, "DbLog $name -> Event ignored by device \"$dev_name\" specific DbLogValueFn - TS: $timestamp, Device: $dev_name, Type: $dev_type, Event: $event, Reading: $reading, Value: $value, Unit: $unit"
+ if($vb4show && !$hash->{HELPER}{".RUNNING_PID"});
+ next;
+ }
+
+ $timestamp = $TIMESTAMP if($TIMESTAMP =~ /(19[0-9][0-9]|2[0-9][0-9][0-9])-(0[1-9]|1[1-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1]) (0[0-9]|1[1-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/);
+ $reading = $READING if($READING ne '');
+ $value = $VALUE if(defined $VALUE);
+ $unit = $UNIT if(defined $UNIT);
+ }
- # Anwender kann Feldwerte mit Funktion aus Attr valueFn verändern oder Datensatz-Log überspringen
+ # zentrale valueFn im DbLog-Device abarbeiten
if($value_fn ne '') {
my $TIMESTAMP = $timestamp;
my $DEVICE = $dev_name;
@@ -1390,6 +1426,7 @@ sub DbLog_Log($$) {
eval $value_fn;
Log3 $name, 2, "DbLog $name -> error valueFn: ".$@ if($@);
+
if($IGNORE) {
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $value_fn
Log3 $hash->{NAME}, 4, "DbLog $name -> Event ignored by valueFn - TS: $timestamp, Device: $dev_name, Type: $dev_type, Event: $event, Reading: $reading, Value: $value, Unit: $unit"
@@ -5730,7 +5767,15 @@ return;
Preparations
- At first you need to setup the database.
+ At first you need to install and setup the database.
+ The installation of database system itself is not described here, please refer to the installation instructions of your
+ database.
+
+ Note:
+ In case of fresh installed MySQL/MariaDB system don't forget deleting the anonymous "Everyone"-User with an admin-tool if
+ existing !
+
+
Sample code and Scripts to prepare a MySQL/PostgreSQL/SQLite database you can find in
SVN -> contrib/dblog/db_create_<DBType>.sql.
(Caution: The local FHEM-Installation subdirectory ./contrib/dblog doesn't contain the freshest scripts !!)
@@ -6541,7 +6586,7 @@ return;
attr <device> DbLogExclude regex:MinInterval,[regex:MinInterval] ...
- A new Attribute DbLogExclude will be propagated to all devices if DBLog is used.
+ A new attribute DbLogExclude will be propagated to all devices if DBLog is used.
DbLogExclude will work as regexp to exclude defined readings to log. Each individual regexp-group are separated by
comma.
If a MinInterval is set, the logentry is dropped if the defined interval is not reached and the value vs.
@@ -6556,6 +6601,41 @@ return;
+
+ attr <device> DbLogValueFn {}
+
+attr SMA_Energymeter DbLogValueFn +{ + if ($READING eq "Bezug_WirkP_Kosten_Diff"){ + $UNIT="Diff-W"; + } + if ($READING =~ /Einspeisung_Wirkleistung_Zaehler/ && $VALUE < 2){ + $IGNORE=1; +} ++
+ attr <device> DbLogValueFn {}
+
+attr SMA_Energymeter DbLogValueFn +{ + if ($READING eq "Bezug_WirkP_Kosten_Diff"){ + $UNIT="Diff-W"; + } + if ($READING =~ /Einspeisung_Wirkleistung_Zaehler/ && $VALUE < 2){ + $IGNORE=1; +} ++