From 29385a29b1b545ccf081ffeafce755ed765df9c5 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sun, 15 Nov 2020 15:55:09 +0000 Subject: [PATCH] 93_DbRep: values next_day_begin, next_day_end for time attributes git-svn-id: https://svn.fhem.de/fhem/trunk@23163 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/93_DbRep.pm | 350 ++++++++++++++++++++++++------------------ 2 files changed, 201 insertions(+), 150 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 4b105940b..4ea09cb5c 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: values next_day_begin, next_day_end for time attributes - feature: 23_LUXTRONIK2: new set parameter opModeVentilation - feature: 93_DbRep: new attrbute avgDailyMeanGWSwithGTS for Grassland temperature sum calculation diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index 8eb5c44e0..5a44f5ac1 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern my %DbRep_vNotesIntern = ( + "8.42.0" => "14.11.2020 new vals next_day_begin, next_day_end for time attr Forum: https://forum.fhem.de/index.php/topic,53584.msg1100040.html#msg1100040 ", "8.41.0" => "08.11.2020 new attrbute avgDailyMeanGWSwithGTS for Grassland temperature sum, minor bugfixes in create time array ", "8.40.8" => "17.09.2020 sqlCmd supports PREPARE statament Forum: #114293, commandRef revised ", "8.40.7" => "03.09.2020 rename getter dbValue to sqlCmdBlocking, consider attr timeout in function DbRep_sqlCmdBlocking (blocking function), commandRef revised ", @@ -735,8 +736,8 @@ sub DbRep_Set { } elsif ($opt =~ m/delEntries|tableCurrentPurge/ && $hash->{ROLE} ne "Agent") { $hash->{LASTCMD} = $prop?"$opt $prop":"$opt"; - delete $hash->{HELPER}{DELENTRIES}; - + delete $hash->{HELPER}{DELENTRIES}; + if (!AttrVal($hash->{NAME}, "allowDeletion", undef)) { return " Set attribute 'allowDeletion' if you want to allow deletion of any database entries. Use it with care !"; } @@ -989,12 +990,12 @@ sub DbRep_Get { } elsif ($opt =~ /sqlCmdBlocking|dbValue/) { return qq{get "$opt" needs at least an argument} if ( @a < 3 ); - - if($opt eq "dbValue") { - Log3($name, 1, qq{$name - WARNING - the command "dbValue" is deprecated and will be removed soon. Please use "sqlCmdBlocking" instead.}); - } - my @cmd = @a; + if($opt eq "dbValue") { + Log3($name, 1, qq{$name - WARNING - the command "dbValue" is deprecated and will be removed soon. Please use "sqlCmdBlocking" instead.}); + } + + my @cmd = @a; shift @cmd; shift @cmd; my $sqlcmd = join " ", @cmd; @@ -1302,7 +1303,7 @@ sub DbRep_Attr { if ($aName eq "timeYearPeriod") { # 06-01 02-28 - unless ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/ ) + unless ($aVal =~ /^(\d{2})-(\d{2})\s(\d{2})-(\d{2})$/x ) { return "The Value of \"$aName\" isn't valid. Set the account period as \"MM-DD MM-DD\".";} my ($mm1, $dd1, $mm2, $dd2) = ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/); my (undef,undef,undef,$mday,$mon,$year1,undef,undef,undef) = localtime(time); # Istzeit Ableitung @@ -1326,21 +1327,48 @@ sub DbRep_Attr { delete($attr{$name}{timestamp_end}) if ($attr{$name}{timestamp_end}); delete($attr{$name}{timeDiffToNow}) if ($attr{$name}{timeDiffToNow}); delete($attr{$name}{timeOlderThan}) if ($attr{$name}{timeOlderThan}); - return undef; + return; } if ($aName eq "timestamp_begin" || $aName eq "timestamp_end") { - my ($a,$b,$c) = split('_',$aVal); - if ($a =~ /^current$|^previous$/ && $b =~ /^hour$|^day$|^week$|^month$|^year$/ && $c =~ /^begin$|^end$/) { - delete($attr{$name}{timeDiffToNow}) if ($attr{$name}{timeDiffToNow}); - delete($attr{$name}{timeOlderThan}) if ($attr{$name}{timeOlderThan}); - delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod}); - return undef; + my @dtas = qw(current_year_begin + current_year_end + previous_year_begin + previous_year_end + current_month_begin + current_month_end + previous_month_begin + previous_month_end + current_week_begin + current_week_end + previous_week_begin + previous_week_end + current_day_begin + current_day_end + previous_day_begin + previous_day_end + next_day_begin + next_day_end + current_hour_begin + current_hour_end + previous_hour_begin + previous_hour_end + ); + + if ($aVal ~~ @dtas) { + delete($attr{$name}{timeDiffToNow}); + delete($attr{$name}{timeOlderThan}); + delete($attr{$name}{timeYearPeriod}); + return; } + $aVal = DbRep_formatpicker($aVal); - unless ($aVal =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) - {return " The Value of $aName is not valid. Use format YYYY-MM-DD HH:MM:SS or one of \"current_[year|month|day|hour]_begin\",\"current_[year|month|day|hour]_end\", \"previous_[year|month|day|hour]_begin\", \"previous_[year|month|day|hour]_end\" !";} + if ($aVal !~ /^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/x) + {return "The Value of $aName is not valid. Use format YYYY-MM-DD HH:MM:SS or one of:\n". + "current_[year|month|day|hour]_begin, current_[year|month|day|hour]_end,\n". + "previous_[year|month|day|hour]_begin, previous_[year|month|day|hour]_end,\n". + "next_day_begin, next_day_end";} - my ($yyyy, $mm, $dd, $hh, $min, $sec) = ($aVal =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/); + my ($yyyy, $mm, $dd, $hh, $min, $sec) = ($aVal =~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/x); eval { my $epoch_seconds_begin = timelocal($sec, $min, $hh, $dd, $mm-1, $yyyy-1900); }; @@ -1348,9 +1376,9 @@ sub DbRep_Attr { my @l = split (/at/, $@); return " The Value of $aName is out of range - $l[0]"; } - delete($attr{$name}{timeDiffToNow}) if ($attr{$name}{timeDiffToNow}); - delete($attr{$name}{timeOlderThan}) if ($attr{$name}{timeOlderThan}); - delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod}); + delete($attr{$name}{timeDiffToNow}); + delete($attr{$name}{timeOlderThan}); + delete($attr{$name}{timeYearPeriod}); } if ($aName =~ /ftpTimeout|timeout|diffAccept/) { unless ($aVal =~ /^[0-9]+$/) { return " The Value of $aName is not valid. Use only figures 0-9 without decimal places !";} @@ -1361,16 +1389,16 @@ sub DbRep_Attr { if ($aName eq "timeDiffToNow") { unless ($aVal =~ /^[0-9]+$/ || $aVal =~ /^\s*[ydhms]:([\d]+)\s*/ && $aVal !~ /.*,.*/ ) { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";} - delete($attr{$name}{timestamp_begin}) if ($attr{$name}{timestamp_begin}); - delete($attr{$name}{timestamp_end}) if ($attr{$name}{timestamp_end}); - delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod}); + delete($attr{$name}{timestamp_begin}); + delete($attr{$name}{timestamp_end}); + delete($attr{$name}{timeYearPeriod}); } if ($aName eq "timeOlderThan") { unless ($aVal =~ /^[0-9]+$/ || $aVal =~ /^\s*[ydhms]:([\d]+)\s*/ && $aVal !~ /.*,.*/ ) { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";} - delete($attr{$name}{timestamp_begin}) if ($attr{$name}{timestamp_begin}); - delete($attr{$name}{timestamp_end}) if ($attr{$name}{timestamp_end}); - delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod}); + delete($attr{$name}{timestamp_begin}); + delete($attr{$name}{timestamp_end}); + delete($attr{$name}{timeYearPeriod}); } if ($aName eq "dumpMemlimit" || $aName eq "dumpSpeed") { unless ($aVal =~ /^[0-9]+$/) { return "The Value of $aName is not valid. Use only figures 0-9 without decimal places.";} @@ -1991,10 +2019,10 @@ sub DbRep_Main { my $othants = fhemTimeLocal($sec2, $min2, $hh2, $dd2, $mm2-1, $yyyy2-1900); if($nthants > $othants) { ReadingsSingleUpdateValue ($hash, "state", "Error - Wrong time limits. The (days newer than) option must be greater than the (older than) one !", 1); - return; + return; } } - + $hash->{HELPER}{RUNNING_PID} = BlockingCall("del_DoParse", "$name|history|$device|$reading|$runtime_string_first|$runtime_string_next", "del_ParseDone", $to, "DbRep_ParseAborted", $hash); } elsif ($opt eq "tableCurrentPurge") { @@ -2091,14 +2119,14 @@ sub DbRep_Main { my ($yyyy2, $mm2, $dd2, $hh2, $min2, $sec2) = $runtime_string_next =~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/x; my $nthants = fhemTimeLocal($sec1, $min1, $hh1, $dd1, $mm1-1, $yyyy1-1900); my $othants = fhemTimeLocal($sec2, $min2, $hh2, $dd2, $mm2-1, $yyyy2-1900); - + if($nthants > $othants) { ReadingsSingleUpdateValue ($hash, "state", "Error - Wrong time limits. The (days newer than) option must be greater than the (older than) one !", 1); - return; + return; } $hash->{HELPER}{RUNNING_REDUCELOG} = BlockingCall("DbRep_reduceLog", "$name|$device|$reading|$runtime_string_first|$runtime_string_next", "DbRep_reduceLogDone", $to, "DbRep_reduceLogAborted", $hash); $hash->{HELPER}{RUNNING_REDUCELOG}{loglevel} = 5 if($hash->{HELPER}{RUNNING_REDUCELOG}); # Forum #77057 - ReadingsSingleUpdateValue ($hash, "state", "reduceLog database is running - be patient and see Logfile !", 1); + ReadingsSingleUpdateValue ($hash, "state", "reduceLog database is running - be patient and see Logfile !", 1); return; } @@ -2147,14 +2175,14 @@ sub DbRep_createTimeArray { my $dep = $4; my $c = ($mon+1).$mday; my $e = $mep.$dep; - + if ($mep <= $mbp && $c <= $e) { $ybp--; } - else { + else { $yep++; } - + $tsbegin = "$ybp-$mbp-$dbp 00:00:00"; $tsend = "$yep-$mep-$dep 23:59:59"; } @@ -2162,38 +2190,38 @@ sub DbRep_createTimeArray { if (AttrVal($name,"timestamp_begin","") eq "current_year_begin" || AttrVal($name,"timestamp_end","") eq "current_year_begin") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_begin","") eq "current_year_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "current_year_end" || AttrVal($name, "timestamp_end", "") eq "current_year_end") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_begin","") eq "current_year_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_end"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_year_begin" || AttrVal($name, "timestamp_end", "") eq "previous_year_begin") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_begin", "") eq "previous_year_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_year_end" || AttrVal($name, "timestamp_end", "") eq "previous_year_end") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_begin", "") eq "previous_year_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_end"); } if (AttrVal($name, "timestamp_begin", "") eq "current_month_begin" || AttrVal($name, "timestamp_end", "") eq "current_month_begin") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_month_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "current_month_end" || AttrVal($name, "timestamp_end", "") eq "current_month_end") { $dim = $mon-1?30+(($mon+1)*3%7<4):28+!($year%4||$year%400*!($year%100)); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_month_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_end"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_month_begin" || @@ -2201,7 +2229,7 @@ sub DbRep_createTimeArray { $ryear = ($mon-1<0)?$year-1:$year; $rmon = ($mon-1<0)?11:$mon-1; $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_month_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_month_end" || @@ -2210,7 +2238,7 @@ sub DbRep_createTimeArray { $rmon = ($mon-1<0)?11:$mon-1; $dim = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_month_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_end"); } if (AttrVal($name, "timestamp_begin", "") eq "current_week_begin" || @@ -2224,7 +2252,7 @@ sub DbRep_createTimeArray { $tsub = 518400 if($wday == 0); # wenn Start am "So" dann Korrektur -6 Tage ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "current_week_end" || @@ -2238,7 +2266,7 @@ sub DbRep_createTimeArray { $tadd = 0 if($wday == 0); # wenn Start am "So" keine Korrektur ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time+$tadd); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_end"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_week_begin" || @@ -2252,7 +2280,7 @@ sub DbRep_createTimeArray { $tsub = 1123200 if($wday == 0); # wenn Start am "So" dann Korrektur -13 Tage ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_week_end" || @@ -2266,21 +2294,35 @@ sub DbRep_createTimeArray { $tsub = 604800 if($wday == 0); # wenn Start am "So" dann Korrektur -7 Tage ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub); $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_end"); } if (AttrVal($name, "timestamp_begin", "") eq "current_day_begin" || AttrVal($name, "timestamp_end", "") eq "current_day_begin") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_day_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "current_day_end" || AttrVal($name, "timestamp_end", "") eq "current_day_end") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_day_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_end"); } + if (AttrVal($name, "timestamp_begin", "") eq "next_day_begin" || + AttrVal($name, "timestamp_end", "") eq "next_day_begin") { + ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time+86400); # Istzeit + 1 Tag + $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "next_day_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "next_day_begin"); + } + + if (AttrVal($name, "timestamp_begin", "") eq "next_day_end" || + AttrVal($name, "timestamp_end", "") eq "next_day_end") { + ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time+86400); # Istzeit + 1 Tag + $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "next_day_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "next_day_end"); + } + if (AttrVal($name, "timestamp_begin", "") eq "previous_day_begin" || AttrVal($name, "timestamp_end", "") eq "previous_day_begin") { $rmday = $mday-1; @@ -2295,7 +2337,7 @@ sub DbRep_createTimeArray { $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11) } $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_day_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_day_end" || @@ -2312,19 +2354,19 @@ sub DbRep_createTimeArray { $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11) } $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_day_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_end"); } if (AttrVal($name, "timestamp_begin", "") eq "current_hour_begin" || AttrVal($name, "timestamp_end", "") eq "current_hour_begin") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_hour_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "current_hour_end" || AttrVal($name, "timestamp_end", "") eq "current_hour_end") { $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_hour_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_end"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_hour_begin" || @@ -2346,7 +2388,7 @@ sub DbRep_createTimeArray { } } $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_hour_begin"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_begin"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_begin"); } if (AttrVal($name, "timestamp_begin", "") eq "previous_hour_end" || AttrVal($name, "timestamp_end", "") eq "previous_hour_end") { @@ -2354,7 +2396,7 @@ sub DbRep_createTimeArray { $rmday = $mday; $rmon = $mon; $ryear = $year; - + if($rhour<0) { $rhour = 23; $rmday = $mday-1; @@ -2367,9 +2409,9 @@ sub DbRep_createTimeArray { $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11) } } - + $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_hour_end"); - $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_end"); + $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_end"); } my ($yyyy1, $mm1, $dd1, $hh1, $min1, $sec1) = $tsbegin =~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/x; # extrahieren der Einzelwerte von Datum/Zeit Beginn @@ -6250,7 +6292,7 @@ sub sqlCmd_DoParse { my $vars = AttrVal($name, "sqlCmdVars", ""); if ($vars) { @pms = split(";",$vars); - + for my $pm (@pms) { if($pm !~ /PRAGMA|SET/i) { next; @@ -6273,7 +6315,7 @@ sub sqlCmd_DoParse { if($cmd =~ /^\s*SET.*;/i) { @pms = split(";",$cmd); $sql = q{}; - + for my $pm (@pms) { if($pm !~ /SET/i) { @@ -6301,7 +6343,7 @@ sub sqlCmd_DoParse { if($cmd =~ /^\s*PRAGMA.*;/i) { @pms = split(";",$cmd); $sql = q{}; - + for my $pm (@pms) { if($pm !~ /PRAGMA/i) { @@ -6328,7 +6370,7 @@ sub sqlCmd_DoParse { # z.B. PREPARE statement FROM @CMD if($sql =~ /^\s*PREPARE.*;/i) { @pms = split(";",$sql); - $sql = q{}; + $sql = q{}; for my $pm (@pms) { if($pm !~ /PREPARE/i) { @@ -13557,7 +13599,7 @@ return;

