diff --git a/fhem/CHANGED b/fhem/CHANGED index d4404bd67..e786f2787 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. + - feature: 93_DbRep: FHEM command "dbReadingsVal" implemented - change: 49_SSCam: Meta.json and minor code change - change: 50_MOBILEALERTSGW: Checksum check added - change: 93_DbRep: check index "Report_Idx" during first DB connect diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index f54aa3e40..fcb39862a 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -58,6 +58,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern our %DbRep_vNotesIntern = ( + "8.21.0" => "28.04.2019 implement FHEM command \"dbReadingsVal\" ", "8.20.1" => "28.04.2019 set index verbose changed, check index \"Report_Idx\" in getInitData ", "8.20.0" => "27.04.2019 don't save hash refs in central hash to prevent potential memory leak, new set \"index\" ". "command, \"repository\" added in Meta.json ", @@ -374,8 +375,18 @@ sub DbRep_Initialize($) { "userExitFn ". "valueFilter ". $readingFnAttributes; + + my %hash = ( + Fn => 'CommandDbReadingsVal', + Hlp => ' ,Get the value of a device:reading combination from database. + The value next to the timestamp is returned if found, otherwise the . + = name of used DbRep device, + = timestamp like YYYY-MM-DD_hh:mm:ss + ' + ); + $cmds{dbReadingsVal} = \%hash; - # Umbenennen von existierenden Attrbuten + # Umbenennen von existierenden Attributen # $hash->{AttrRenameMap} = { "reading" => "readingFilter", # "device" => "deviceFilter", # }; @@ -1493,7 +1504,7 @@ sub DbRep_getInitData($) { Log3($name, 3, "DbRep $name - $idxstate. Check ok"); } else { $idxstate = "Index $idx doesn't exist. Please create the index by \"set $name index recreate_Report_Idx\" command !"; - Log3($name, 2, "DbRep $name - WARNING - $idxstate"); + Log3($name, 3, "DbRep $name - WARNING - $idxstate"); } } } @@ -10642,12 +10653,25 @@ return ($ret); } #################################################################################################### -# blockierende DB-Abfrage -# liefert den Wert eines Device:Readings des nächsmöglichen Logeintrags zum -# angegebenen Zeitpunkt +# blockierende DB-Abfrage +# liefert den Wert eines Device:Readings des nächstmöglichen Logeintrags zum +# angegebenen Zeitpunkt # -# Aufruf: DbReadingsVal("","",","") +# Aufruf als Funktion: DbReadingsVal("","",","") +# Aufruf als FHEM-Cmd: DbReadingsVal #################################################################################################### +sub CommandDbReadingsVal($$) { + my ($cl, $param) = @_; + + my @a = split("[ \t][ \t]*", $param); + my ($name, $devread, $ts, $default) = @a; + $ts =~ s/_/ /; + + my $ret = DbReadingsVal($name, $devread, $ts, $default); + +return $ret; +} + sub DbReadingsVal($$$$) { my ($name, $devread, $ts, $default) = @_; my $hash = $defs{$name}; @@ -10659,9 +10683,10 @@ sub DbReadingsVal($$$$) { } unless($defs{$name}{TYPE} eq "DbRep") { return ("\"$name\" is not a DbRep-device but of type \"".$defs{$name}{TYPE}."\""); - } + } + $ts =~ s/_/ /; unless($ts =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) { - return ("timestamp has not a valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp."); + return ("timestamp has not the valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp."); } my ($dev,$reading) = split(":",$devread); unless($dev && $reading) { @@ -10828,28 +10853,44 @@ return; Further informations you can find as described at attribute "userExitFn".

- Once a DbRep-Device is defined, the function DbReadingsVal is provided. + Once a DbRep-Device is defined, the Perl function DbReadingsVal provided as well as and the FHEM command dbReadingsVal. With this function you can, similar to the well known ReadingsVal, get a reading value from database. - The function execution is carried out blocking. - The command syntax is:

- + The function execution is carried out blocking.

+
    - DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>")

    + The command syntax for the Perl function is:

    + + + DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>") + +

    Examples:
    - $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13 08:00:00","");
    - attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13 08:00:00","")} + my $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
    + attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}

    + The command syntax for the FHEM command is:

    + + + dbReadingsVal <name> <device:reading> <timestamp> <default> + +

    + + Example:
    + dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 +

    + - +
    <name> : name of the DbRep-Device to request
    <device:reading> : device:reading whose value is to deliver
    <timestamp> : timestamp of reading whose value is to deliver (*) in the form "YYYY-MM-DD hh:mm:ss"
    <timestamp> : timestamp of reading whose value is to deliver (*) in the form "YYYY-MM-DD_hh:mm:ss"
    <default> : default value if no reading value can be retrieved

+ (*) If no value can be retrieved at the <timestamp> exactly requested, the chronological most convenient reading value is delivered back.

@@ -10858,9 +10899,8 @@ return; Modul 93_DbRep - Reporting and Management of database content (DbLog).


- - + Preparations

    The module requires the usage of a DbLog instance and the credentials of the database definition will be used.
    @@ -13225,28 +13265,45 @@ sub bdump { unabhängig von einer Eventgenerierung. Weitere Informationen dazu ist unter Attribut "userExitFn" beschrieben.

    - Sobald ein DbRep-Device definiert ist, wird die Funktion DbReadingsVal zur Verfügung gestellt. + Sobald ein DbRep-Device definiert ist, wird sowohl die Perl Funktion DbReadingsVal als auch das FHEM Kommando + dbReadingsVal zur Verfügung gestellt. Mit dieser Funktion läßt sich, ähnlich dem allgemeinen ReadingsVal, der Wert eines Readings aus der Datenbank abrufen. - Die Funktionsausführung erfolgt blockierend. - Die Befehlssyntax ist:

    - + Die Funktionsausführung erfolgt blockierend.

    +
      - DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>")

      + Die Befehlssyntax für die Perl Funktion ist:

      + + + DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>") + +

      Beispiele:
      - $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13 08:00:00","");
      - attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13 08:00:00","")} + $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
      + attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}

      + Die Befehlssyntax als FHEM Kommando ist:

      + + + dbReadingsVal <name> <device:reading> <timestamp> <default> + +

      + + Beispiel:
      + dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 +

      + - +
      <name> : Name des abzufragenden DbRep-Device
      <device:reading> : Device:Reading dessen Wert geliefert werden soll
      <timestamp> : Zeitpunkt des zu liefernden Readingwertes (*) in der Form "YYYY-MM-DD hh:mm:ss"
      <timestamp> : Zeitpunkt des zu liefernden Readingwertes (*) im Format "YYYY-MM-DD_hh:mm:ss"
      <default> : Defaultwert falls kein Readingwert ermittelt werden konnte

    + (*) Es wird der zeitlich zu <timestamp> passendste Readingwert zurück geliefert, falls kein Wert exakt zu dem angegebenen Zeitpunkt geloggt wurde.

    diff --git a/fhem/contrib/DS_Starter/93_DbRep.pm b/fhem/contrib/DS_Starter/93_DbRep.pm index 81114ec9f..4b657ebaa 100644 --- a/fhem/contrib/DS_Starter/93_DbRep.pm +++ b/fhem/contrib/DS_Starter/93_DbRep.pm @@ -58,6 +58,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern our %DbRep_vNotesIntern = ( + "8.21.0" => "28.04.2019 implement FHEM command \"dbReadingsVal\" ", "8.20.1" => "28.04.2019 set index verbose changed, check index \"Report_Idx\" in getInitData ", "8.20.0" => "27.04.2019 don't save hash refs in central hash to prevent potential memory leak, new set \"index\" ". "command, \"repository\" added in Meta.json ", @@ -374,8 +375,18 @@ sub DbRep_Initialize($) { "userExitFn ". "valueFilter ". $readingFnAttributes; + + my %hash = ( + Fn => 'CommandDbReadingsVal', + Hlp => ' ,Get the value of a device:reading combination from database. + The value next to the timestamp is returned if found, otherwise the . + = name of used DbRep device, + = timestamp like YYYY-MM-DD_hh:mm:ss + ' + ); + $cmds{dbReadingsVal} = \%hash; - # Umbenennen von existierenden Attrbuten + # Umbenennen von existierenden Attributen # $hash->{AttrRenameMap} = { "reading" => "readingFilter", # "device" => "deviceFilter", # }; @@ -1493,7 +1504,7 @@ sub DbRep_getInitData($) { Log3($name, 3, "DbRep $name - $idxstate. Check ok"); } else { $idxstate = "Index $idx doesn't exist. Please create the index by \"set $name index recreate_Report_Idx\" command !"; - Log3($name, 2, "DbRep $name - WARNING - $idxstate"); + Log3($name, 3, "DbRep $name - WARNING - $idxstate"); } } } @@ -10642,12 +10653,25 @@ return ($ret); } #################################################################################################### -# blockierende DB-Abfrage -# liefert den Wert eines Device:Readings des nächsmöglichen Logeintrags zum -# angegebenen Zeitpunkt +# blockierende DB-Abfrage +# liefert den Wert eines Device:Readings des nächstmöglichen Logeintrags zum +# angegebenen Zeitpunkt # -# Aufruf: DbReadingsVal("","",","") +# Aufruf als Funktion: DbReadingsVal("","",","") +# Aufruf als FHEM-Cmd: DbReadingsVal #################################################################################################### +sub CommandDbReadingsVal($$) { + my ($cl, $param) = @_; + + my @a = split("[ \t][ \t]*", $param); + my ($name, $devread, $ts, $default) = @a; + $ts =~ s/_/ /; + + my $ret = DbReadingsVal($name, $devread, $ts, $default); + +return $ret; +} + sub DbReadingsVal($$$$) { my ($name, $devread, $ts, $default) = @_; my $hash = $defs{$name}; @@ -10659,9 +10683,10 @@ sub DbReadingsVal($$$$) { } unless($defs{$name}{TYPE} eq "DbRep") { return ("\"$name\" is not a DbRep-device but of type \"".$defs{$name}{TYPE}."\""); - } + } + $ts =~ s/_/ /; unless($ts =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) { - return ("timestamp has not a valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp."); + return ("timestamp has not the valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp."); } my ($dev,$reading) = split(":",$devread); unless($dev && $reading) { @@ -10828,28 +10853,44 @@ return; Further informations you can find as described at attribute "userExitFn".

    - Once a DbRep-Device is defined, the function DbReadingsVal is provided. + Once a DbRep-Device is defined, the Perl function DbReadingsVal provided as well as and the FHEM command dbReadingsVal. With this function you can, similar to the well known ReadingsVal, get a reading value from database. - The function execution is carried out blocking. - The command syntax is:

    - + The function execution is carried out blocking.

    +
      - DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>")

      + The command syntax for the Perl function is:

      + + + DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>") + +

      Examples:
      - $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13 08:00:00","");
      - attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13 08:00:00","")} + my $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
      + attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}

      + The command syntax for the FHEM command is:

      + + + dbReadingsVal <name> <device:reading> <timestamp> <default> + +

      + + Example:
      + dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 +

      + - +
      <name> : name of the DbRep-Device to request
      <device:reading> : device:reading whose value is to deliver
      <timestamp> : timestamp of reading whose value is to deliver (*) in the form "YYYY-MM-DD hh:mm:ss"
      <timestamp> : timestamp of reading whose value is to deliver (*) in the form "YYYY-MM-DD_hh:mm:ss"
      <default> : default value if no reading value can be retrieved

    + (*) If no value can be retrieved at the <timestamp> exactly requested, the chronological most convenient reading value is delivered back.

    @@ -10858,9 +10899,8 @@ return; Modul 93_DbRep - Reporting and Management of database content (DbLog).


    - -
+ Preparations

    The module requires the usage of a DbLog instance and the credentials of the database definition will be used.
    @@ -13225,28 +13265,45 @@ sub bdump { unabhängig von einer Eventgenerierung. Weitere Informationen dazu ist unter Attribut "userExitFn" beschrieben.

    - Sobald ein DbRep-Device definiert ist, wird die Funktion DbReadingsVal zur Verfügung gestellt. + Sobald ein DbRep-Device definiert ist, wird sowohl die Perl Funktion DbReadingsVal als auch das FHEM Kommando + dbReadingsVal zur Verfügung gestellt. Mit dieser Funktion läßt sich, ähnlich dem allgemeinen ReadingsVal, der Wert eines Readings aus der Datenbank abrufen. - Die Funktionsausführung erfolgt blockierend. - Die Befehlssyntax ist:

    - + Die Funktionsausführung erfolgt blockierend.

    +
      - DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>")

      + Die Befehlssyntax für die Perl Funktion ist:

      + + + DbReadingsVal("<name>","<device:reading>","<timestamp>","<default>") + +

      Beispiele:
      - $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13 08:00:00","");
      - attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13 08:00:00","")} + $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
      + attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}

      + Die Befehlssyntax als FHEM Kommando ist:

      + + + dbReadingsVal <name> <device:reading> <timestamp> <default> + +

      + + Beispiel:
      + dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 +

      + - +
      <name> : Name des abzufragenden DbRep-Device
      <device:reading> : Device:Reading dessen Wert geliefert werden soll
      <timestamp> : Zeitpunkt des zu liefernden Readingwertes (*) in der Form "YYYY-MM-DD hh:mm:ss"
      <timestamp> : Zeitpunkt des zu liefernden Readingwertes (*) im Format "YYYY-MM-DD_hh:mm:ss"
      <default> : Defaultwert falls kein Readingwert ermittelt werden konnte

    + (*) Es wird der zeitlich zu <timestamp> passendste Readingwert zurück geliefert, falls kein Wert exakt zu dem angegebenen Zeitpunkt geloggt wurde.