From 87a5f3a0c44d589fa8e3f1f492521ca3ee900da4 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Wed, 25 Jan 2023 21:51:45 +0000 Subject: [PATCH] 93_DbLog: contrib 5.7.0 git-svn-id: https://svn.fhem.de/fhem/trunk@27122 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/93_DbLog.pm | 351 ++++++++++++++++++++-------- 1 file changed, 249 insertions(+), 102 deletions(-) diff --git a/fhem/contrib/DS_Starter/93_DbLog.pm b/fhem/contrib/DS_Starter/93_DbLog.pm index 5f7163055..773658930 100644 --- a/fhem/contrib/DS_Starter/93_DbLog.pm +++ b/fhem/contrib/DS_Starter/93_DbLog.pm @@ -5771,11 +5771,11 @@ sub DbLog_Get { my $to = shift @a; # Now @a contains the list of column_specs my ($internal, @fld); - if($inf eq "-") { + if ($inf eq "-") { $inf = "history"; } - if($outf eq "int" && $inf eq "current") { + if ($outf eq "int" && $inf eq "current") { $inf = "history"; Log3 $name, 3, "Defining DbLog SVG-Plots with :CURRENT is deprecated. Please define DbLog SVG-Plots with :HISTORY instead of :CURRENT. (define SVG ::HISTORY)"; } @@ -5784,10 +5784,10 @@ sub DbLog_Get { $outf = "-"; $internal = 1; } - elsif($outf eq "array") { + elsif ($outf eq "array") { } - elsif(lc($outf) eq "webchart") { # redirect the get request to the DbLog_chartQuery function + elsif (lc($outf) eq "webchart") { # redirect the get request to the DbLog_chartQuery function return DbLog_chartQuery ($hash, @_); } @@ -8277,14 +8277,14 @@ sub DbLog_dbReadings { my $dbh = $hash->{DBHU}; return 'Wrong Syntax for ReadingsVal!' unless defined($a[4]); - + my $cmd = $a[1]; my $device = $a[2]; my $reading = $a[3]; my $def = $a[4]; my $query = q{}; - + if ($cmd =~ /ReadingsMaxVal(Timestamp)?$/xs) { $query = "select MAX(VALUE),TIMESTAMP from $history where DEVICE= '$device' and READING= '$reading';"; } @@ -8297,15 +8297,15 @@ sub DbLog_dbReadings { elsif ($cmd =~ /Readings(Val|ValTimestamp|Timestamp)$/xs) { $query = "select VALUE,TIMESTAMP from $history where DEVICE= '$device' and READING= '$reading' order by TIMESTAMP desc limit 1;"; } - + return ">$cmd< isn't valid!" if(!$query); - + ($err, my $val, my $timestamp) = __DbLog_SBP_selectrowArray ($dbh, $query); - return "error-> $err" if($err); + return "error-> $err" if($err); $val = defined $val ? $val : $def; $timestamp = defined $timestamp ? $timestamp : $def; - + if ($cmd =~ /Readings(Max|Min|Avg)?Val$/xs) { return $val; } @@ -8891,45 +8891,45 @@ return; Get

- +
  • get <name> ReadingsMaxVal[Timestamp] <Device> <Reading> <default>

      Determines the record with the largest value of the specified Device / Reading combination from the history table.
      - Only the value or the combination of value and timestamp is returned as string + Only the value or the combination of value and timestamp is returned as string "<Wert> , <Timestamp>".
      <default> specifies a defined return value if no value can be determined.

      - + Note:
      - This database retrieval works blocking and influences FHEM if the database does not respond or not responds + This database retrieval works blocking and influences FHEM if the database does not respond or not responds sufficiently fast.

- +
  • get <name> ReadingsMinVal[Timestamp] <Device> <Reading> <default>

      Determines the record with the smallest value of the specified device / reading combination from the history table.
      - Only the value or the combination of value and timestamp is returned as string + Only the value or the combination of value and timestamp is returned as string "<Wert> , <Timestamp>".
      <default> specifies a defined return value if no value can be determined.

      - + Note:
      - This database retrieval works blocking and influences FHEM if the database does not respond or not responds + This database retrieval works blocking and influences FHEM if the database does not respond or not responds sufficiently fast.

- +
  • get <name> ReadingsAvgVal <Device> <Reading> <default>

    @@ -8939,9 +8939,9 @@ return; <default> specifies a defined return value if no value can be determined.

    - + Note:
    - This database retrieval works blocking and influences FHEM if the database does not respond or not responds + This database retrieval works blocking and influences FHEM if the database does not respond or not responds sufficiently fast.