- +
  • dbstatus - lists global information about MySQL server status (e.g. informations related to cache, threads, bufferpools, etc. ). Initially all available informations are reported. Using the attribute showStatus the quantity of results can be limited to show only the desired values. Further detailed informations of items meaning are @@ -13578,16 +13620,16 @@ return; The timeout can be set with the attribute timeout.

    -
      - Examples:
      - { fhem("get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
      - { CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
      - get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device
      -
    +
      + Examples:
      + { fhem("get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
      + { CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
      + get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device
      +
  • -
    - - Because of its mode of operation this function is particular convenient for user own perl scripts.
    +
    + + Because of its mode of operation this function is particular convenient for user own perl scripts.
    The input accepts multi line commands and delivers multi line results as well. This command also accept the setting of SQL session variables like "SET @open:=NULL, @closed:=NULL;".
    @@ -13596,7 +13638,7 @@ return; are separated by newline ("\n").
    This function only set/update status readings, the userExitFn function isn't called.

    - + If you create a little routine in 99_myUtils, for example:
    @@ -13610,15 +13652,15 @@ sub dbval {
                                 it can be accessed with e.g. those calls: 
                                 

    -
      - Examples:
      - { dbval("<name>","select count(*) from history") }
      - $ret = dbval("<name>","select count(*) from history");
      -
    +
      + Examples:
      + { dbval("<name>","select count(*) from history") }
      + $ret = dbval("<name>","select count(*) from history");
      +


    - +
  • dbvars - lists global informations about MySQL system variables. Included are e.g. readings related to InnoDB-Home, datafile path, memory- or cache-parameter and so on. The Output reports initially all available informations. Using the attribute showVariables the quantity of results can be limited to show only the desired values. @@ -13634,14 +13676,14 @@ sub dbval {


  • - +
  • minTimestamp - Identifies the oldest timestamp in the database (will be executed implicitely at FHEM start). The timestamp is used as begin of data selection if no time attribut is set to determine the start date.


  • - +
  • procinfo - Reports the existing database processes in a summary table (only MySQL).
    Typically only the own processes of the connection user (set in DbLog configuration file) will be reported. If all precesses have to be reported, the global "PROCESS" right has to be granted to the @@ -13655,7 +13697,7 @@ sub dbval {

    -
  • storedCredentials - Reports the users / passwords stored for database access by the device.
    +
  • storedCredentials - Reports the users / passwords stored for database access by the device.
    (only valid if database type is MYSQL)


  • @@ -13694,7 +13736,7 @@ sub dbval {
  • versionNotes [hints | rel | <key>] - Shows realease informations and/or hints about the module. - +

      @@ -13707,10 +13749,10 @@ sub dbval {
  • - -
    - - It contains only main release informations for module users.
    + +
    + + It contains only main release informations for module users.
    If no options are specified, both release informations and hints will be shown. "rel" shows only release informations and "hints" shows only hints. By the <key>-specification only the hint with the specified number is shown. @@ -14308,6 +14350,8 @@ sub bdump { current_day_end : matches "<current day> 23:59:59"
    previous_day_begin : matches "<previous day> 00:00:00"
    previous_day_end : matches "<previous day> 23:59:59"
    + next_day_begin : matches "<next day> 00:00:00"
    + next_day_end : matches "<next day> 23:59:59"
    current_hour_begin : matches "<current hour>:00:00"
    current_hour_end : matches "<current hour>:59:59"
    previous_hour_begin : matches "<previous hour>:00:00"
    @@ -14340,6 +14384,8 @@ sub bdump { current_day_end : matches "<current day> 23:59:59"
    previous_day_begin : matches "<previous day> 00:00:00"
    previous_day_end : matches "<previous day> 23:59:59"
    + next_day_begin : matches "<next day> 00:00:00"
    + next_day_end : matches "<next day> 23:59:59"
    current_hour_begin : matches "<current hour>:00:00"
    current_hour_end : matches "<current hour>:59:59"
    previous_hour_begin : matches "<previous hour>:00:00"
    @@ -14777,12 +14823,12 @@ sub bdump { (nur gültig bei Datenbanktyp MYSQL und DbRep-Typ "Client")
    - +
  • averageValue [display | writeToDB | writeToDBSingle | writeToDBInTime] - berechnet einen Durchschnittswert des Datenbankfelds "VALUE" in den Zeitgrenzen der möglichen time.*-Attribute.

  • - + Es muss das auszuwertende Reading im Attribut reading angegeben sein. Mit dem Attribut averageCalcForm wird die Berechnungsvariante zur @@ -14800,7 +14846,7 @@ sub bdump {
    - + Der neue Readingname wird aus einem Präfix und dem originalen Readingnamen gebildet, wobei der originale Readingname durch das Attribut "readingNameMap" ersetzt werden kann. Der Präfix setzt sich aus der Bildungsfunktion und der Aggregation zusammen.
    @@ -14836,7 +14882,7 @@ sub bdump {
    - +
  • cancelDump - bricht einen laufenden Datenbankdump ab.

  • @@ -14846,7 +14892,7 @@ sub bdump { berücksichtigt wie gesetzte Zeitgrenzen (Attribute time.*).
    Fehlen diese Beschränkungen, wird die gesamte Datenbank durchsucht und der angegebene Wert geändert.

    - +
      Syntax:
      @@ -14866,10 +14912,10 @@ sub bdump { des Perl-Code geändert werden. Der zurückgebene Wert von $VALUE und $UNIT wird in dem Feld VALUE bzw. UNIT des Datensatzes gespeichert. -
    +
    -
      +
        Beispiele:
        set <name> changeValue "OL","12 OL"
        # der alte Feldwert "OL" wird in "12 OL" geändert.

        @@ -14907,18 +14953,18 @@ sub bdump {
      - +
    • countEntries [history | current] - liefert die Anzahl der Tabelleneinträge (default: history) in den gegebenen Zeitgrenzen (siehe Attribute). Sind die Timestamps nicht gesetzt, werden alle Einträge der Tabelle gezählt. Beschränkungen durch die Attribute device bzw. reading gehen in die Selektion mit ein.
      -
    • - + + Standardmäßig wird die Summe aller Datensätze, gekennzeichnet mit "ALLREADINGS", erstellt. Ist das Attribut "countEntriesDetail" gesetzt, wird die Anzahl jedes einzelnen Readings - zusätzlich ausgegeben.

      + zusätzlich ausgegeben.

      Die für diese Funktion relevanten Attribute sind:

      @@ -14938,14 +14984,14 @@ sub bdump {
      - +
    • delDoublets [adviceDelete | delete] - zeigt bzw. löscht doppelte / mehrfach vorkommende Datensätze. Dazu wird Timestamp, Device,Reading und Value ausgewertet.
      Die Attribute zur Aggregation,Zeit-,Device- und Reading-Abgrenzung werden dabei berücksichtigt. Ist das Attribut "aggregation" nicht oder auf "no" gesetzt, wird im Standard die Aggregation "day" verwendet.

      -
    • +
        @@ -14965,7 +15011,7 @@ sub bdump { beeinflusst NUR die Anzeige der Daten.
        Vor und nach der Ausführung von "delDoublets" kann ein FHEM-Kommando bzw. Perl-Routine ausgeführt werden. (siehe Attribute executeBeforeProc, executeAfterProc) -

        +

          Beispiel:

          @@ -16211,14 +16257,14 @@ sub bdump { Ergebnismenge eingeschränkt werden, um nur gewünschte Ergebnisse abzurufen. Detailinformationen zur Bedeutung der einzelnen Readings sind hier verfügbar.

          -
            - Beispiel
            - attr <name> showStatus %uptime%,%qcache%
            - get <name> dbstatus
            - # Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthaltenen -
          - -

          +
            + Beispiel
            + attr <name> showStatus %uptime%,%qcache%
            + get <name> dbstatus
            + # Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthaltenen +
          + +

        • sqlCmdBlocking <SQL-Statement> - @@ -16226,14 +16272,14 @@ sub bdump { Der Timeout kann mit dem Attribut timeout eingestellt werden.

          -
            - Beispiele:
            - { fhem("get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
            - { CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
            - get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device
            -
          +
            + Beispiele:
            + { fhem("get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
            + { CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") }
            + get <name> sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device
            +
        • -
          +
          Diese Funktion ist durch ihre Arbeitsweise speziell für den Einsatz in benutzerspezifischen Scripten geeignet.
          Die Eingabe akzeptiert Mehrzeiler und gibt ebenso mehrzeilige Ergebisse zurück. @@ -16246,7 +16292,7 @@ sub bdump { wird nicht aufgerufen.

          - Erstellt man eine kleine Routine in 99_myUtils, wie z.B.: + Erstellt man eine kleine Routine in 99_myUtils, wie z.B.:
           sub dbval {
          @@ -16259,12 +16305,12 @@ sub dbval {
                                       kann sqlCmdBlocking vereinfacht verwendet werden mit Aufrufen wie: 
                                       

          -
            - Beispiele:
            - { dbval("<name>","select count(*) from history") }
            - oder
            - $ret = dbval("<name>","select count(*) from history");
            -
          +
            + Beispiele:
            + { dbval("<name>","select count(*) from history") }
            + oder
            + $ret = dbval("<name>","select count(*) from history");
            +


          @@ -16275,14 +16321,14 @@ sub dbval { abzurufen. Weitere Informationen zur Bedeutung der ausgegebenen Variablen sind hier verfügbar.

          -
            - Beispiel
            - attr <name> showVariables %version%,%query_cache%
            - get <name> dbvars
            - # Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten -
          - -

          +
            + Beispiel
            + attr <name> showVariables %version%,%query_cache%
            + get <name> dbvars
            + # Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten +
          + +

        • minTimestamp - Ermittelt den Zeitstempel des ältesten Datensatzes in der Datenbank (wird implizit beim Start von @@ -16316,14 +16362,14 @@ sub dbval { Weitere Erläuterungen zu den gelieferten Informationen sind hier zu finden.

          -
            - Beispiel
            - attr <name> showSvrInfo %SQL_CATALOG_TERM%,%NAME%
            - get <name> svrinfo
            - # Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten -
          -
        • -

          +
            + Beispiel
            + attr <name> showSvrInfo %SQL_CATALOG_TERM%,%NAME%
            + get <name> svrinfo
            + # Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten +
          + +

        • tableinfo - ruft Tabelleninformationen aus der mit dem DbRep-Device verbundenen Datenbank ab (MySQL). @@ -16331,14 +16377,14 @@ sub dbval { Mit dem Attribut showTableInfo können die Ergebnisse eingeschränkt werden. Erläuterungen zu den erzeugten Readings sind hier zu finden.

          -
            - Beispiel
            - attr <name> showTableInfo current,history
            - get <name> tableinfo
            - # Es werden nur Information der Tabellen "current" und "history" angezeigt -
          -
        • -

          +
            + Beispiel
            + attr <name> showTableInfo current,history
            + get <name> tableinfo
            + # Es werden nur Information der Tabellen "current" und "history" angezeigt +
          + +

        • versionNotes [hints | rel | <key>] - @@ -16355,10 +16401,10 @@ sub dbval {
        - -
        - Sind keine Optionen angegeben, werden sowohl Release Informationen als auch Hinweise angezeigt. - Es sind nur Release Informationen mit Bedeutung für den Modulnutzer enthalten.
        + +
        + Sind keine Optionen angegeben, werden sowohl Release Informationen als auch Hinweise angezeigt. + Es sind nur Release Informationen mit Bedeutung für den Modulnutzer enthalten.

        @@ -16959,6 +17005,8 @@ sub bdump { current_day_end : entspricht "<aktueller Tag> 23:59:59"
        previous_day_begin : entspricht "<Vortag> 00:00:00"
        previous_day_end : entspricht "<Vortag> 23:59:59"
        + next_day_begin : entspricht "<nächster Tag> 00:00:00"
        + next_day_end : entspricht "<nächster Tag> 23:59:59"
        current_hour_begin : entspricht "<aktuelle Stunde>:00:00"
        current_hour_end : entspricht "<aktuelle Stunde>:59:59"
        previous_hour_begin : entspricht "<vorherige Stunde>:00:00"
        @@ -16990,6 +17038,8 @@ sub bdump { current_day_end : entspricht "<aktueller Tag> 23:59:59"
        previous_day_begin : entspricht "<Vortag> 00:00:00"
        previous_day_end : entspricht "<Vortag> 23:59:59"
        + next_day_begin : entspricht "<nächster Tag> 00:00:00"
        + next_day_end : entspricht "<nächster Tag> 23:59:59"
        current_hour_begin : entspricht "<aktuelle Stunde>:00:00"
        current_hour_end : entspricht "<aktuelle Stunde>:59:59"
        previous_hour_begin : entspricht "<vorherige Stunde>:00:00"