From b054377ad9d2ba1fc9b1301c2179f29ede525d56 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sat, 12 Jun 2021 07:03:47 +0000 Subject: [PATCH] 76_SolarForecast.pm: contrib 0.52.0 git-svn-id: https://svn.fhem.de/fhem/trunk@24614 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SolarForecast.pm | 177 +++++++++++--------- 1 file changed, 99 insertions(+), 78 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index 072fd3f56..5040b1ef5 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -51,6 +51,7 @@ BEGIN { AnalyzePerlCommand AttrVal AttrNum + CommandAttr CommandSet CommandSetReading data @@ -118,6 +119,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "0.52.0" => "12.06.2021 new Attr Css ", "0.51.3" => "10.06.2021 more refactoring, add 'none' to graphicSelect ", "0.51.2" => "05.06.2021 minor fixes ", "0.51.1" => "04.06.2021 minor fixes ", @@ -473,6 +475,21 @@ my $defcmode = "can"; my $defflowGSize = 300; # default flowGraphicSize + # Default CSS-Style +my $cssdef = qq{.flowg.text { stroke: none; fill: gray; } \n}. + qq{.flowg.sun_active { stroke: orange; fill: orange; } \n}. + qq{.flowg.sun_inactive { stroke: gray; fill: gray; } \n}. + qq{.flowg.bat25 { stroke: red; fill: red; } \n}. + qq{.flowg.bat50 { stroke: yellow; fill: yellow; } \n}. + qq{.flowg.bat75 { stroke: green; fill: green; } \n}. + qq{.flowg.grid_color1 { fill: green; } \n}. + qq{.flowg.grid_color2 { fill: red; } \n}. + qq{.flowg.grid_color3 { fill: gray; } \n}. + qq{.flowg.inactive_in { stroke: gray; stroke-dashoffset: 20; stroke-dasharray: 10; opacity: 0.2; } \n}. + qq{.flowg.inactive_out { stroke: gray; stroke-dashoffset: 20; stroke-dasharray: 10; opacity: 0.2; } \n}. + qq{.flowg.active_in { stroke: red; stroke-dashoffset: 20; stroke-dasharray: 10; opacity: 0.8; animation: dash 0.5s linear; animation-iteration-count: infinite; } \n}. + qq{.flowg.active_out { stroke: yellow; stroke-dashoffset: 20; stroke-dasharray: 10; opacity: 0.8; animation: dash 0.5s linear; animation-iteration-count: infinite; } \n} + ; my %hef = ( # Energiedaktoren für Verbrauchertypen "heater" => { tot => 1.00, f => 0.30, m => 0.40, l => 0.30, mt => 240 }, # tot = Faktor nominaler Gesamtenergieverbrauch @@ -528,6 +545,7 @@ sub Initialize { "consumerLegend:none,icon_top,icon_bottom,text_top,text_bottom ". # "consumerAdviceIcon ". "cloudFactorDamping:slider,0,1,100 ". + "Css:textField-long ". "disable:1,0 ". "flowGraphicSize ". "flowGraphicAnimate:1,0 ". @@ -607,6 +625,8 @@ sub Define { _readCacheFile ($params); readingsSingleUpdate($hash, "state", "initialized", 1); + + CommandAttr (undef,"$name Css $cssdef"); # Css Attribut vorbelegen centralTask ($hash); # Einstieg in Abfrage InternalTimer (gettimeofday()+$whistrepeat, "FHEM::SolarForecast::periodicWriteCachefiles", $hash, 0); # Einstieg periodisches Schreiben historische Daten @@ -4442,8 +4462,13 @@ sub _beamGraphic { last if ($ii > $maxhours); # ToDo : weather_icon sollte im Fehlerfall Title mit der ID besetzen um in FHEMWEB sofort die ID sehen zu können if (exists($hfcg->{$i}{weather}) && defined($hfcg->{$i}{weather})) { - my ($icon_name, $title) = $hfcg->{$i}{weather} > 100 ? weather_icon($hfcg->{$i}{weather}-100) : weather_icon($hfcg->{$i}{weather}); - Log3 ($name, 4, "$name - unknown weather id: ".$hfcg->{$i}{weather}.", please inform the maintainer") if($icon_name eq 'unknown'); + my ($icon_name, $title) = $hfcg->{$i}{weather} > 100 ? + weather_icon($hfcg->{$i}{weather}-100) : + weather_icon($hfcg->{$i}{weather}); + + if($icon_name eq 'unknown') { + Log3 ($name, 4, "$name - unknown weather id: ".$hfcg->{$i}{weather}.", please inform the maintainer"); + } $icon_name .= ($hfcg->{$i}{weather} < 100 ) ? '@'.$colorw : '@'.$colorwn; $val = FW_makeImage($icon_name); @@ -4475,7 +4500,12 @@ sub _beamGraphic { last if ($ii > $maxhours); # vorzeitiger Abbruch $val = formatVal6($hfcg->{$i}{diff},$kw,$hfcg->{$i}{weather}); - $val = ($hfcg->{$i}{diff} < 0) ? ''.$val.'' : ($val>0) ? '+'.$val : $val; # negative Zahlen in Fettschrift, 0 aber ohne + + $val = $hfcg->{$i}{diff} < 0 ? + ''.$val.'' : + $val > 0 ? + '+'.$val : + $val; # negative Zahlen in Fettschrift, 0 aber ohne + + $ret .= "$val"; } $ret .= ""; # freier Platz am Ende @@ -4529,7 +4559,8 @@ sub _beamGraphic { $z3 = int($height - $he - $z2); # was von maxVal noch übrig ist if ($z3 < int($fsize/2)) { # dünnen Strichbalken vermeiden / ca. halbe Zeichenhöhe - $z2 += $z3; $z3 = 0; + $z2 += $z3; + $z3 = 0; } } @@ -4732,40 +4763,37 @@ return $ret; # Energieflußgrafik ################################################################ sub _flowGraphic { - my $paref = shift; - my $name = $paref->{name}; - my $flowgh = $paref->{flowgh}; - my $flowgani = $paref->{flowgani}; + my $paref = shift; + my $name = $paref->{name}; + my $flowgh = $paref->{flowgh}; + my $flowgani = $paref->{flowgani}; my $style = 'width:'.$flowgh.'px; height:'.$flowgh.'px;'; - my $fs = ($flowgh < 300) ? '48px' : '32px'; + my $fs = $flowgh < 300 ? '48px' : '32px'; my $animation = $flowgani ? '@keyframes dash { to { stroke-dashoffset: 0; } }' : ''; # Animation Ja/Nein - - my $inactive = 'stroke-dashoffset: 20; stroke-dasharray: 10; opacity: 0.2;'; - my $active = 'stroke-dashoffset: 20; stroke-dasharray: 10; animation: dash 0.5s linear; animation-iteration-count: infinite; opacity: 0.8;' ; + my $css = AttrVal($name, 'Css', $cssdef); my $cpv = ReadingsNum($name, 'Current_PV', 0); - my $sun_color = $cpv ? 'orange' : 'gray'; + my $sun_color = $cpv ? 'flowg sun_active' : 'flowg sun_inactive'; my $cgc = ReadingsNum($name, 'Current_GridConsumption', 0); - my $cgc_style = $cgc ? $active : $inactive; - my $cgc_color = $cgc ? 'red' : 'gray'; + my $cgc_style = $cgc ? 'flowg active_in' : 'flowg inactive_in'; my $cgfi = ReadingsNum($name, 'Current_GridFeedIn', 0); - my $cgfi_style = $cgfi ? $active : $inactive; - my $cgfi_color = $cgfi ? 'yellow' : 'gray'; + my $cgfi_style = $cgfi ? 'flowg active_out' : 'flowg inactive_out'; my $csc = ReadingsNum($name, 'Current_SelfConsumption', 0); - my $csc_style = $csc ? $active : $inactive; - my $csc_color = $csc ? 'yellow' : 'gray'; + my $csc_style = $csc ? 'flowg active_out' : 'flowg inactive_out'; my $batin = ReadingsNum($name, 'Current_PowerBatIn', undef); my $batout = ReadingsNum($name, 'Current_PowerBatOut', undef); - my $soc = ReadingsNum($name, 'Current_BatCharge', -1); - my $batcolor = ($soc < 0) ? 'grey' : ($soc < 26) ? 'red' : ($soc < 76) ? 'yellow' : 'green'; + my $soc = ReadingsNum($name, 'Current_BatCharge', 100); + my $bat_color = $soc < 26 ? 'flowg bat25' : + $soc < 76 ? 'flowg bat50' : + 'flowg bat75'; + my $hasbat = 1; - $soc = q{} if($soc < 0); if (!defined($batin) && !defined($batout)) { $hasbat = 0; @@ -4774,56 +4802,53 @@ sub _flowGraphic { $soc = 0; } - my $batin_style = $batin ? $active : $inactive; - my $batin_color = $batin ? 'yellow' : 'gray'; - my $batout_style = $batout ? $active : $inactive; - my $batout_color = $batout ? 'yellow' : 'gray'; - - my $grid_color = $cgfi ? 'green' : 'red'; - $grid_color = 'gray' if (!$cgfi && !$cgc && $batout); # dritte Farbe + my $batin_style = $batin ? 'flowg active_out' : 'flowg inactive_out'; + my $batout_style = $batout ? 'flowg active_in' : 'flowg inactive_in'; + my $grid_color = $cgfi ? 'flowg grid_color1' : 'flowg grid_color2'; + $grid_color = 'flowg grid_color3' if (!$cgfi && !$cgc && $batout); # dritte Farbe my $ret; - #$ret .= qq{}; - #$ret .= qq{}; - #$ret .= qq{
}; - #$ret .= qq{}; - #$ret .= qq{}; - #$ret .= qq{
}; - + $ret .= qq{ + - + - + - + - + - + - + - + - + - + - + - + - + }; @@ -4831,11 +4856,11 @@ sub _flowGraphic { if ($hasbat) { $ret .= qq{ - + }; - + $ret .= '' if ($soc > 12); $ret .= '' if ($soc > 38); $ret .= '' if ($soc > 63); @@ -4843,40 +4868,28 @@ sub _flowGraphic { $ret .= ''; } - $ret .= qq{ - - - - }; + $ret .= qq{ + + + + + }; - $ret .= qq{$csc} if ($csc); - $ret .= qq{$cpv} if ($cpv); - $ret .= qq{' : 'start;">'; - - $ret .= $cgfi if ($cgfi); - - $ret .= qq{}; - $ret .= qq{$cgc} if ($cgc); + $ret .= qq{ + + + } if ($hasbat); - if ($hasbat) { - $ret .= qq{ - - - $soc % - }; - - $ret .= qq{$batout} if ($batout); - $ret .= qq{$batin} if ($batin); - } + $ret .= qq{$cpv} if ($cpv); + $ret .= qq{$soc %} if ($hasbat); + $ret .= qq{$csc} if ($csc); + $ret .= qq{$cgfi} if ($cgfi); + $ret .= qq{$cgc} if ($cgc); + $ret .= qq{$batout} if ($batout && $hasbat); + $ret .= qq{$batin} if ($batin && $hasbat); $ret .= qq{}; - #$ret .= qq{
}; - #$ret .= qq{
}; return $ret; } @@ -7043,6 +7056,12 @@ Ein/Ausschaltzeiten sowie deren Ausführung vom SolarForecast Modul übernehmen
+ + +
  • Css
    + Definiert den Style für die Energieflußgrafik. Das Attribut wird mit einem Default automatisch vorbelegt.
    +
  • +
  • disable
    @@ -7092,7 +7111,9 @@ Ein/Ausschaltzeiten sowie deren Ausführung vom SolarForecast Modul übernehmen
  • graphicSelect
    - Wählt die anzuzeigende interne Grafik des Moduls aus.

    + Wählt die anzuzeigende interne Grafik des Moduls aus.
    + Zur Anpassung der Energieflußgrafik steht das Attribut Css zur + Verfügung.