From dbd0752b49f30e6fa5fcddd59e4c40b00b345c61 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Wed, 15 Sep 2021 09:56:58 +0000 Subject: [PATCH] 76_Solarforcast: contrib 0.56.3 git-svn-id: https://svn.fhem.de/fhem/trunk@24976 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SolarForecast.pm | 78 ++++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index 6f09979ee..ba048bfe7 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -120,6 +120,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "0.56.3" => "15.09.2021 extent __calcEnergyPieces by MadMax calc (first test implementation) ", "0.56.2" => "14.09.2021 some fixes, new calculation of hourscsmeXX, new key minutescsmXX ", "0.56.1" => "12.09.2021 some fixes ", "0.56.0" => "11.09.2021 new Attr flowGraphicShowConsumer, extend calc consumer power consumption ", @@ -2622,9 +2623,11 @@ sub _manageConsumerData { my $chour = $paref->{chour}; my $day = $paref->{day}; my $daref = $paref->{daref}; - - my $nhour = $chour+1; - my $type = $hash->{TYPE}; + + my $type = $hash->{TYPE}; + + my $nhour = $chour+1; + $paref->{nhour} = $nhour; for my $c (sort{$a<=>$b} keys %{$data{$type}{$name}{consumers}}) { my $consumer = ConsumerVal ($hash, $c, "name", ""); @@ -2675,15 +2678,13 @@ sub _manageConsumerData { my $consumerco = $etot - $ehist; $consumerco += HistoryVal ($hash, $day, sprintf("%02d",$nhour), "csme${c}", 0); - $paref->{consumerco} = $consumerco; - $paref->{nhour} = sprintf("%02d",$nhour); # Verbrauch des Consumers aktuelle Stunde + $paref->{consumerco} = $consumerco; # Verbrauch des Consumers aktuelle Stunde $paref->{histname} = "csme${c}"; setPVhistory ($paref); delete $paref->{histname}; } $paref->{consumerco} = $etot; # Totalverbrauch des Verbrauchers - $paref->{nhour} = sprintf("%02d",$nhour); $paref->{histname} = "csmt${c}"; setPVhistory ($paref); delete $paref->{histname}; @@ -2741,13 +2742,11 @@ sub _manageConsumerData { } $paref->{val} = ConsumerVal ($hash, $c, "numberDayStarts", 0); # Anzahl Tageszyklen des Verbrauchers speichern - $paref->{nhour} = sprintf("%02d",$nhour); $paref->{histname} = "cyclescsm${c}"; setPVhistory ($paref); delete $paref->{histname}; $paref->{val} = ceil ConsumerVal ($hash, $c, "minutesOn", 0); # Verbrauchsminuten akt. Stunde des Consumers - $paref->{nhour} = sprintf("%02d",$nhour); $paref->{histname} = "minutescsm${c}"; setPVhistory ($paref); delete $paref->{histname}; @@ -2810,6 +2809,66 @@ sub __calcEnergyPieces { my $type = $hash->{TYPE}; + ## Ergänzung Max: epieces ermitteln + speichern + ################################################### + my $epiecHistCounts = 10; + + if(ConsumerVal ($hash, $c, "onoff", "off") eq "on") { + my $epiecHist = ""; + my $epiecHist_hours = ""; + my $etot = HistoryVal ($hash, $paref->{day}, sprintf("%02d",$paref->{nhour}), "csmt${c}", 0); + + if(ConsumerVal ($hash, $c, "epiecHour", 0) < 0) { #neue Aufzeichnung + $data{$type}{$name}{consumers}{$c}{epiecHist} += 1; + $data{$type}{$name}{consumers}{$c}{epiecHist} = 1 if(ConsumerVal ($hash, $c, "epiecHist", 0) > $epiecHistCounts); + + $epiecHist = "epiecHist_".ConsumerVal ($hash, $c, "epiecHist", 0); + delete $data{$type}{$name}{consumers}{$c}{$epiecHist}; # Löschen, wird neu erfasst + } + + $epiecHist = "epiecHist_".ConsumerVal ($hash, $c, "epiecHist", 0); + $epiecHist_hours = "epiecHist_".ConsumerVal ($hash, $c, "epiecHist", 0)."_hours"; + my $epiecHour = floor (ConsumerVal ($hash, $c, "minutesOn", 0) / 60) + 1; + + if(ConsumerVal ($hash, $c, "epiecHour", 0) != $epiecHour) { + my $epiecHour_last = $epiecHour - 1; + + $data{$type}{$name}{consumers}{$c}{$epiecHist}{$epiecHour_last} = $etot - ConsumerVal ($hash, $c, "epiecEstart", 0) if($epiecHour > 1); + $data{$type}{$name}{consumers}{$c}{epiecEstart} = $etot; + } + + $data{$type}{$name}{consumers}{$c}{$epiecHist}{$epiecHour} = $etot - ConsumerVal ($hash, $c, "epiecEstart", 0); + $data{$type}{$name}{consumers}{$c}{epiecHour} = $epiecHour; + $data{$type}{$name}{consumers}{$c}{$epiecHist_hours} = $epiecHour; + } + else { # Durchschnitt ermitteln + if(ConsumerVal ($hash, $c, "epiecHour", 0) > 0) { # Durchschnittliche Stunden ermitteln + my $hours = 0; + + for my $h (1..$epiecHistCounts) { + $hours += ConsumerVal ($hash, $c, "epiecHist_".$h."_hours", 0); + } + + $hours = ceil ($hours / $epiecHistCounts); + $data{$type}{$name}{consumers}{$c}{epiecAVG_hours} = $hours; + + delete $data{$type}{$name}{consumers}{$c}{epiecAVG}; # Durchschnitt für epics ermitteln + for my $hour (1..$hours) { + for my $h (1..$epiecHistCounts) { + my $epiecHist = "epiecHist_".$h; + + $data{$type}{$name}{consumers}{$c}{epiecAVG}{$hour} += $data{$type}{$name}{consumers}{$c}{$epiecHist}{$hour}; + } + + $data{$type}{$name}{consumers}{$c}{epiecAVG}{$hour} = $data{$type}{$name}{consumers}{$c}{epiecAVG}{$hour} / $epiecHistCounts; + } + } + + $data{$type}{$name}{consumers}{$c}{epiecHour} = -1; + } + + ###################################################################################################### + delete $data{$type}{$name}{consumers}{$c}{epieces}; my $cotype = ConsumerVal ($hash, $c, "type", $defctype ); @@ -6910,7 +6969,8 @@ return $def; # powerthreshold - Schwellenwert (Wh pro Stunde) ab der ein # Verbraucher als aktiv gewertet wird # upcurr - Unit des aktuellen Verbrauchs -# avgenergy - gemessener Durchschnittsverbrauch eines Tages +# avgenergy - initialer / gemessener Durchschnittsverbrauch +# eines Tages # epieces - prognostizierte Energiescheiben (Hash) # isConsumptionRecommended - ist Verbrauch empfohlen ? #