diff --git a/fhem/CHANGED b/fhem/CHANGED index e61e0af85..f934533a5 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. + - changed: 93_DbRep: usage of "insert" changed, pls. refer to commandref - changed: 93_DbRep: function "insert" added, check of numeric value type in functions maxvalue, diffvalue - added: 98_Hyperion: initial release of completely new module diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index 0bd06e740..d6098a3ab 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -37,6 +37,9 @@ ########################################################################################################### # Versions History: # +# 3.4.3 09.08.2016 fields for input using "insert" changed to "date,time,value,unit". Attributes +# device, reading will be used to complete dataset, +# now more informations available about faulty datasets in arithmetic operations # 3.4.2 05.08.2016 commandref complemented, fieldlength used in function "insert" trimmed to 32 # 3.4.1 04.08.2016 check of numeric value type in functions maxvalue, diffvalue # 3.4 03.08.2016 function "insert" added @@ -100,6 +103,7 @@ use Blocking; use Time::Local; no if $] >= 5.017011, warnings => 'experimental'; + ################################################################################### # DbRep_Initialize ################################################################################### @@ -122,7 +126,7 @@ sub DbRep_Initialize($) { "timestamp_end ". "timeDiffToNow ". "timeout ". - $readingFnAttributes; + $readingFnAttributes; return undef; } @@ -218,10 +222,13 @@ sub DbRep_Set { } elsif ($opt eq "insert") { if ($prop) { + if (!AttrVal($hash->{NAME}, "device", "") || !AttrVal($hash->{NAME}, "reading", "") ) { + return " The attribute \"device\" and/or \"reading\" is not set. It's mandatory to complete dataset for manual insert !"; + } - my ($i_date, $i_time, $i_device, $i_reading, $i_value, $i_unit) = split(",",$prop); + my ($i_date, $i_time, $i_value, $i_unit) = split(",",$prop); - if (!$i_date || !$i_time || !$i_device || !$i_reading || !$i_value) {return "At least data for Date, Time, Device, Reading and Value are needed to insert. Inputformat is 'YYYY-MM-DD,HH:MM:SS,,,,' ";} + if (!$i_date || !$i_time || !$i_value) {return "At least data for Date, Time and Value are needed to insert. Inputformat is 'YYYY-MM-DD,HH:MM:SS,,' ";} unless ($i_date =~ /(\d{4})-(\d{2})-(\d{2})/) {return "Input for date is not valid. Use format YYYY-MM-DD !";} unless ($i_time =~ /(\d{2}):(\d{2}):(\d{2})/) {return "Input for time is not valid. Use format HH:MM:SS !";} @@ -235,11 +242,14 @@ sub DbRep_Set { return " Timestamp is out of range - $l[0]"; } + my $i_device = AttrVal($hash->{NAME}, "device", ""); + my $i_reading = AttrVal($hash->{NAME}, "reading", ""); + # Daten auf maximale Länge (entsprechend der Feldlänge in DbLog DB create-scripts) beschneiden $i_device = substr($i_device,0, 32); $i_reading = substr($i_reading,0, 32); $i_value = substr($i_value,0, 32); - $i_unit = substr($i_unit,0, 32); + $i_unit = substr($i_unit,0, 32) if($i_unit); $hash->{helper}{I_TIMESTAMP} = $i_timestamp; $hash->{helper}{I_DEVICE} = $i_device; @@ -250,7 +260,7 @@ sub DbRep_Set { $hash->{helper}{I_EVENT} = my $i_event = "manual"; } else { - return "Data to insert to table 'history' are needed like this pattern: 'Date,Time,Device,Reading,Value,Unit'. Spaces are not allowed !"; + return "Data to insert to table 'history' are needed like this pattern: 'Date,Time,Value,Unit'. Spaces are not allowed !"; } sqlexec($hash,"insert"); @@ -1049,8 +1059,9 @@ sub maxval_ParseDone { if (!looks_like_number($value)) { readingsSingleUpdate($hash, "state", "error", 1); delete($hash->{helper}{RUNNING_PID}); - Log3 ($name, 2, "DbRep $name - ERROR - found value = '$value' isn't numeric in maxValue function. Leaving ..."); - Log3 ($name, 4, "DbRep $name -> BlockingCall diffval_ParseDone finished"); + $a[3] =~ s/\s+$//g; + Log3 ($name, 2, "DbRep $name - ERROR - value isn't numeric in maxValue function. Faulty dataset was \nTIMESTAMP: $a[2] $a[3], DEVICE: $device, READING: $reading, VALUE: $value. \nLeaving ..."); + Log3 ($name, 4, "DbRep $name -> BlockingCall maxval_ParseDone finished"); return; } @@ -1257,12 +1268,14 @@ sub diffval_ParseDone { my $runtime_string = decode_base64($a[0]); $lastruntimestring = $runtime_string if ($i == 1); - my $value = $a[1]; + my $value = $a[1]; + # Test auf $value = "numeric" if (!looks_like_number($value)) { readingsSingleUpdate($hash, "state", "error", 1); delete($hash->{helper}{RUNNING_PID}); - Log3 ($name, 2, "DbRep $name - ERROR - found value = '$value' isn't numeric in diffValue function. Leaving ..."); + $a[3] =~ s/\s+$//g; + Log3 ($name, 2, "DbRep $name - ERROR - value isn't numeric in diffValue function. Faulty dataset was \nTIMESTAMP: $a[2] $a[3], DEVICE: $device, READING: $reading, VALUE: $value. \nLeaving ..."); Log3 ($name, 4, "DbRep $name -> BlockingCall diffval_ParseDone finished"); return; } @@ -2088,22 +2101,29 @@ return ($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll)
  • averageValue - calculates the average value of readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow". The reading to evaluate must be defined using attribute "reading".

  • countEntries - provides the number of DB-entries between period given by attributes "timestamp_begin", "timestamp_end".(if set) or "timeDiffToNow". 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.

  • fetchrows - provides all DB-entries between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow". A possibly set aggregation attribute will not considered.

  • -
  • insert - use it to insert data ito table "history" manually. Input values for Date, Time, Device, Reading and Value are mandatory. The database fields for Type and Event will be filled in with "manual" automatically.

    - - input format: Date,Time,Device,Reading,Value,Unit
    - example: 2016-08-01,23:00:09,TestDevice,TestReading,TestValue,TestUnit # field lenth is maximum 32 characters, NO spaces are allowed in fieldvalues !
    +
  • insert - use it to insert data ito table "history" manually. Input values for Date, Time and Value are mandatory. The database fields for Type and Event will be filled in with "manual" automatically and the values of Device, Reading will be get from set attributes.

    + +
      + input format: Date,Time,Value,[Unit]
      + # Unit is optional, attributes of device, reading must be set !

      + + example: 2016-08-01,23:00:09,TestValue,TestUnit
      + # field lenth is maximum 32 characters, NO spaces are allowed in fieldvalues !

      +
  • sumValue - calculates the amount of readingvalues DB-column "VALUE") between period given by attributes "timestamp_begin", "timestamp_end" or "timeDiffToNow". 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". The reading to evaluate must be defined using attribute "reading". The evaluation contains the timestamp of the identified max values 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". 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.

  • 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".

    - + +
      "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
      +

    @@ -2214,21 +2234,28 @@ return ($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll)
  • averageValue - berechnet den Durchschnittswert der Readingwerte (DB-Spalte "VALUE") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow". Es muß das auszuwertende Reading über das Attribut "reading" angegeben sein.

  • countEntries - liefert die Anzahl der DB-Einträge in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" (wenn gesetzt) bzw. "timeDiffToNow". 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.

  • fetchrows - liefert alle DB-Einträge in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end". 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, Device, Reading und Value. Die Werte für die DB-Felder Type bzw. Event werden mit "manual" gefüllt.

    - - Eingabeformat: Datum,Zeit,Device,Reading,Value,Unit
    - Beispiel: 2016-08-01,23:00:09,TestDevice,TestReading,TestValue,TestUnit # die Feldlänge ist maximal 32 Zeichen lang, es sind KEINE Leerzeichen im Feldwert erlaubt !
    +
  • 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

      + + Beispiel: 2016-08-01,23:00:09,TestValue,TestUnit
      + # die Feldlänge ist maximal 32 Zeichen lang, es sind KEINE Leerzeichen im Feldwert erlaubt !


      +
  • sumValue - berechnet die Summenwerte eines Readingwertes (DB-Spalte "VALUE") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw. "timeDiffToNow". Es muss das auszuwertende Reading über das 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". Es muss das auszuwertende Reading über das Attribut "reading" angegeben sein. Die Auswertung enthält den Zeitstempel des ermittelten Maximalwertes innerhalb der Aggregation bzw. Zeitgrenzen.

  • diffValue - berechnet den Differenzwert eines Readingwertes (DB-Spalte "Value") in den Zeitgrenzen (Attribute) "timestamp_begin", "timestamp_end" bzw "timeDiffToNow". Es muss das auszuwertende Reading über das Attribut "reading" angegeben sein. Diese Funktion ist z.B. zur Auswertung von Eventloggings sinnvoll, deren Werte sich fortlaufend erhöhen und keine Wertdifferenzen wegschreiben.

  • 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
      +