From deb0b30f41d905c754f254ed6bb04c949802ab62 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Tue, 4 Oct 2022 20:52:54 +0000 Subject: [PATCH] 76_SolarForecast.pm: contrib 0.68.5 git-svn-id: https://svn.fhem.de/fhem/trunk@26481 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SolarForecast.pm | 225 ++++++++++++++++---- 1 file changed, 185 insertions(+), 40 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index cef7ee52e..bb497b9bd 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -126,6 +126,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "0.68.5 "=> "03.10.2022 extent plant configuration check ", "0.68.4 "=> "03.10.2022 do ___setLastAPIcallKeyData if response_status, generate events of Today_MaxPVforecast.* in every cycle ". "add SolCast section in _graphicHeader, change default colors and settings, new reading Today_PVreal ". "fix sub __setConsRcmdState ", @@ -397,6 +398,8 @@ my %hqtxt = ( DE => qq{Stand:} }, autoct => { EN => qq{automatic correction:}, DE => qq{automatische Korrektur:} }, + plntck => { EN => qq{Plant Configurationcheck Information}, + DE => qq{Informationen zur Anlagenkonfigurationsprüfung} }, lbpcq => { EN => qq{correction quality current hour:}, DE => qq{Korrekturqualität akt. Stunde:} }, lblPvh => { EN => qq{next 4h:}, @@ -413,10 +416,12 @@ my %hqtxt = ( DE => qq{nach} }, pstate => { EN => qq{Planning status: 
On: 
Off: }, DE => qq{Planungsstatus: 
Ein: 
Aus: } }, - strok => { EN => qq{Congratulations 😊, your system configuration has been checked and is error-free !}, - DE => qq{Herzlichen Glückwunsch 😊, ihre Anlagenkonfiguration wurde geprüft und ist fehlerfrei !} }, - strnok => { EN => qq{Oh no 🙁, your string configuration is inconsistent.\nPlease check the settings !}, - DE => qq{Oh nein 🙁, Ihre String-Konfiguration ist inkonsistent.\nBitte überprüfen Sie die Einstellungen !} }, + strok => { EN => qq{Congratulations 😊, your system configuration has been checked and is error-free !}, + DE => qq{Herzlichen Glückwunsch 😊, ihre Anlagenkonfiguration wurde geprüft und ist fehlerfrei !} }, + strwn => { EN => qq{Looks quite good 😐, the check of the plant configuration showed only warnings !}, + DE => qq{Sieht ganz gut aus 😐, die Prüfung der Anlagenkonfiguration ergab nur Warnungen !} }, + strnok => { EN => qq{Oh no 🙁, your string configuration is inconsistent.\nPlease check the settings !}, + DE => qq{Oh nein 🙁, Ihre String-Konfiguration ist inkonsistent.\nBitte überprüfen Sie die Einstellungen !} }, ); my %htitles = ( # Hash Hilfetexte (Mouse Over) @@ -3602,7 +3607,7 @@ sub _calcMaxEstimateToday { my $paref = shift; my $hash = $paref->{hash}; my $name = $paref->{name}; - my $daref = $paref->{daref}; + my $daref = $paref->{daref}; my $type = $hash->{TYPE}; @@ -3614,12 +3619,12 @@ sub _calcMaxEstimateToday { for my $idx (sort keys %{$data{$type}{$name}{nexthours}}) { next if(!NexthoursVal ($hash, $idx, 'today', 0)); + my $stt = NexthoursVal ($hash, $idx, 'starttime', ''); + next if (!$stt); + my $pvfc = NexthoursVal ($hash, $idx, 'pvforecast', 0); next if($pvfc < $maxest); - my $stt = NexthoursVal ($hash, $idx, 'starttime', ''); - next if(!$stt); - $maxest = $pvfc; $maxtim = $stt; } @@ -8364,21 +8369,20 @@ sub checkPlantConfig { my $name = $hash->{NAME}; my $type = $hash->{TYPE}; - my $lang = AttrVal ("global", 'language', 'EN'); - - my $sc; - my $result = { 'stringconfig' => '', 'result' => '', 'state' => '', 'note' => '', 'fault' => 0 }; # Ergebnishash - my $cf = 0; # config fault: 1 -> Konfig fehlerhaft, 0 -> Konfig ok - - my $err = createStringConfig ($hash); - - if ($err) { - $cf = 1; - $sc .= $err."

"; - } - + my $lang = AttrVal ("global", 'language', 'EN'); my $stch = $data{$type}{$name}{strings}; - + my $cf = 0; # config fault: 1 -> Konfig fehlerhaft, 0 -> Konfig ok + my $wn = 0; # Warnung wenn 1 + + my $ok = FW_makeImage('10px-kreis-gruen.png', ''); + my $nok = FW_makeImage('10px-kreis-rot.png', ''); + my $warn = FW_makeImage('10px-kreis-gelb.png', ''); + + my $result = { # Ergebnishash + 'String Configuration' => { 'state' => $ok, 'result' => '', 'note' => '', 'fault' => 0 }, + 'DWD Weather Attributes' => { 'state' => $ok, 'result' => '', 'note' => '', 'fault' => 0 }, + }; + my $sub = sub { my $string = shift; my $ret; @@ -8390,48 +8394,189 @@ sub checkPlantConfig { return $ret; }; + + ## Check Strings + ################## + + my $err = createStringConfig ($hash); + + if ($err) { + $result->{'String Configuration'}{state} = $nok; + $result->{'String Configuration'}{result} = $err; + $result->{'String Configuration'}{fault} = 1; + } for my $sn (sort keys %{$stch}) { my $sp = $sn." => ".$sub->($sn)."
"; + $result->{'String Configuration'}{result} .= $sn." => ".$sub->($sn)."
"; - if (!isSolCastUsed ($hash)) { # Strahlungsdevice DWD - $cf = 1 if($sp !~ /dir.*?peak.*?tilt/x); # Test Vollständigkeit: z.B. Süddach => dir: S, peak: 5.13, tilt: 45 + if (!isSolCastUsed ($hash)) { # Strahlungsdevice DWD + $result->{'String Configuration'}{fault} = 1 if($sp !~ /dir.*?peak.*?tilt/x); # Test Vollständigkeit: z.B. Süddach => dir: S, peak: 5.13, tilt: 45 } - else { # Strahlungsdevice SolCast-API - $cf = 1 if($sp !~ /peak.*?pk/x); # Test Vollständigkeit + else { # Strahlungsdevice SolCast-API + $result->{'String Configuration'}{fault} = 1 if($sp !~ /peak.*?pk/x); # Test Vollständigkeit } - - $sc .= $sp; } - $sc .= "

"; + ## Check Attribute DWD Wetterdevice + ##################################### + my $fcname = ReadingsVal($name, 'currentForecastDev', ''); - if($cf) { - $sc .= encode ("utf8", $hqtxt{strnok}{$lang}); + if (!$fcname || !$defs{$fcname}) { + $result->{'DWD Weather Attributes'}{state} = $nok; + $result->{'DWD Weather Attributes'}{result} = qq{The DWD device "$fcname" doesn't exist}; + $result->{'DWD Weather Attributes'}{fault} = 1; } else { - $sc .= encode ("utf8", $hqtxt{strok}{$lang}); + $result->{'DWD Weather Attributes'}{note} = qq{checked attributes of device "$fcname":
}. join ' ', @dweattrmust; + $err = checkdwdattr ($name, $fcname, \@dweattrmust); + + if ($err) { + $result->{'DWD Weather Attributes'}{state} = $nok; + $result->{'DWD Weather Attributes'}{result} = $err; + $result->{'DWD Weather Attributes'}{fault} = 1; + } + else { + $result->{'DWD Weather Attributes'}{result} = 'fullfilled'; + } } + ## Check Attribute DWD Radiation Device + ######################################### + if (!isSolCastUsed ($hash)) { + $result->{'DWD Radiation Attributes'}{state} = $ok; + $result->{'DWD Radiation Attributes'}{result} = ''; + $result->{'DWD Radiation Attributes'}{note} = ''; + $result->{'DWD Radiation Attributes'}{fault} = 0; + + my $raname = ReadingsVal($name, 'currentRadiationDev', ''); + + if (!$raname || !$defs{$raname}) { + $result->{'DWD Radiation Attributes'}{state} = $nok; + $result->{'DWD Radiation Attributes'}{result} = qq{The DWD device "$raname" doesn't exist}; + $result->{'DWD Radiation Attributes'}{fault} = 1; + } + else { + $result->{'DWD Radiation Attributes'}{note} = qq{checked attributes of device "$raname":
}. join ' ', @draattrmust; + $err = checkdwdattr ($name, $raname, \@draattrmust); + + if ($err) { + $result->{'DWD Radiation Attributes'}{state} = $nok; + $result->{'DWD Radiation Attributes'}{result} = $err; + $result->{'DWD Radiation Attributes'}{fault} = 1; + } + else { + $result->{'DWD Radiation Attributes'}{result} = 'fullfilled'; + } + } + } + + ## Check Roof Ident Pair Settings + ################################### + if (isSolCastUsed ($hash)) { + $result->{'Roof Ident Pair Settings'}{state} = $ok; + $result->{'Roof Ident Pair Settings'}{result} = ''; + $result->{'Roof Ident Pair Settings'}{note} = ''; + $result->{'Roof Ident Pair Settings'}{fault} = 0; + + my $rft = ReadingsVal($name, "moduleRoofTops", ""); + my ($a,$h) = parseParams ($rft); + + while (my ($is, $pk) = each %$h) { + my $rtid = SolCastAPIVal ($hash, '?IdPair', '?'.$pk, 'rtid', ''); + my $apikey = SolCastAPIVal ($hash, '?IdPair', '?'.$pk, 'apikey', ''); + + if(!$rtid || !$apikey) { + my $res = qq{String "$is" has no Roof Ident Pair "$pk" defined or has no Rooftop-ID and/or SolCast-API key assigned.
}; + my $note = qq{Set the Roof Ident Pair "$pk" with "set $name roofIdentPair".
}; + + $result->{'Roof Ident Pair Settings'}{state} = $nok; + $result->{'Roof Ident Pair Settings'}{result} .= $res; + $result->{'Roof Ident Pair Settings'}{note} .= $note; + $result->{'Roof Ident Pair Settings'}{fault} = 1; + } + else { + $result->{'Roof Ident Pair Settings'}{result} = 'fullfilled' if(!$result->{'Roof Ident Pair Settings'}{fault}); + $result->{'Roof Ident Pair Settings'}{note} .= qq{checked "$is" Roof Ident Pair "$pk":
rtid=$rtid, apikey=$apikey
}; + } + } + } + + ## Attr. Settings für SolCast + ############################### + if (isSolCastUsed ($hash)) { + $result->{'SolCast Settings'}{state} = $ok; + $result->{'SolCast Settings'}{result} = ''; + $result->{'SolCast Settings'}{note} = ''; + $result->{'SolCast Settings'}{warn} = 0; + + my $cfd = AttrVal ($name, 'cloudFactorDamping', ''); + my $rfd = AttrVal ($name, 'rainFactorDamping', ''); + my $pcf = ReadingsVal ($name, 'pvCorrectionFactor_Auto', ''); + + if ($cfd eq '' || $cfd != 0) { + $result->{'SolCast Settings'}{state} = $warn; + $result->{'SolCast Settings'}{result} .= qq{Attribute cloudFactorDamping is set to "$cfd"
}; + $result->{'SolCast Settings'}{note} .= qq{It is recommended to set cloudFactorDamping explicitly to "0"
}; + $result->{'SolCast Settings'}{warn} = 1; + } + + if ($rfd eq '' || $rfd != 0) { + $result->{'SolCast Settings'}{state} = $warn; + $result->{'SolCast Settings'}{result} .= qq{Attribute rainFactorDamping is set to "$rfd"
}; + $result->{'SolCast Settings'}{note} .= qq{It is recommended to set rainFactorDamping explicitly to "0"
}; + $result->{'SolCast Settings'}{warn} = 1; + } + + if (!$pcf || $pcf ne 'off') { + $result->{'SolCast Settings'}{state} = $warn; + $result->{'SolCast Settings'}{result} .= qq{pvCorrectionFactor_Auto is set to "$pcf"
}; + $result->{'SolCast Settings'}{note} .= qq{It is recommended to set pvCorrectionFactor_Auto to "off"
}; + $result->{'SolCast Settings'}{warn} = 1; + } + + $result->{'SolCast Settings'}{result} = 'fullfilled' if(!$result->{'SolCast Settings'}{warn}); + } + + ## Ausgabe + ############ + my $out = qq{}; - $out .= qq{Plant Configuration check Info

}; + $out .= qq{}.$hqtxt{plntck}{$lang}.qq{

}; + $out .= qq{}; - $out .= qq{}; - $out .= qq{}; + $out .= qq{}; + $out .= qq{}; for my $key (sort keys %{$result}) { + $cf = $result->{$key}{fault} if($result->{$key}{fault}); + $wn = $result->{$key}{warn} if($result->{$key}{warn}); $out .= qq{}; - $out .= qq{}; - $out .= qq{}; - $out .= qq{}; - $out .= qq{}; + $out .= qq{}; + $out .= qq{}; + $out .= qq{}; + $out .= qq{}; $out .= qq{}; + + $out .= qq{}; } $out .= qq{
Object Result State Note
Object State Result Note
$result->{stringconfig} $result->{result} $result->{state} $result->{note} $key $result->{$key}{state} $result->{$key}{result} $result->{$key}{note}
}; $out .= qq{}; + + $out .= "

"; + + if($cf) { + $out .= encode ("utf8", $hqtxt{strnok}{$lang}); + } + elsif ($wn) { + $out .= encode ("utf8", $hqtxt{strwn}{$lang}); + } + else { + $out .= encode ("utf8", $hqtxt{strok}{$lang}); + } -return $sc; +return $out; } ################################################################