mit $name,$reading,$value
+####################################################################################################
+sub userexit ($$$) {
+ my ($name,$reading,$value) = @_;
+ my $hash = $defs{$name};
+
+ return if(!$hash->{HELPER}{USEREXITFN});
+
+ if(!defined($reading)) {$reading = "";}
+ if(!defined($value)) {$value = "";}
+ $value =~ s/\\/\\\\/g; # escapen of chars for evaluation
+ $value =~ s/'/\\'/g;
+
+ my $re = $hash->{HELPER}{UEFN_REGEXP}?$hash->{HELPER}{UEFN_REGEXP}:".*:.*";
+
+ if("$reading:$value" =~ m/^$re$/ ) {
+ my @res;
+ my $cmd = $hash->{HELPER}{USEREXITFN}."('$name','$reading','$value')";
+ $cmd = "{".$cmd."}";
+ my $r = AnalyzeCommandChain(undef, $cmd);
+ }
+return;
}
####################################################################################################
@@ -3877,7 +4197,7 @@ my $name = $hash->{NAME};
if ( !DbRep_Connect($hash) ) {
Log3 ($name, 2, "DbRep $name - DB connect failed. Database down ? ");
- readingsSingleUpdate($hash, "state", "disconnected", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "disconnected", 1);
return;
} else {
my $dbh = $hash->{DBH};
@@ -3945,12 +4265,18 @@ return;
import of datasets from file (CSV-Format).
rename of device names in datasets
automatic rename of device names in datasets and other DbRep-definitions after FHEM "rename" command (see DbRep-Agent)
+ Execution of arbitrary user specific SQL-commands
To activate the function "Autorename" the attribute "role" has to be assigned to a defined DbRep-device. The standard role after DbRep definition is "Client.
Please read more in section DbRep-Agent .
+ DbRep provides a UserExit function. By that interface the user can execute own program code dependent from free
+ definable Reading/Value-combinations (Regex). The interface works without respectively independent from event
+ generation.
+ Further informations you can find as described at attribute "userExitFn".
+
FHEM-Forum:
Modul 93_DbRep - Reporting and Management of database content (DbLog).
@@ -3959,7 +4285,7 @@ return;
Preparations
The module requires the usage of a DbLog instance and the credentials of the database definition will be used. (currently tested with MySQL and SQLite).
- Only the content of table "history" will be included.
+ Only the content of table "history" will be included (except command "sqlCmd").
Overview which other Perl-modules DbRep is using:
@@ -4007,7 +4333,20 @@ return;
countEntries - provides the number of DB-entries between period given by timestamp-attributes which are set.
If timestamp-attributes are not set, all entries in db will be count. The attributes "device" and "reading" can be used to limit the evaluation.
-
+
+ delEntries - deletes all database entries or only the database entries specified by attributes Device and/or
+ Reading and the entered time period between "timestamp_begin", "timestamp_end" (if set) or "timeDiffToNow/timeOlderThan".
+
+
+ "timestamp_begin" is set: deletes db entries from this timestamp until current date/time
+ "timestamp_end" is set : deletes db entries until this timestamp
+ both Timestamps are set : deletes db entries between these timestamps
+
+ Due to security reasons the attribute "allowDeletion" needs to be set to unlock the delete-function.
+
+
+
+
deviceRename - renames the device name of a device inside the connected database (Internal DATABASE).
The devicename will allways be changed in the entire database. Possibly set time limits or restrictions by
attributes device and/or reading will not be considered.
@@ -4020,20 +4359,30 @@ return;
-
- readingRename - renames the reading name of a device inside the connected database (see Internal DATABASE).
- The readingname will allways be changed in the entire database. Possibly set time limits or restrictions by
- attributes device and/or reading will not be considered.
-
-
- input format: set <name> readingRename <old reading name>,<new reading name>
- # The amount of renamed reading names (datasets) will be displayed in reading "reading_renamed".
- # If the reading name to be renamed was not found in the database, a WARNUNG will appear in reading "reading_not_renamed".
- # Appropriate entries will be written to Logfile if verbose >= 3 is set.
-
-
-
+ diffValue - calculates the defference of the readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow / timeOlderThan".
+ The reading to evaluate must be defined using attribute "reading".
+ This function is mostly reasonable if readingvalues are increasing permanently and don't write value-differences to the database.
+ The difference will be generated from the first available dataset (VALUE-Field) to the last available dataset between the
+ specified time linits/aggregation, in which a balanced difference value of the previous aggregation period will be transfered to the
+ following aggregation period in case this period contains a value.
+ An possible counter overrun (restart with value "0") will be considered (compare attribute "diffAccept").
+
+ If only one dataset will be found within the evalution period, the difference can be calculated only in combination with the balanced
+ difference of the previous aggregation period. In this case a logical inaccuracy according the assignment of the difference to the particular aggregation period
+ can be possible. Hence in warning in "state" will be placed and the reading "less_data_in_period" with a list of periods
+ with only one dataset found in it will be created.
+
+
+
+ Note:
+ Within the evaluation respectively aggregation period (day, week, month, etc.) you should make available at least one dataset
+ at the beginning and one dataset at the end of each aggregation period to take the difference calculation as much as possible.
+
+
+
+
+
exportToFile - exports DB-entries to a file in CSV-format between period given by timestamp.
Limitations of selections can be set by attributes Device and/or Reading.
The filename will be defined by attribute "expimpfile" .
@@ -4074,8 +4423,6 @@ return;
- sumValue - calculates the amount of readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow / timeOlderThan". The reading to evaluate must be defined using attribute "reading". Using this function is mostly reasonable if value-differences of readings are written to the database.
-
maxValue - calculates the maximum value of readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow / timeOlderThan".
The reading to evaluate must be defined using attribute "reading".
The evaluation contains the timestamp of the last appearing of the identified maximum value within the given period.
@@ -4083,48 +4430,69 @@ return;
minValue - calculates the miniimum value of readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow / timeOlderThan".
The reading to evaluate must be defined using attribute "reading".
The evaluation contains the timestamp of the first appearing of the identified minimum value within the given period.
-
- diffValue - calculates the defference of the readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow / timeOlderThan".
- The reading to evaluate must be defined using attribute "reading".
- This function is mostly reasonable if readingvalues are increasing permanently and don't write value-differences to the database.
- The difference will be generated from the first available dataset (VALUE-Field) to the last available dataset between the
- specified time linits/aggregation, in which a balanced difference value of the previous aggregation period will be transfered to the
- following aggregation period in case this period contains a value.
- An possible counter overrun (restart with value "0") will be considered (compare attribute "diffAccept").
- If only one dataset will be found within the evalution period, the difference can be calculated only in combination with the balanced
- difference of the previous aggregation period. In this case a logical inaccuracy according the assignment of the difference to the particular aggregation period
- can be possible. Hence in warning in "state" will be placed and the reading "less_data_in_period" with a list of periods
- with only one dataset found in it will be created.
-
-
- no difference can be calculated
- and the reading "less_data_in_period" with a list of concerned periods will be generated in that case.
-
-
- Note:
- Within the evaluation respectively aggregation period (day, week, month, etc.) you should make available at least one dataset
- at the beginning and one dataset at the end of each aggregation period to take the difference calculation as much as possible.
-
-
-
-
-
- delEntries - deletes all database entries or only the database entries specified by attributes Device and/or
- Reading and the entered time period between "timestamp_begin", "timestamp_end" (if set) or "timeDiffToNow/timeOlderThan".
+
+ readingRename - renames the reading name of a device inside the connected database (see Internal DATABASE).
+ The readingname will allways be changed in the entire database. Possibly set time limits or restrictions by
+ attributes device and/or reading will not be considered.
- "timestamp_begin" is set: deletes db entries from this timestamp until current date/time
- "timestamp_end" is set : deletes db entries until this timestamp
- both Timestamps are set : deletes db entries between these timestamps
-
- Due to security reasons the attribute "allowDeletion" needs to be set to unlock the delete-function.
-
+ input format: set <name> readingRename <old reading name>,<new reading name>
+ # The amount of renamed reading names (datasets) will be displayed in reading "reading_renamed".
+ # If the reading name to be renamed was not found in the database, a WARNUNG will appear in reading "reading_not_renamed".
+ # Appropriate entries will be written to Logfile if verbose >= 3 is set.
+
+
+
+
+ sqlCmd - executes an arbitrary user specific command.
+ If the command contains a operation to delete data, the attribute
+ "allowDeletion" has to be set for security reason.
+ The statement doesn't consider limitations by attributes device and/or reading.
+ If the attributes "timestamp_begin" respectively "timestamp_end"
+ should assumed in the statement, you can use the placeholder "§timestamp_begin§" respectively
+ "§timestamp_end§" on suitable place.
+
+
+ Examples of SQL-statements:
+
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= "2017-01-06 00:00:00" group by DEVICE having count(*) > 800
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= "2017-05-06 00:00:00" group by DEVICE
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= §timestamp_begin§ group by DEVICE
+ - set <name> sqlCmd select * from history where DEVICE like "Te%t" order by `TIMESTAMP` desc
+ - set <name> sqlCmd select * from history where `TIMESTAMP` > "2017-05-09 18:03:00" order by `TIMESTAMP` desc
+ - set <name> sqlCmd select * from current order by `TIMESTAMP` desc
+ - set <name> sqlCmd select sum(VALUE) as 'Einspeisung am 04.05.2017', count(*) as 'Anzahl' FROM `history` where `READING` = "Einspeisung_WirkP_Zaehler_Diff" and TIMESTAMP between '2017-05-04' AND '2017-05-05'
+ - set <name> sqlCmd delete from current
+ - set <name> sqlCmd delete from history where TIMESTAMP < "2016-05-06 00:00:00"
+ - set <name> sqlCmd update history set VALUE='TestVa$$ue$' WHERE VALUE='TestValue'
+ - set <name> sqlCmd select * from history where DEVICE = "Test"
+ - set <name> sqlCmd insert into history (TIMESTAMP, DEVICE, TYPE, EVENT, READING, VALUE, UNIT) VALUES ('2017-05-09 17:00:14','Test','manuell','manuell','Tes§e','TestValue','°C')
+
+
+ The result of the statement will be shown in Reading "SqlResult".
+ By attribut "sqlResultFormat" the fomatting can be choosen.
+
+ Note:
+ Even though the module works non-blocking regarding to database operations, a huge
+ sample space (number of rows/readings) could block the browser session respectively
+ FHEMWEB.
+ If you are unsure about the result of the statement, you should preventively add a limit to
+ the statement.
+
+
+
+ sumValue - calculates the amount of readingvalues DB-column "VALUE") between period given by
+ attributes "timestamp_begin", "timestamp_end" or
+ "timeDiffToNow / timeOlderThan". The reading to evaluate must be defined using attribute
+ "reading". Using this function is mostly reasonable if value-differences of readings
+ are written to the database.
+
- For all evaluation variants applies:
+ For all evaluation variants (except sqlCmd) applies:
In addition to the needed reading the device can be complemented to restrict the datasets for reporting / function.
If the time limit attributes are not set, the period from '1970-01-01 01:00:00' to the current date/time will be used as selection criterion.
@@ -4209,7 +4577,7 @@ return;
-
+ a
@@ -4223,20 +4591,26 @@ return;
Using the module specific attributes you are able to define the scope of evaluation and the aggregation.
- Hint to SQL-Wildcard Usage:
+ Note for SQL-Wildcard Usage:
Within the attribute values of "device" and "reading" you may use SQL-Wildcards, "%" and "_". The character "%" stands for any some characters, but
the character "_" = stands for only one.
This rule is valid to all functions except "insert", "deviceRename" and "delEntries".
The function "insert" doesn't allow setting the mentioned attributes containing the wildcard "%", the character "_" will evaluated as a normal character.
- The deletion function "delEntries" evaluates both characters "$", "_" NOT as wildcards and delete device/readings only if they are entered in the
+ The deletion function "delEntries" evaluates both characters "%", "_" NOT as wildcards and delete device/readings only if they are entered in the
attribute as exactly as they are stored in the database .
In readings the wildcard character "%" will be replaced by "/" to meet the rules of allowed characters in readings.
- - aggregation - Aggregation of Device/Reading-selections. Possible is hour, day, week, month or "no". Delivers e.g. the count of database entries for a day (countEntries), Summation of difference values of a reading (sumValue) and so on. Using aggregation "no" (default) an aggregation don't happens but the output contaims all values of Device/Reading in the defined time period.
+ - aggregation - Aggregation of Device/Reading-selections. Possible is hour, day, week, month or "no".
+ Delivers e.g. the count of database entries for a day (countEntries), Summation of
+ difference values of a reading (sumValue) and so on. Using aggregation "no" (default) an
+ aggregation don't happens but the output contaims all values of Device/Reading in the defined time period.
+
- allowDeletion - unlocks the delete-function
+
- device - selection of a particular device
+
- diffAccept - valid for function diffValue. diffAccept determines the threshold, up to that a calaculated difference between two
straight sequently datasets should be commenly accepted (default = 20).
Hence faulty DB entries with a disproportional high difference value will be eliminated and don't tamper the result.
@@ -4246,60 +4620,84 @@ return;
logfile.
-
- Example report in logfile if threshold of diffAccept=10 overruns:
+
+ Example report in logfile if threshold of diffAccept=10 overruns:
- DbRep Rep.STP5000.etotal -> data ignored while calc diffValue due to threshold overrun (diffAccept = 10):
- 2016-04-09 08:50:50 0.0340 -> 2016-04-09 12:42:01 13.3440
+ DbRep Rep.STP5000.etotal -> data ignored while calc diffValue due to threshold overrun (diffAccept = 10):
+ 2016-04-09 08:50:50 0.0340 -> 2016-04-09 12:42:01 13.3440
- # The first dataset with a value of 0.0340 is untypical low compared to the next value of 13.3440 and results a untypical
- high difference value.
- # Now you have to decide if the (second) dataset should be deleted, ignored of the attribute diffAccept should be adjusted.
-
+ # The first dataset with a value of 0.0340 is untypical low compared to the next value of 13.3440 and results a untypical
+ high difference value.
+ # Now you have to decide if the (second) dataset should be deleted, ignored of the attribute diffAccept should be adjusted.
+
- disable - deactivates the module
+
- expimpfile - Path/filename for data export/import
+
- reading - selection of a particular reading
+
- readingNameMap - the name of the analyzed reading can be overwritten for output
- - role - the role of the DbRep-device. Standard role is "Client". The role "Agent" is described in section DbRep-Agent.
- - readingPreventFromDel - comma separated list of readings which are should prevent from deletion when a new operation starts
- - showproctime - if set, the reading "sql_processing_time" shows the required execution time (in seconds) for the sql-requests. This is not calculated for a single sql-statement, but the summary of all sql-statements necessara for within an executed DbRep-function in background.
+
+ - role - the role of the DbRep-device. Standard role is "Client". The role "Agent" is described
+ in section DbRep-Agent.
+
+ - readingPreventFromDel - comma separated list of readings which are should prevent from deletion when a
+ new operation starts
+
+ - showproctime - if set, the reading "sql_processing_time" shows the required execution time (in seconds)
+ for the sql-requests. This is not calculated for a single sql-statement, but the summary
+ of all sql-statements necessara for within an executed DbRep-function in background.
+
- showStatus - limits the sample space of command "get ... dbstatus". SQL-Wildcards (% _) can be used.
-
- Example: attr ... showStatus %uptime%,%qcache%
- # Only readings with containing "uptime" and "qcache" in name will be shown
-
+
+ Example: attr ... showStatus %uptime%,%qcache%
+ # Only readings with containing "uptime" and "qcache" in name will be shown
+
- - showVariables - limits the sample space of command "get ... dbvars". SQL-Wildcards (% _) can be used.
+ - showVariables - limits the sample space of command "get ... dbvars". SQL-Wildcards (% _) can be used.
-
- Example: attr ... showVariables %version%,%query_cache%
- # Only readings with containing "version" and "query_cache" in name will be shown
-
+
+ Example: attr ... showVariables %version%,%query_cache%
+ # Only readings with containing "version" and "query_cache" in name will be shown
+
- showSvrInfo - limits the sample space of command "get ... svrinfo". SQL-Wildcards (% _) can be used.
-
- Example: attr ... showSvrInfo %SQL_CATALOG_TERM%,%NAME%
- # Only readings with containing "SQL_CATALOG_TERM" and "NAME" in name will be shown
-
+
+ Example: attr ... showSvrInfo %SQL_CATALOG_TERM%,%NAME%
+ # Only readings with containing "SQL_CATALOG_TERM" and "NAME" in name will be shown
+
- - showTableInfo - limits the tablename which is selected by command "get ... tableinfo". SQL-Wildcards (% _) can be used.
+ - showTableInfo - limits the tablename which is selected by command "get ... tableinfo". SQL-Wildcards
+ (% _) can be used.
-
- Example: attr ... showTableInfo current,history
- # Only informations about tables "current" and "history" will be shown
-
+
+ Example: attr ... showTableInfo current,history
+ # Only informations about tables "current" and "history" will be shown
+
+
+
+ - sqlResultFormat - determines the formatting of the "set ... sqlCmd" command result.
+
+ possible options are:
+
+ separated - every line of the result will be generated sequentially in a single
+ reading. (default)
+ mline - the result will be generated as multiline in
+ Reading SqlResult.
+ Field separator is "|".
+ sline - the result will be generated as singleline in
+ Reading SqlResult.
+ Field separator is "|" and the dataset is separated by "]|[".
+ table - the result will be generated as an table in
+ Reading SqlResult.
+
- timestamp_begin - begin of data selection (*)
- - timestamp_end - end of data selection. If not set the current date/time combination will be used. (*)
- - timeDiffToNow - the begin of data selection will be set to the timestamp "<current time> - <timeDiffToNow>" dynamically (in seconds). Thereby always the last <timeDiffToNow>-seconds will be considered (e.g. if set to 86400, always the last 24 hours should assumed). The Timestamp calculation will be done dynamically at execution time.
- - timeOlderThan - the end of data selection will be set to the timestamp "<aktuelle Zeit> - <timeOlderThan>" dynamically (in seconds). Always the datasets up to timestamp "<current time> - <timeOlderThan>" will be considered (e.g. if set to 86400, all datasets older than one day will be considered). The Timestamp calculation will be done dynamically at execution time.
-
- - timeout - sets the timeout-value for Blocking-Call Routines in background (default 60 seconds)
-
-
+
+ - timestamp_end - end of data selection. If not set the current date/time combination will be used. (*)
(*) The format of timestamp is as used with DbLog "YYYY-MM-DD HH:MM:SS". For the attributes "timestamp_begin", "timestamp_end"
you can also use one of the following entries. The timestamp-attribute will be dynamically set to:
@@ -4325,14 +4723,70 @@ return;
previous_hour_begin : "<previous hour>:00:00"
previous_hour_end : "<previous hour>:59:59"
- Make sure that timestamp_begin < timestamp_end is fulfilled.
+ Make sure that "timestamp_begin" < "timestamp_end" is fulfilled.
Note
If the attribute "timeDiffToNow" will be set, the attributes "timestamp_begin" respectively "timestamp_end" will be deleted if they were set before.
The setting of "timestamp_begin" respectively "timestamp_end" causes the deletion of attribute "timeDiffToNow" if it was set before as well.
+
+ timeDiffToNow - the begin of data selection will be set to the timestamp "<current time> -
+ <timeDiffToNow>" dynamically (in seconds). Thereby always the last
+ <timeDiffToNow>-seconds will be considered (e.g. if set to 86400, always the last
+ 24 hours should assumed). The Timestamp calculation will be done dynamically at execution
+ time.
+ timeOlderThan - the end of data selection will be set to the timestamp "<aktuelle Zeit> -
+ <timeOlderThan>" dynamically (in seconds). Always the datasets up to timestamp
+ "<current time> - <timeOlderThan>" will be considered (e.g. if set to
+ 86400, all datasets older than one day will be considered). The Timestamp calculation
+ will be done dynamically at execution time.
+
+ timeout - sets the timeout-value for Blocking-Call Routines in background (default 60 seconds)
+
+ userExitFn - proveds an interface to execute user specific program code.
+ To activate the interfaace at first you should implement the subroutine which will be
+ called by the interface in your 99_myUtls.pm as shown in by the example:
+
+
+ sub UserExitFn {
+ my ($name,$reading,$value) = @_;
+ my $hash = $defs{$name};
+ ...
+ # z.B. übergebene Daten loggen
+ Log3 $name, 1, "UserExitFn $name called - transfer parameter are Reading: $reading, Value: $value " ;
+ ...
+ return;
+ }
+
+ The interface activation takes place by setting the subroutine name in the attribute.
+ Optional you may set a Reading:Value combination (Regex) as argument. If no Regex is
+ specified, all value combinations will be evaluated as "true" (related to .*:.*).
+
+
+
+ Example:
+ attr userExitFn UserExit UserExit .*:.*
+ # "UserExit" is the name of subroutine in 99_myUtils.pm.
+
+
+
+ The interface works generally without and independent from Events.
+ If the attribute is set, after every reading generation the Regex will be evaluated.
+ If the evaluation was "true", set subroutine will be called.
+ For further processing following parameters will be forwarded to the function:
+
+
+ - $hash - the hash of the DbRep-Device
+ - $reading - the name of the created reading
+ - $value - the value of the reading
+
+
+
+
+
+
@@ -4346,15 +4800,26 @@ return;
In addition the following readings will be created:
- - state - contains the current state of evaluation. If warnings are occured (state = Warning) compare Readings
- "diff_overrun_limit_<diffLimit>" and "less_data_in_period"
- - errortext - description about the reason of an error state
+ - state - contains the current state of evaluation. If warnings are occured (state = Warning) compare Readings
+ "diff_overrun_limit_<diffLimit>" and "less_data_in_period"
+
+ - errortext - description about the reason of an error state
+
- background_processing_time - the processing time spent for operations in background/forked operation
- - sql_processing_time - the processing time wasted for all sql-statements used for an operation
+
+ - sql_processing_time - the processing time wasted for all sql-statements used for an operation
+
- diff_overrun_limit_<diffLimit> - contains a list of pairs of datasets which have overrun the threshold (<diffLimit>)
of calculated difference each other determined by attribute "diffAccept" (default=20).
- - less_data_in_period - contains a list of time periods within only one dataset was found. The difference calculation considers
- the last value of the aggregation period before the current one. Valid for function "diffValue".
+
+ - less_data_in_period - contains a list of time periods within only one dataset was found. The difference calculation considers
+ the last value of the aggregation period before the current one. Valid for function "diffValue".
+
+ - SqlResult - result of the last executed sqlCmd-command. The formatting can be specified
+ by attribute "sqlResultFormat"
+
+ - sqlCmd - contains the last executed sqlCmd-command
+
@@ -4432,32 +4897,44 @@ return;
Alle vorhandenen Readings werden vor einer neuen Operation gelöscht. Durch das Attribut "readingPreventFromDel" kann eine Komma separierte Liste von Readings
angegeben werden die nicht gelöscht werden sollen.
- Zur Zeit werden folgende Operationen unterstützt:
+ Aktuell werden folgende Operationen unterstützt:
- Selektion aller Datensätze innerhalb einstellbarer Zeitgrenzen.
- Darstellung der Datensätze einer Device/Reading-Kombination innerhalb einstellbarer Zeitgrenzen.
- Selektion der Datensätze unter Verwendung von dynamisch berechneter Zeitgrenzen zum Ausführungszeitpunkt.
- - Berechnung der Anzahl von Datensätzen einer Device/Reading-Kombination unter Berücksichtigung von Zeitgrenzen und verschiedenen Aggregationen.
- - Die Berechnung von Summen- , Differenz- , Maximum- , Minimum- und Durchschnittswerten von numerischen Readings in Zeitgrenzen und verschiedenen Aggregationen.
- - Löschung von Datensätzen. Die Eingrenzung der Löschung kann durch Device und/oder Reading sowie fixer oder dynamisch berechneter Zeitgrenzen zum Ausführungszeitpunkt erfolgen.
+ - Berechnung der Anzahl von Datensätzen einer Device/Reading-Kombination unter Berücksichtigung von Zeitgrenzen
+ und verschiedenen Aggregationen.
+ - Die Berechnung von Summen- , Differenz- , Maximum- , Minimum- und Durchschnittswerten von numerischen Readings
+ in Zeitgrenzen und verschiedenen Aggregationen.
+ - Löschung von Datensätzen. Die Eingrenzung der Löschung kann durch Device und/oder Reading sowie fixer oder
+ dynamisch berechneter Zeitgrenzen zum Ausführungszeitpunkt erfolgen.
- Export von Datensätzen in ein File im CSV-Format
- Import von Datensätzen aus File im CSV-Format
- Umbenennen von Device-Namen in Datenbanksätzen
- - automatisches Umbenennen von Device-Namen in Datenbanksätzen und DbRep-Definitionen nach FHEM "rename" Befehl (siehe DbRep-Agent)
-
+ automatisches Umbenennen von Device-Namen in Datenbanksätzen und DbRep-Definitionen nach FHEM "rename"
+ Befehl (siehe DbRep-Agent)
+ Ausführen von beliebigen Benutzer spezifischen SQL-Kommandos
+
+
Zur Aktivierung der Funktion "Autorename" wird dem definierten DbRep-Device mit dem Attribut "role" die Rolle "Agent" zugewiesen. Die Standardrolle nach Definition
ist "Client". Mehr ist dazu im Abschnitt DbRep-Agent beschrieben.
+ DbRep stellt dem Nutzer einen UserExit zur Verfügung. Über diese Schnittstelle kann der Nutzer in Abhängigkeit von
+ frei definierbaren Reading/Value-Kombinationen (Regex) eigenen Code zur Ausführung bringen. Diese Schnittstelle arbeitet
+ unabhängig von einer Eventgenerierung. Weitere Informationen dazu ist unter Attribut
+ "userExitFn" beschrieben.
+
FHEM-Forum:
Modul 93_DbRep - Reporting und Management von Datenbankinhalten (DbLog).
Voraussetzungen
- Das Modul setzt den Einsatz einer oder mehrerer DBLog-Instanzen voraus. Es werden die Zugangsdaten dieser Datenbankdefinition genutzt (bisher getestet mit MySQL und SQLite).
- Es werden nur Inhalte der Tabelle "history" berücksichtigt.
+ Das Modul setzt den Einsatz einer oder mehrerer DbLog-Instanzen voraus. Es werden die Zugangsdaten dieser
+ Datenbankdefinition genutzt (bisher getestet mit MySQL und SQLite).
+ Es werden nur Inhalte der Tabelle "history" (Ausnahme Kommando "sqlCmd") berücksichtigt.
Überblick welche anderen Perl-Module DbRep verwendet:
@@ -4500,16 +4977,38 @@ return;
- - averageValue - berechnet den Durchschnittswert der Readingwerte (DB-Spalte "VALUE") in den gegebenen Zeitgrenzen ( siehe Attribute).
- Es muss das auszuwertende Reading über das Attribut "reading" angegeben sein.
+ - averageValue - berechnet den Durchschnittswert der Readingwerte (DB-Spalte "VALUE") in den gegebenen
+ Zeitgrenzen ( siehe Attribute).
+ Es muss das auszuwertende Reading über das Attribut "reading"
+ angegeben sein.
- - countEntries - liefert die Anzahl der DB-Einträge in den gegebenen Zeitgrenzen (siehe Attribute).
+
- countEntries - liefert die Anzahl der DB-Einträge in den gegebenen Zeitgrenzen
+ (siehe Attribute).
Sind die Timestamps nicht gesetzt werden alle Einträge gezählt.
- Beschränkungen durch die Attribute Device bzw. Reading gehen in die Selektion mit ein.
+ Beschränkungen durch die Attribute Device bzw. Reading gehen
+ in die Selektion mit ein.
- - deviceRename - benennt den Namen eines Device innerhalb der angeschlossenen Datenbank (Internal DATABASE) um.
- Der Gerätename wird immer in der gesamten Datenbank umgesetzt. Eventuell gesetzte Zeitgrenzen oder Beschränkungen
- durch die Attribute Device bzw. Reading werden nicht berücksichtigt.
+ - delEntries - löscht alle oder die durch die Attribute device und/oder
+ reading definierten Datenbankeinträge. Die Eingrenzung über Timestamps erfolgt
+ folgendermaßen:
+
+
+ "timestamp_begin" gesetzt: gelöscht werden DB-Einträge ab diesem Zeitpunkt bis zum aktuellen Datum/Zeit
+ "timestamp_end" gesetzt : gelöscht werden DB-Einträge bis bis zu diesem Zeitpunkt
+ beide Timestamps gesetzt : gelöscht werden DB-Einträge zwischen diesen Zeitpunkten
+
+
+ Aus Sicherheitsgründen muss das Attribut "allowDeletion"
+ gesetzt sein um die Löschfunktion freizuschalten.
+
+
+
+
+ - deviceRename - benennt den Namen eines Device innerhalb der angeschlossenen Datenbank (Internal
+ DATABASE) um.
+ Der Gerätename wird immer in der gesamten Datenbank umgesetzt. Eventuell gesetzte
+ Zeitgrenzen oder Beschränkungen durch die Attribute Device bzw.
+ Reading werden nicht berücksichtigt.
Eingabeformat: set <name> deviceRename <alter Devicename>,<neuer Devicename>
@@ -4519,76 +5018,7 @@ return;
-
- readingRename - benennt den Namen eines Readings innerhalb der angeschlossenen Datenbank (siehe Internal DATABASE) um.
- Der Readingname wird immer in der gesamten Datenbank umgesetzt. Eventuell gesetzte Zeitgrenzen oder Beschränkungen
- durch die Attribute Device bzw. Reading werden nicht berücksichtigt.
-
-
- Eingabeformat: set <name> readingRename <alter Readingname>,<neuer Readingname>
- # Die Anzahl der umbenannten Device-Datensätze wird im Reading "reading_renamed" ausgegeben.
- # Wird der umzubenennende Readingname in der Datenbank nicht gefunden, wird eine WARNUNG im Reading "reading_not_renamed" ausgegeben.
- # Entsprechende Einträge erfolgen auch im Logfile mit verbose=3.
-
-
-
-
- exportToFile - exportiert DB-Einträge im CSV-Format in den gegebenen Zeitgrenzen.
- Einschränkungen durch die Attribute Device bzw. Reading gehen in die Selektion mit ein.
- Der Filename wird durch das Attribut "expimpfile" bestimmt.
-
- fetchrows - liefert alle DB-Einträge in den gegebenen Zeitgrenzen ( siehe Attribute).
- Eine evtl. gesetzte Aggregation wird nicht berücksichtigt.
-
- insert - Manuelles Einfügen eines Datensatzes in die Tabelle "history". Obligatorisch sind Eingabewerte für Datum, Zeit und Value.
- Die Werte für die DB-Felder Type bzw. Event werden mit "manual" gefüllt, sowie die Werte für Device, Reading aus den gesetzten Attributen genommen.
-
-
- Eingabeformat: Datum,Zeit,Value,[Unit]
- # Unit ist optional, Attribute "reading" und "device" müssen gesetzt sein
- # Soll "Value=0" eingefügt werden, ist "Value = 0.0" zu verwenden.
-
- Beispiel: 2016-08-01,23:00:09,TestValue,TestUnit
- # Es sind KEINE Leerzeichen im Feldwert erlaubt !
-
-
- Hinweis:
- Bei der Eingabe ist darauf zu achten dass im beabsichtigten Aggregationszeitraum (Tag, Woche, Monat, etc.) MINDESTENS zwei
- Datensätze für die Funktion diffValue zur Verfügung stehen. Ansonsten kann keine Differenz berechnet werden und diffValue
- gibt in diesem Fall "0" in der betroffenen Periode aus !
-
-
-
-
-
- importFromFile - importiert Datensätze im CSV-Format aus einem File in die Datenbank. Der Filename wird durch das Attribut "expimpfile" bestimmt.
-
-
- Datensatzformat: "TIMESTAMP","DEVICE","TYPE","EVENT","READING","VALUE","UNIT"
- # Die Felder "TIMESTAMP","DEVICE","TYPE","EVENT","READING" und "VALUE" müssen gesetzt sein. Das Feld "UNIT" ist optional.
- Der Fileinhalt wird als Transaktion importiert, d.h. es wird der Inhalt des gesamten Files oder, im Fehlerfall, kein Datensatz des Files importiert.
- Wird eine umfangreiche Datei mit vielen Datensätzen importiert sollte KEIN verbose=5 gesetzt werden. Es würden in diesem Fall sehr viele Sätze in
- das Logfile geschrieben werden was FHEM blockieren oder überlasten könnte.
-
- Beispiel: "2016-09-25 08:53:56","STP_5000","SMAUTILS","etotal: 11859.573","etotal","11859.573",""
-
-
-
-
- sumValue - berechnet die Summenwerte eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
- Es muss das auszuwertende Reading im Attribut "reading" angegeben sein.
- Diese Funktion ist sinnvoll wenn fortlaufend Wertedifferenzen eines Readings in die Datenbank geschrieben werden.
-
- maxValue - berechnet den Maximalwert eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
- Es muss das auszuwertende Reading über das Attribut "reading" angegeben sein.
- Die Auswertung enthält den Zeitstempel des ermittelten Maximumwertes innerhalb der Aggregation bzw. Zeitgrenzen.
- Im Reading wird der Zeitstempel des letzten Auftretens vom Maximalwert ausgegeben falls dieser Wert im Intervall mehrfach erreicht wird.
-
- minValue - berechnet den Minimalwert eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
- Es muss das auszuwertende Reading über das Attribut "reading" angegeben sein.
- Die Auswertung enthält den Zeitstempel des ermittelten Minimumwertes innerhalb der Aggregation bzw. Zeitgrenzen.
- Im Reading wird der Zeitstempel des ersten Auftretens vom Minimalwert ausgegeben falls dieser Wert im Intervall mehrfach erreicht wird.
-
+
diffValue - berechnet den Differenzwert eines Readingwertes (DB-Spalte "Value") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw "timeDiffToNow / timeOlderThan".
Es muss das auszuwertende Reading im Attribut "reading" angegeben sein.
Diese Funktion ist z.B. zur Auswertung von Eventloggings sinnvoll, deren Werte sich fortlaufend erhöhen und keine Wertdifferenzen wegschreiben.
@@ -4610,23 +5040,133 @@ return;
-
- delEntries - löscht alle oder die durch die Attribute device und/oder reading definierten Datenbankeinträge. Die Eingrenzung über Timestamps erfolgt folgendermaßen:
+
+ exportToFile - exportiert DB-Einträge im CSV-Format in den gegebenen Zeitgrenzen.
+ Einschränkungen durch die Attribute Device bzw. Reading gehen in die Selektion mit ein.
+ Der Filename wird durch das Attribut "expimpfile" bestimmt.
+
+ fetchrows - liefert alle DB-Einträge in den gegebenen Zeitgrenzen ( siehe Attribute).
+ Eine evtl. gesetzte Aggregation wird nicht berücksichtigt.
+
+ insert - Manuelles Einfügen eines Datensatzes in die Tabelle "history". Obligatorisch sind Eingabewerte für Datum, Zeit und Value.
+ Die Werte für die DB-Felder Type bzw. Event werden mit "manual" gefüllt, sowie die Werte für Device, Reading aus den gesetzten Attributen genommen.
- "timestamp_begin" gesetzt: gelöscht werden DB-Einträge ab diesem Zeitpunkt bis zum aktuellen Datum/Zeit
- "timestamp_end" gesetzt : gelöscht werden DB-Einträge bis bis zu diesem Zeitpunkt
- beide Timestamps gesetzt : gelöscht werden DB-Einträge zwischen diesen Zeitpunkten
+ Eingabeformat: Datum,Zeit,Value,[Unit]
+ # Unit ist optional, Attribute "reading" und "device" müssen gesetzt sein
+ # Soll "Value=0" eingefügt werden, ist "Value = 0.0" zu verwenden.
+ Beispiel: 2016-08-01,23:00:09,TestValue,TestUnit
+ # Es sind KEINE Leerzeichen im Feldwert erlaubt !
- Aus Sicherheitsgründen muss das Attribut "allowDeletion" gesetzt sein um die Löschfunktion freizuschalten.
-
+
+ Hinweis:
+ Bei der Eingabe ist darauf zu achten dass im beabsichtigten Aggregationszeitraum (Tag, Woche, Monat, etc.) MINDESTENS zwei
+ Datensätze für die Funktion diffValue zur Verfügung stehen. Ansonsten kann keine Differenz berechnet werden und diffValue
+ gibt in diesem Fall "0" in der betroffenen Periode aus !
+
+
+
+
+ importFromFile - importiert Datensätze im CSV-Format aus einem File in die Datenbank. Der Filename wird
+ durch das Attribut "expimpfile" bestimmt.
+
+ Datensatzformat: "TIMESTAMP","DEVICE","TYPE","EVENT","READING","VALUE","UNIT"
+ # Die Felder "TIMESTAMP","DEVICE","TYPE","EVENT","READING" und "VALUE" müssen gesetzt sein. Das Feld "UNIT" ist optional.
+ Der Fileinhalt wird als Transaktion importiert, d.h. es wird der Inhalt des gesamten Files oder, im Fehlerfall, kein Datensatz des Files importiert.
+ Wird eine umfangreiche Datei mit vielen Datensätzen importiert sollte KEIN verbose=5 gesetzt werden. Es würden in diesem Fall sehr viele Sätze in
+ das Logfile geschrieben werden was FHEM blockieren oder überlasten könnte.
+
+ Beispiel: "2016-09-25 08:53:56","STP_5000","SMAUTILS","etotal: 11859.573","etotal","11859.573",""
+
+
+
+
+ maxValue - berechnet den Maximalwert eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen
+ (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
+ Es muss das auszuwertende Reading über das Attribut "reading"
+ angegeben sein.
+ Die Auswertung enthält den Zeitstempel des ermittelten Maximumwertes innerhalb der
+ Aggregation bzw. Zeitgrenzen.
+ Im Reading wird der Zeitstempel des letzten Auftretens vom Maximalwert ausgegeben
+ falls dieser Wert im Intervall mehrfach erreicht wird.
+
+ minValue - berechnet den Minimalwert eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen
+ (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
+ Es muss das auszuwertende Reading über das Attribut "reading"
+ angegeben sein.
+ Die Auswertung enthält den Zeitstempel des ermittelten Minimumwertes innerhalb der
+ Aggregation bzw. Zeitgrenzen.
+ Im Reading wird der Zeitstempel des ersten Auftretens vom Minimalwert ausgegeben
+ falls dieser Wert im Intervall mehrfach erreicht wird.
+
+ readingRename - benennt den Namen eines Readings innerhalb der angeschlossenen Datenbank (siehe Internal DATABASE) um.
+ Der Readingname wird immer in der gesamten Datenbank umgesetzt. Eventuell
+ gesetzte Zeitgrenzen oder Beschränkungen durch die Attribute
+ Device bzw. Reading werden nicht berücksichtigt.
+
+
+ Eingabeformat: set <name> readingRename <alter Readingname>,<neuer Readingname>
+ # Die Anzahl der umbenannten Device-Datensätze wird im Reading "reading_renamed"
+ ausgegeben.
+ # Wird der umzubenennende Readingname in der Datenbank nicht gefunden, wird eine
+ WARNUNG im Reading "reading_not_renamed" ausgegeben.
+ # Entsprechende Einträge erfolgen auch im Logfile mit verbose=3.
+
+
+
+
+ sqlCmd - führt ein beliebiges Benutzer spezifisches Kommando aus.
+ Enthält dieses Kommando eine Delete-Operation, muss zur Sicherheit das
+ Attribut "allowDeletion" gesetzt sein.
+ Bei der Ausführung dieses Kommandos werden keine Einschränkungen durch gesetzte Attribute
+ device und/oder reading berücksichtigt.
+ Sollen die im Modul gesetzten Attribute "timestamp_begin" bzw.
+ "timestamp_end" im Statement berücksichtigt werden, können die Platzhalter
+ "§timestamp_begin§" bzw. "§timestamp_end§" dafür verwendet werden.
+
+
+ Beispiele für Statements:
+
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= "2017-01-06 00:00:00" group by DEVICE having count(*) > 800
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= "2017-05-06 00:00:00" group by DEVICE
+ - set <name> sqlCmd select DEVICE, count(*) from history where TIMESTAMP >= §timestamp_begin§ group by DEVICE
+ - set <name> sqlCmd select * from history where DEVICE like "Te%t" order by `TIMESTAMP` desc
+ - set <name> sqlCmd select * from history where `TIMESTAMP` > "2017-05-09 18:03:00" order by `TIMESTAMP` desc
+ - set <name> sqlCmd select * from current order by `TIMESTAMP` desc
+ - set <name> sqlCmd select sum(VALUE) as 'Einspeisung am 04.05.2017', count(*) as 'Anzahl' FROM `history` where `READING` = "Einspeisung_WirkP_Zaehler_Diff" and TIMESTAMP between '2017-05-04' AND '2017-05-05'
+ - set <name> sqlCmd delete from current
+ - set <name> sqlCmd delete from history where TIMESTAMP < "2016-05-06 00:00:00"
+ - set <name> sqlCmd update history set VALUE='TestVa$$ue$' WHERE VALUE='TestValue'
+ - set <name> sqlCmd select * from history where DEVICE = "Test"
+ - set <name> sqlCmd insert into history (TIMESTAMP, DEVICE, TYPE, EVENT, READING, VALUE, UNIT) VALUES ('2017-05-09 17:00:14','Test','manuell','manuell','Tes§e','TestValue','°C')
+
+
+
+ Das Ergebnis des Statements wird im Reading "SqlResult" dargestellt.
+ Die Formatierung kann durch das Attribut "sqlResultFormat" ausgewählt werden.
+
+ Hinweis:
+ Auch wenn das Modul bezüglich der Datenbankabfrage nichtblockierend arbeitet, kann eine
+ zu große Ergebnismenge (Anzahl Zeilen bzw. Readings) die Browsersesssion bzw. FHEMWEB
+ blockieren. Wenn man sich unsicher ist, sollte man vorsorglich dem Statement ein Limit
+ hinzufügen.
+
+
+
+
+ sumValue - berechnet die Summenwerte eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen
+ (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow / timeOlderThan".
+ Es muss das auszuwertende Reading im Attribut "reading"
+ angegeben sein. Diese Funktion ist sinnvoll wenn fortlaufend Wertedifferenzen eines
+ Readings in die Datenbank geschrieben werden.
+
- Für alle Auswertungsvarianten gilt:
+ Für alle Auswertungsvarianten (Ausnahme sqlCmd) gilt:
Zusätzlich zu dem auszuwertenden Reading kann das Device mit angegeben werden um das Reporting nach diesen Kriterien einzuschränken.
Sind keine Zeitgrenzen-Attribute angegeben, wird '1970-01-01 01:00:00' und das aktuelle Datum/Zeit als Zeitgrenze genutzt.
@@ -4730,7 +5270,7 @@ return;
viele Zeichen und "_" = ein Zeichen.
Dies gilt für alle Funktionen außer "insert", "deviceRename" und "delEntries".
Die Funktion "insert" erlaubt nicht dass die genannten Attribute das Wildcard "%" enthalten, "_" wird als normales Zeichen gewertet.
- Die Löschfunktion "delEntries" wertet die Zeichen "$", "_" NICHT als Wildcards und löscht nur Device/Readings die exakt wie in den Attributen angegeben
+ Die Löschfunktion "delEntries" wertet die Zeichen "%", "_" NICHT als Wildcards und löscht nur Device/Readings die exakt wie in den Attributen angegeben
in der DB gespeichert sind.
In den Readings wird das Wildcardzeichen "%" durch "/" ersetzt um die Regeln für erlaubte Zeichen in Readings einzuhalten.
@@ -4759,47 +5299,71 @@ return;
disable - deaktiviert das Modul
+
expimpfile - Pfad/Dateiname für Export/Import in/aus einem File.
- reading - Abgrenzung der DB-Selektionen auf ein bestimmtes Reading
- readingNameMap - der Name des ausgewerteten Readings wird mit diesem String für die Anzeige überschrieben
- readingPreventFromDel - Komma separierte Liste von Readings die vor einer neuen Operation nicht gelöscht werden sollen
- role - die Rolle des DbRep-Device. Standard ist "Client". Die Rolle "Agent" ist im Abschnitt DbRep-Agent beschrieben.
- showproctime - wenn gesetzt, zeigt das Reading "sql_processing_time" die benötigte Abarbeitungszeit (in Sekunden) für die SQL-Ausführung der durchgeführten Funktion. Dabei wird nicht ein einzelnes SQl-Statement, sondern die Summe aller notwendigen SQL-Abfragen innerhalb der jeweiligen Funktion betrachtet.
+
+ reading - Abgrenzung der DB-Selektionen auf ein bestimmtes Reading
+
+ readingNameMap - der Name des ausgewerteten Readings wird mit diesem String für die Anzeige überschrieben
+
+ readingPreventFromDel - Komma separierte Liste von Readings die vor einer neuen Operation nicht gelöscht
+ werden sollen
+
+ role - die Rolle des DbRep-Device. Standard ist "Client". Die Rolle "Agent" ist im Abschnitt
+ DbRep-Agent beschrieben.
+
+ showproctime - wenn gesetzt, zeigt das Reading "sql_processing_time" die benötigte Abarbeitungszeit (in Sekunden)
+ für die SQL-Ausführung der durchgeführten Funktion. Dabei wird nicht ein einzelnes
+ SQl-Statement, sondern die Summe aller notwendigen SQL-Abfragen innerhalb der jeweiligen
+ Funktion betrachtet.
+
showStatus - grenzt die Ergebnismenge des Befehls "get ... dbstatus" ein. Es können SQL-Wildcards (% _) verwendet werden.
-
- Bespiel: attr ... showStatus %uptime%,%qcache%
- # Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthalten
-
+
+ Bespiel: attr ... showStatus %uptime%,%qcache%
+ # Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthalten
+
showVariables - grenzt die Ergebnismenge des Befehls "get ... dbvars" ein. Es können SQL-Wildcards (% _) verwendet werden.
-
- Bespiel: attr ... showVariables %version%,%query_cache%
- # Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten
-
+
+ Bespiel: attr ... showVariables %version%,%query_cache%
+ # Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten
+
showSvrInfo - grenzt die Ergebnismenge des Befehls "get ... svrinfo" ein. Es können SQL-Wildcards (% _) verwendet werden.
-
- Bespiel: attr ... showSvrInfo %SQL_CATALOG_TERM%,%NAME%
- # Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten
-
+
+ Bespiel: attr ... showSvrInfo %SQL_CATALOG_TERM%,%NAME%
+ # Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten
+
showTableInfo - grenzt die Ergebnismenge des Befehls "get ... tableinfo" ein. Es können SQL-Wildcards (% _) verwendet werden.
-
- Bespiel: attr ... showTableInfo current,history
- # Es werden nur Information der Tabellen "current" und "history" angezeigt
-
+
+ Bespiel: attr ... showTableInfo current,history
+ # Es werden nur Information der Tabellen "current" und "history" angezeigt
+
+ sqlResultFormat - legt die Formatierung des Ergebnisses von "set ... sqlResult" fest.
+
+ mögliche Optionen sind:
+
+ separated - die Ergebniszeilen werden als einzelne Readings fortlaufend
+ generiert. (default)
+ mline - das Ergebnis wird als Mehrzeiler im Reading
+ sqlCmd dargestellt. Feldtrenner ist "|".
+ sline - das Ergebnis wird als Singleline im Reading
+ sqlCmd dargestellt. Feldtrenner ist "|", Satztrenner ist"]|[".
+ table - das Ergebnis wird als Tabelle im Reading
+ sqlCmd dargestellt.
+
+
timestamp_begin - der zeitliche Beginn für die Datenselektion (*)
- timestamp_end - das zeitliche Ende für die Datenselektion. Wenn nicht gesetzt wird immer die aktuelle Datum/Zeit-Kombi für das Ende der Selektion eingesetzt. (*)
- timeDiffToNow - der Selektionsbeginn wird auf den Zeitpunkt "<aktuelle Zeit> - <timeDiffToNow>" gesetzt (in Sekunden). Es werden immer die letzten <timeDiffToNow>-Sekunden berücksichtigt (z.b. 86400 wenn immer die letzten 24 Stunden in die Selektion eingehen sollen). Die Timestampermittlung erfolgt dynamisch zum Ausführungszeitpunkt.
- timeOlderThan - das Selektionsende wird auf den Zeitpunkt "<aktuelle Zeit> - <timeOlderThan>" gesetzt (in Sekunden). Dadurch werden alle Datensätze bis zu dem Zeitpunkt "<aktuelle Zeit> - <timeOlderThan>" berücksichtigt (z.b. wenn auf 86400 gesetzt werden alle Datensätze die älter als ein Tag sind berücksichtigt). Die Timestampermittlung erfolgt dynamisch zum Ausführungszeitpunkt.
- timeout - das Attribut setzt den Timeout-Wert für die Blocking-Call Routinen (Standard 60) in Sekunden
-
-
+
+ timestamp_end - das zeitliche Ende für die Datenselektion. Wenn nicht gesetzt wird immer die aktuelle
+ Datum/Zeit-Kombi für das Ende der Selektion eingesetzt. (*)
+
(*) Das Format von Timestamp ist wie in DbLog "YYYY-MM-DD HH:MM:SS". Für die Attribute "timestamp_begin", "timestamp_end"
kann ebenso eine der folgenden Eingaben verwendet werden. Dabei wird das timestamp-Attribut dynamisch belegt:
@@ -4826,14 +5390,70 @@ return;
previous_hour_end : "<vorherige Stunde>:59:59"
- Natürlich sollte man immer darauf achten dass timestamp_begin < timestamp_end ist.
+ Natürlich sollte man immer darauf achten dass "timestamp_begin" < "timestamp_end" ist.
Hinweis
Wird das Attribut "timeDiffToNow" gesetzt, werden die evtentuell gesetzten Attribute "timestamp_begin" bzw. "timestamp_end" gelöscht.
Das Setzen von "timestamp_begin" bzw. "timestamp_end" bedingt die Löschung von Attribut "timeDiffToNow" wenn es vorher gesetzt war.
+
+ timeDiffToNow - der Selektionsbeginn wird auf den Zeitpunkt "<aktuelle Zeit> - <timeDiffToNow>"
+ gesetzt (in Sekunden). Es werden immer die letzten <timeDiffToNow>-Sekunden
+ berücksichtigt (z.b. 86400 wenn immer die letzten 24 Stunden in die Selektion eingehen
+ sollen). Die Timestampermittlung erfolgt dynamisch zum Ausführungszeitpunkt.
+
+ timeOlderThan - das Selektionsende wird auf den Zeitpunkt "<aktuelle Zeit> - <timeOlderThan>"
+ gesetzt (in Sekunden). Dadurch werden alle Datensätze bis zu dem Zeitpunkt "<aktuelle
+ Zeit> - <timeOlderThan>" berücksichtigt (z.b. wenn auf 86400 gesetzt werden alle
+ Datensätze die älter als ein Tag sind berücksichtigt). Die Timestampermittlung erfolgt
+ dynamisch zum Ausführungszeitpunkt.
+
+ timeout - das Attribut setzt den Timeout-Wert für die Blocking-Call Routinen (Standard 60) in
+ Sekunden
+ userExitFn - stellt eine Schnittstelle zur Ausführung eigenen Usercodes zur Verfügung.
+ Um die Schnittstelle zu aktivieren, wird zunächst die aufzurufende Subroutine in
+ 99_myUtls.pm nach folgendem Muster erstellt:
+
+ sub UserExitFn {
+ my ($name,$reading,$value) = @_;
+ my $hash = $defs{$name};
+ ...
+ # z.B. übergebene Daten loggen
+ Log3 $name, 1, "UserExitFn $name called - transfer parameter are Reading: $reading, Value: $value " ;
+ ...
+ return;
+ }
+
+
+ Die Aktivierung der Schnittstelle erfogt durch Setzen des Funktionsnames im Attribut.
+ Optional kann ein Reading:Value Regex als Argument angegeben werden. Wird kein Regex
+ angegeben, werden alle Wertekombinationen als "wahr" gewertet (entspricht .*:.*).
+
+
+
+ Beispiel:
+ attr userExitFn UserExit UserExit .*:.*
+ # "UserExit" ist die Subroutine in 99_myUtils.pm.
+
+
+
+ Grundsätzlich arbeitet die Schnittstelle OHNE Eventgenerierung bzw. benötigt zur Funktion keinen
+ Event. Sofern das Attribut gesetzt ist, erfolgt Die Regexprüfung NACH der Erstellung eines
+ Readings. Ist die Prüfung WAHR, wird die angegebene Funktion aufgerufen.
+ Zur Weiterverarbeitung werden der aufgerufenenen Funktion folgende Variablen übergeben:
+
+
+ - $hash - der Hash des DbRep-Devices
+ - $reading - der Namen des erstellen Readings
+ - $value - der Wert des Readings
+
+
+
+
+
+
@@ -4847,16 +5467,26 @@ return;
Zusätzlich werden folgende Readings erzeugt:
- - state - enthält den aktuellen Status der Auswertung. Wenn Warnungen auftraten (state = Warning) vergleiche Readings
+
- state - enthält den aktuellen Status der Auswertung. Wenn Warnungen auftraten (state = Warning) vergleiche Readings
"diff_overrun_limit_<diffLimit>" und "less_data_in_period"
- - errortext - Grund eines Fehlerstatus
+
+ - errortext - Grund eines Fehlerstatus
+
- background_processing_time - die gesamte Prozesszeit die im Hintergrund/Blockingcall verbraucht wird
- - sql_processing_time - der Anteil der Prozesszeit die für alle SQL-Statements der ausgeführten Operation verbraucht wird
+
- diff_overrun_limit_<diffLimit> - enthält eine Liste der Wertepaare die eine durch das Attribut "diffAccept" festgelegte Differenz
<diffLimit> (Standard: 20) überschreiten. Gilt für Funktion "diffValue".
- - less_data_in_period - enthält eine Liste der Zeitperioden in denen nur ein einziger Datensatz gefunden wurde. Die
- Differenzberechnung berücksichtigt den letzten Wert der Vorperiode. Gilt für Funktion "diffValue".
-
+
+ - less_data_in_period - enthält eine Liste der Zeitperioden in denen nur ein einziger Datensatz gefunden wurde. Die
+ Differenzberechnung berücksichtigt den letzten Wert der Vorperiode. Gilt für Funktion "diffValue".
+
+ - sql_processing_time - der Anteil der Prozesszeit die für alle SQL-Statements der ausgeführten
+ Operation verbraucht wird
+
+ - SqlResult - Ergebnis des letzten sqlCmd-Kommandos. Die Formatierung erfolgt entsprechend
+ des Attributes "sqlResultFormat"
+
+ - sqlCmd - das letzte ausgeführte sqlCmd-Kommando
@@ -4919,4 +5549,4 @@ return;
=end html_DE
-=cut
+=cut
\ No newline at end of file