@@ -8954,14 +8954,14 @@ return;
    Reads the last (newest) record stored in the history table of the specified Device / Reading combination.
    - Only the value or the combination of value and timestamp is returned as string + Only the value or the combination of value and timestamp is returned as string "<Wert> , <Timestamp>".
    <default> specifies a defined return value if no value can be determined.

    - + Note:
    - This database retrieval works blocking and influences FHEM if the database does not respond or not responds + This database retrieval works blocking and influences FHEM if the database does not respond or not responds sufficiently fast.
@@ -8977,9 +8977,9 @@ return; <default> specifies a defined return value if no value is found in the database.

- + Note:
- This database retrieval works blocking and influences FHEM if the database does not respond or not responds + This database retrieval works blocking and influences FHEM if the database does not respond or not responds sufficiently fast. @@ -9002,6 +9002,8 @@ return;
  • -: identical to "history"
  • +
    +
  • <out>
    A dummy parameter for FileLog compatibility. Setting by default to - to check the output for plot-computing.
    @@ -9014,77 +9016,137 @@ return;
  • -: default
  • +
    +
  • <from> / <to>
    Used to select the data. Please use the following timeformat or an initial substring of it:
    -
      YYYY-MM-DD_HH24:MI:SS
  • +
      + YYYY-MM-DD_HH24:MI:SS +
    + +
    +
  • <column_spec>
    For each column_spec return a set of data separated by a comment line on the current connection.
    - Syntax: <device>:<reading>:<default>:<fn>:<regexp>
    +
    + + Syntax: <device>:<reading>:<default>:<fn>:<regexp>
    +
    +
    • <device>
      - The name of the device. Case sensitive. Using a the joker "%" is supported.
    • + The name of the device. Case sensitive. Using a the joker "%" is supported. + +
      +
    • <reading>
      The reading of the given device to select. Case sensitive. Using a the joker "%" is supported. -
    • + +
      +
    • <default>
      no implemented yet -
    • + +
      +
    • <fn> One of the following:
      • int
        Extract the integer at the beginning of the string. Used e.g. - for constructs like 10%
      • + for constructs like 10% + +
        +
      • int<digit>
        Extract the decimal digits including negative character and decimal point at the beginning og the string. Used e.g. - for constructs like 15.7°C
      • + for constructs like 15.7°C + +
        +
      • delta-h / delta-d
        Return the delta of the values for a given hour or a given day. Used if the column contains a counter, as is the case for the - KS300 rain column.
      • + KS300 rain column. + +
        +
      • delta-ts
        Replaced the original value with a measured value of seconds since the last and the actual logentry.
      • -
    • +
      + +
    +
  • +
  • <regexp>
    The string is evaluated as a perl expression. The regexp is executed before <fn> parameter.
    Note: The string/perl expression cannot contain spaces, as the part after the space will be considered as the next column_spec.
    +
    + Keywords
  • $val is the current value returned from the Database.
  • $ts is the current timestamp returned from the Database.
  • This Logentry will not print out if $val contains th keyword "hide".
  • This Logentry will not print out and not used in the following processing - if $val contains th keyword "ignore".
  • + if $val contains th keyword "ignore". - + +

    + Examples:
      -
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature
    • -
    • get myDbLog current ALL - - %:temperature

    • +
    • + get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature +
    • +
      + +
    • get myDbLog current ALL - - %:temperature
      you will get all actual readings "temperature" from all logged devices. Be careful by using "history" as inputfile because a long execution time will be expected! +
    • +
      +
    • get myDbLog - - 2012-11-10_10 2012-11-10_20 KS300:temperature::int1
      - like from 10am until 08pm at 10.11.2012
    • -
    • get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature
    • -
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d
    • + like from 10am until 08pm at 10.11.2012 + +
      + +
    • + get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature +
    • +
      + +
    • + get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d +
    • +
      +
    • get myDbLog - - 2012-11-10 2012-11-20 MyFS20:data:::$val=~s/(on|off).*/$1eq"on"?1:0/eg
      - return 1 for all occurance of on* (on|on-for-timer etc) and 0 for all off*
    • + return 1 for all occurance of on* (on|on-for-timer etc) and 0 for all off* + +
      +
    • get myDbLog - - 2012-11-10 2012-11-20 Bodenfeuchte:data:::$val=~s/.*B:\s([-\.\d]+).*/$1/eg
      Example of OWAD: value like this: "A: 49.527 % B: 66.647 % C: 9.797 % D: 0.097 V"
      - and output for port B is like this: 2012-11-20_10:23:54 66.647
    • + and output for port B is like this: 2012-11-20_10:23:54 66.647 + +
      +
    • get DbLog - - 2013-05-26 2013-05-28 Pumpe:data::delta-ts:$val=~s/on/hide/
      Setting up a "Counter of Uptime". The function delta-ts gets the seconds between the last and the actual logentry. The keyword "hide" will hide the logentry of "on" because this time - is a "counter of Downtime"
    • + is a "counter of Downtime" +
    @@ -9102,46 +9164,69 @@ return;
    • <name>
      The name of the defined DbLog, like it is given in fhem.cfg.
    • +
      +
    • <in>
      A dummy parameter for FileLog compatibility. Always set to -
    • +
      +
    • <out>
      A dummy parameter for FileLog compatibility. Set it to webchart to use the charting related get function.
    • +
      +
    • <from> / <to>
      Used to select the data. Please use the following timeformat:
        YYYY-MM-DD_HH24:MI:SS
    • +
      +
    • <device>
      A string which represents the device to query.
    • +
      +
    • <querytype>
      A string which represents the method the query should use. Actually supported values are:
      - getreadings to retrieve the possible readings for a given device
      - getdevices to retrieve all available devices
      - timerange to retrieve charting data, which requires a given xaxis, yaxis, device, to and from
      - savechart to save a chart configuration in the database. Requires a given xaxis, yaxis, device, to and from, and a 'savename' used to save the chart
      - deletechart to delete a saved chart. Requires a given id which was set on save of the chart
      - getcharts to get a list of all saved charts.
      - getTableData to get jsonformatted data from the database. Uses paging Parameters like start and limit.
      - hourstats to get statistics for a given value (yaxis) for an hour.
      - daystats to get statistics for a given value (yaxis) for a day.
      - weekstats to get statistics for a given value (yaxis) for a week.
      - monthstats to get statistics for a given value (yaxis) for a month.
      - yearstats to get statistics for a given value (yaxis) for a year.
      + getreadings to retrieve the possible readings for a given device
      + getdevices to retrieve all available devices
      + timerange to retrieve charting data, which requires a given xaxis, yaxis, device, to and from
      + savechart to save a chart configuration in the database. Requires a given xaxis, yaxis, device, to and from, and a 'savename' used to save the chart
      + deletechart to delete a saved chart. Requires a given id which was set on save of the chart
      + getcharts to get a list of all saved charts.
      + getTableData to get jsonformatted data from the database. Uses paging Parameters like start and limit.
      + hourstats to get statistics for a given value (yaxis) for an hour.
      + daystats to get statistics for a given value (yaxis) for a day.
      + weekstats to get statistics for a given value (yaxis) for a week.
      + monthstats to get statistics for a given value (yaxis) for a month.
      + yearstats to get statistics for a given value (yaxis) for a year.
    • +
      +
    • <xaxis>
      A string which represents the xaxis
    • +
      +
    • <yaxis>
      A string which represents the yaxis
    • +
      +
    • <savename>
      A string which represents the name a chart will be saved with
    • +
      +
    • <chartconfig>
      A jsonstring which represents the chart to save
    • +
      +
    • <pagingstart>
      An integer used to determine the start for the sql used for query 'getTableData'
    • +
      +
    • <paginglimit>
      An integer used to set the limit for the sql used for query 'getTableData'
    • -
    -

    +
    + + Examples:
    • get logdb - webchart "" "" "" getcharts
      @@ -10578,45 +10663,45 @@ attr SMA_Energymeter DbLogValueFn Get

      - +
      • get <name> ReadingsMaxVal[Timestamp] <Device> <Reading> <default>

          Ermittelt den Datensatz mit dem größten Wert der angegebenen Device / Reading Kombination aus der history Tabelle.
          - Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String + Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String "<Wert> , <Timestamp>".
          <default> gibt einen definierten Rückgabewert an, wenn kein Wert ermittelt werden kann.

          - + Hinweis:
          - Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht + Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht hinreichend schnell antwortet.

    • - +
      • get <name> ReadingsMinVal[Timestamp] <Device> <Reading> <default>

          Ermittelt den Datensatz mit dem kleinsten Wert der angegebenen Device / Reading Kombination aus der history Tabelle.
          - Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String + Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String "<Wert> , <Timestamp>".
          <default> gibt einen definierten Rückgabewert an, wenn kein Wert ermittelt werden kann.

          - + Hinweis:
          - Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht + Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht hinreichend schnell antwortet.

      - +
      • get <name> ReadingsAvgVal <Device> <Reading> <default>

        @@ -10626,9 +10711,9 @@ attr SMA_Energymeter DbLogValueFn <default> gibt einen definierten Rückgabewert an, wenn kein Wert ermittelt werden kann.

        - + Hinweis:
        - Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht + Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht hinreichend schnell antwortet.
    @@ -10641,14 +10726,14 @@ attr SMA_Energymeter DbLogValueFn
      Liest den letzten (neuesten) in der history Tabelle gespeicherten Datensatz der angegebenen Device / Reading Kombination.
      - Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String + Zurück gegeben wird nur der Wert oder die Kombination aus Wert und Timestamp als String "<Wert> , <Timestamp>".
      <default> gibt einen definierten Rückgabewert an, wenn kein Wert ermittelt werden kann.

      - + Hinweis:
      - Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht + Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht hinreichend schnell antwortet.
    @@ -10664,11 +10749,11 @@ attr SMA_Energymeter DbLogValueFn <default> gibt einen definierten Rückgabewert an, wenn kein Wert in der Datenbank gefunden wird.

    - + Hinweis:
    - Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht + Dieser Datenbankabruf arbeitet blockierend und beeinflusst FHEM wenn die Datenbank nicht oder nicht hinreichend schnell antwortet. - +
    @@ -10692,6 +10777,7 @@ attr SMA_Energymeter DbLogValueFn
  • -: identisch wie "history"
  • +
  • <out>
    Ein Parameter um eine Kompatibilität zum Filelog herzustellen. @@ -10705,29 +10791,45 @@ attr SMA_Energymeter DbLogValueFn
  • -: default
  • +
  • <from> / <to>
    Wird benutzt um den Zeitraum der Daten einzugrenzen. Es ist das folgende Zeitformat oder ein Teilstring davon zu benutzen:
    -
      YYYY-MM-DD_HH24:MI:SS
  • + +
      + YYYY-MM-DD_HH24:MI:SS +
    + +
  • <column_spec>
    Für jede column_spec Gruppe wird ein Datenset zurückgegeben welches durch einen Kommentar getrennt wird. Dieser Kommentar repräsentiert - die column_spec.
    - Syntax: <device>:<reading>:<default>:<fn>:<regexp>
    + die column_spec.
    +
    + Syntax: <device>:<reading>:<default>:<fn>:<regexp>
    +
    +
    • <device>
      Der Name des Devices. Achtung: Gross/Kleinschreibung beachten!
      - Es kann ein % als Jokerzeichen angegeben werden.
    • + Es kann ein % als Jokerzeichen angegeben werden. + +
      +
    • <reading>
      Das Reading des angegebenen Devices zur Datenselektion.
      Es kann ein % als Jokerzeichen angegeben werden.
      Achtung: Gross/Kleinschreibung beachten!
    • +
      +
    • <default>
      Zur Zeit noch nicht implementiert.
    • +
      +
    • <fn> Angabe einer speziellen Funktion:
        @@ -10750,7 +10852,10 @@ attr SMA_Energymeter DbLogValueFn Ermittelt die vergangene Zeit zwischen dem letzten und dem aktuellen Logeintrag in Sekunden und ersetzt damit den originalen Wert. -
    • +
    +
  • +
    +
  • <regexp>
    Diese Zeichenkette wird als Perl Befehl ausgewertet. Die regexp wird vor dem angegebenen <fn> Parameter ausgeführt. @@ -10758,9 +10863,11 @@ attr SMA_Energymeter DbLogValueFn Bitte zur Beachtung: Diese Zeichenkette darf keine Leerzeichen enthalten da diese sonst als <column_spec> Trennung interpretiert werden und alles nach dem Leerzeichen als neue - <column_spec> gesehen wird.
    + <column_spec> gesehen wird.
    +
    Schlüsselwörter +
  • $val ist der aktuelle Wert die die Datenbank für ein Device/Reading ausgibt.
  • $ts ist der aktuelle Timestamp des Logeintrages.
  • Wird als $val das Schlüsselwort "hide" zurückgegeben, so wird dieser Logeintrag nicht @@ -10768,36 +10875,51 @@ attr SMA_Energymeter DbLogValueFn
  • Wird als $val das Schlüsselwort "ignore" zurückgegeben, so wird dieser Logeintrag nicht für eine Folgeberechnung verwendet.
  • - + +

    Beispiele:
      -
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature
    • +
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature

    • -
    • get myDbLog current ALL - - %:temperature

    • +
    • get myDbLog current ALL - - %:temperature
      Damit erhält man alle aktuellen Readings "temperature" von allen in der DB geloggten Devices. Achtung: bei Nutzung von Jokerzeichen auf die history-Tabelle kann man sein FHEM aufgrund langer Laufzeit lahmlegen! +
    • +
    • get myDbLog - - 2012-11-10_10 2012-11-10_20 KS300:temperature::int1
      - gibt Daten aus von 10Uhr bis 20Uhr am 10.11.2012
    • + gibt Daten aus von 10Uhr bis 20Uhr am 10.11.2012 + +
      -
    • get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature
    • +
    • get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature +
    • +
      -
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d
    • +
    • get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d +
    • +
    • get myDbLog - - 2012-11-10 2012-11-20 MyFS20:data:::$val=~s/(on|off).*/$1eq"on"?1:0/eg
      - gibt 1 zurück für alle Ausprägungen von on* (on|on-for-timer etc) und 0 für alle off*
    • + gibt 1 zurück für alle Ausprägungen von on* (on|on-for-timer etc) und 0 für alle off* + +
    • get myDbLog - - 2012-11-10 2012-11-20 Bodenfeuchte:data:::$val=~s/.*B:\s([-\.\d]+).*/$1/eg
      Beispiel von OWAD: Ein Wert wie z.B.: "A: 49.527 % B: 66.647 % C: 9.797 % D: 0.097 V"
      - und die Ausgabe ist für das Reading B folgende: 2012-11-20_10:23:54 66.647
    • + und die Ausgabe ist für das Reading B folgende: 2012-11-20_10:23:54 66.647 + +
    • get DbLog - - 2013-05-26 2013-05-28 Pumpe:data::delta-ts:$val=~s/on/hide/
      Realisierung eines Betriebsstundenzählers. Durch delta-ts wird die Zeit in Sek zwischen den Log- Einträgen ermittelt. Die Zeiten werden bei den on-Meldungen nicht ausgegeben welche einer Abschaltzeit - entsprechen würden.
    • + entsprechen würden. + +
    @@ -10814,24 +10936,36 @@ attr SMA_Energymeter DbLogValueFn
    • <name>
      - Der Name des definierten DbLogs, so wie er in der fhem.cfg angegeben wurde.
    • + Der Name des definierten DbLogs, so wie er in der fhem.cfg angegeben wurde. + +
    • <in>
      Ein Dummy Parameter um eine Kompatibilität zum Filelog herzustellen. - Dieser Parameter ist immer auf - zu setzen.
    • + Dieser Parameter ist immer auf - zu setzen. + +
    • <out>
      Ein Dummy Parameter um eine Kompatibilität zum Filelog herzustellen. Dieser Parameter ist auf webchart zu setzen um die Charting Get Funktion zu nutzen.
    • +
    • <from> / <to>
      Wird benutzt um den Zeitraum der Daten einzugrenzen. Es ist das folgende Zeitformat zu benutzen:
      -
        YYYY-MM-DD_HH24:MI:SS
    • + +
        + YYYY-MM-DD_HH24:MI:SS +
      + +
    • <device>
      - Ein String, der das abzufragende Device darstellt.
    • + Ein String, der das abzufragende Device darstellt. + +
    • <querytype>
      Ein String, der die zu verwendende Abfragemethode darstellt. Zur Zeit unterstützte Werte sind:
      @@ -10848,26 +10982,39 @@ attr SMA_Energymeter DbLogValueFn monthstats um Statistiken für einen Wert (yaxis) für einen Monat abzufragen.
      yearstats um Statistiken für einen Wert (yaxis) für ein Jahr abzufragen.
    • +
    • <xaxis>
      - Ein String, der die X-Achse repräsentiert
    • + Ein String, der die X-Achse repräsentiert + +
    • <yaxis>
      - Ein String, der die Y-Achse repräsentiert
    • + Ein String, der die Y-Achse repräsentiert + +
    • <savename>
      - Ein String, unter dem ein Chart in der Datenbank gespeichert werden soll
    • + Ein String, unter dem ein Chart in der Datenbank gespeichert werden soll + +
    • <chartconfig>
      - Ein jsonstring der den zu speichernden Chart repräsentiert
    • + Ein jsonstring der den zu speichernden Chart repräsentiert + +
    • <pagingstart>
      - Ein Integer um den Startwert für die Abfrage 'getTableData' festzulegen
    • + Ein Integer um den Startwert für die Abfrage 'getTableData' festzulegen + +
    • <paginglimit>
      - Ein Integer um den Limitwert für die Abfrage 'getTableData' festzulegen
    • + Ein Integer um den Limitwert für die Abfrage 'getTableData' festzulegen + +
    -

    +
    Beispiele: