SMA Sunny Home Manager abfragen.

Begonnen von Brun, 07 Oktober 2014, 10:40:34

Vorheriges Thema - Nächstes Thema

Wzut

ist ja lustig, als ich das gestern Morgen gesehen habe konnte ich ich auch nicht die Finger davon lassen :)
Ich habe es als Funktion in die 99_myUtils gepackt, den Code vereinfacht und die Darstellung etwas auf meinen Geschmack angepasst.
Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher

DS_Starter

#361
Moin Wzut,

so kanns gehen.  :) Ist aber wirklich eine schöne Idee von saschab.
Ich will auch noch Anpassungsmöglichkeiten für Farben einbauen und den Code stark einlkürzen. Weiß aber nicht ob ich das vor meinem Urlaub noch schaffe, eher nicht. Wollte gestern nur erstmal diese Möglichkeit integrieren.
Aber wenn du magst, gibst du deinen Code mal bekannt und ich baue es als weiteren Style ins Modul ein.

LG,
Heiko
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

Wzut

Bitteschön :)

Was habe ich geändert :
a. die Stunden nach unten verschoben und diese zähle ich nicht mehr nur stur durch, sondern verwende das jeweilige Reading _Time. So stimmen die Stunden auch wenn die Werte mal nicht geholt werden konnten. Leider war das etwas mehr Aufwand, da die SMA Zeitwerte auf GMT basieren und sich durch unsere Zeitzone und Sommerzeit eine Verschiebung ergibt. ( z.Z 2 Stunden )
b. Die Höhe der Balken passt sich an den max Ertrag an , so hat man im Winter auch ordenliche Balken und keine Bodendecker
c. Wenn kein Ertrag zu erwarten ist beträgt die Balkenbreite nur 25% (24px vs. 6px) , das macht die Nacht schön schmal und schafft Raum am Tag.
d. Ich habe mal wieder gemerkt das ich mich bisher viel zuwenig um FHEM Styles  und CSS gekümmert habe, das war ein echter Krampf bis ich die Balken unten sauber auf einer Linie hatte weil in FHEM die Tabellen per default abgerundete Ecken haben. Die hellgraue Farbe der Balken passt jetzt nur zum DarkStyle.




sub SMA_Portal_G($)
{
my $name = shift;
my $i;
my @p;
my @r;
my @t;
my $t;
my $maxVal;        # max Ertrag in den nächsten 24 Stunden
my $he;            # Balkenhöhe
my $space  =   1;  # Platz zwischen den Balken
my $width  =  24;  # Breite der Balken , 24 max , 6 min
my $height = 200;  # Höhe der Balken
my $fsize  =  20;  # Höhe für Font
my $color  = "#7F7F7F"; # Farbe des Wertes , ggf dyn ermitteln aus Device WEB styleData cols.Header
#my $icon   = "/fhem/images/default/10px-kreis-gruen.png";
my $icon   = "/fhem/images/openautomation/light_light_dim_100.svg";
my (undef,undef,$h,undef,undef,undef,undef,undef,undef) = localtime(time);
my (undef,undef,$g,undef,undef,undef,undef,undef,undef) = gmtime(time);

my $td  = $h-$g; # Zeitversatz zwischen jetzt + Sommer/Winterzeit und GMT

# Sonderfall aktuelle Stunde
$p[0] = ReadingsNum($name,"L2_ThisHour_PvMeanPower",0);
$r[0] = (ReadingsVal($name,"L2_ThisHour_IsConsumptionRecommended",'no') eq 'yes' ) ? $icon : undef;
(undef,undef,undef,$t) = ReadingsVal($name,"L2_ThisHour_Time",'0') =~ m!(\d{4})-(\d{2})-(\d{2})\s(\d{2})!;
$t    = int($t-$td);
$t[0] = ($t < 0) ? $t+24 : $t;

$maxVal = $p[0]; # nehmen wir mal als Startwert

for ($i=1; $i<=23; $i++)
{
$p[$i]  = ReadingsNum($name,"L4_NextHour".sprintf("%02d",$i)."_PvMeanPower",0);
$maxVal = ($p[$i] > $maxVal) ? $p[$i]  : $maxVal;
$r[$i]  = (ReadingsVal($name,"L4_NextHour".sprintf("%02d",$i)."_IsConsumptionRecommended",'no') eq 'yes') ? $icon : undef;
(undef,undef,undef,$t)  = ReadingsVal($name,"L4_NextHour".sprintf("%02d",$i)."_Time",'0') =~ m!(\d{4})-(\d{2})-(\d{2})\s(\d{2})!;
$t      = int($t-$td);
$t[$i]  = ($t < 0) ? $t+24 : $t;
}

my $html = "<html><table><tr>
<td colspan='24'> Prognose der n&auml;chsten 4 h: ".ReadingsNum($name,"L2_Next04Hours-PV",0)." Wh / Rest des Tages: ".ReadingsNum($name,"L3_RestOfDay-PV",0)." Wh / Morgen: ".ReadingsNum($name,"L3_Tomorrow-PV",0)." Wh</td></tr><tr style='height:".$height."px;'>";

for ($i=0; $i<=23; $i++)
{
$he     = int(($maxVal-$p[$i])/$maxVal*$height) + $fsize;
$space  = ($p[$i]) ?  1 : 0;
$width  = ($p[$i]) ? 24 : 6;
$p[$i]  = "&nbsp;" if (!$p[$i]); # keine Anzeige bei Null

$html .= "<td style='width:".$width."px; height:".($height+$fsize)."px; padding-right:".$space."px; padding-left:".$space."px'>
<table>
<tr style='height:".$he."px'><td style='vertical-align:bottom'>".$p[$i]."</td></tr>";

if ($he < ($height+$fsize))
{
$html .= "<tr style='height:".($height+20-$he)."px;'><td style='background-color:".$color."; padding-bottom:0px; padding-top:1px; vertical-align:top'>";
$html .="<img src='".$r[$i]."' height='".$fsize."'/>" if (defined($r[$i]));
$html .="</td></tr>";
}

$html .= "<tr><td>".$t[$i]."</td></tr>";
$html .= "</table></td>";
}

$html .= "</tr></table></html>";

return $html;
}
Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher

Xguide

Guten Tag zusammen,

hey eure schönen Bildchen haben mich heute auch mal dazu bewegt SMAPortal zu integrieren.
Danke für die tolle Arbeit. Wzuts Design gefällt mir richtig gut, da es prima zum darkstyle passt.

Aktuell vermisse ich zwei Readings die ich zuvor genutzt habe, hast Du die mit Absicht weggelassen Heiko?

- Forecast-Today-PV
- Forecast-Today-Consumption

Grüße Marcel
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

DS_Starter

Hallo ihr zwei,

danke Wzut  :D
Gebe Marcel recht, dein Style ist echt super und gefällt mir natürlich ebenfalls sehr gut. Bin auch nicht so der HTML-CSS Fan und muss da immer viel recherchieren.
Vielelicht schaffe ich es noch vor meinem Urlaub schön zu integrieren, bin schon mitten in den Vorbereitungen  ;)

@Marcel,  habe nichts bewusst weggelassen. Ist mir dann bestimmt durchgerutscht. Das war sicher imm Forecastmodul ...

LG,
Heiko
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

Xguide

Hallo Heiko,
genau im Forecast war es.

Vielleicht magst Du es mit aufnehmen, ich habe es mal quick and dirty erweitert. Die Readings könnten sicher vom Namen noch besser angepasst werden.

  my $PV_sum = 0;
  my $consum_sum = 0;
  # Loop through all forecast objects
  # Energie wird als "J" geliefert, Wh = J / 3600
  foreach my $fc_obj (@{$forecast->{'ForecastSeries'}}) {
      # Example for DateTime: 2016-02-15T23:00:00
      my $fc_datetime = $fc_obj->{'TimeStamp'}->{'DateTime'};

      # Calculate Unix timestamp (month begins at 0, year at 1900)
      my ($fc_year, $fc_month, $fc_day, $fc_hour) = $fc_datetime =~ /^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):00:00$/;
      my $fc_uts          = POSIX::mktime( 0, 0, $fc_hour,  $fc_day, $fc_month - 1, $fc_year - 1900 );
      my $fc_diff_seconds = $fc_uts - time + 3600;  # So we go above 0 for the current hour                                                                       
      my $fc_diff_hours   = int( $fc_diff_seconds / 3600 );

  #MS - to keep known readings from former moduls, implementation of an integrator for daily PV and Consumption forecast
  if ( $current_day == $fc_day ) {
        $PV_sum += int($fc_obj->{'PvMeanPower'}->{'Amount'});
$consum_sum += int($fc_obj->{'ConsumptionForecast'}->{'Amount'}/3600);
  }

      # Don't use old data
      next if $fc_diff_seconds < 0;

      # Sum up for the next few hours (4 hours total, this is current hour plus the next 3 hours)
      if ($obj_nr < 4) {
         $nextFewHoursSum{'PV'}            += $fc_obj->{'PvMeanPower'}->{'Amount'};
         $nextFewHoursSum{'Consumption'}   += $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600;
         $nextFewHoursSum{'Total'}         += $fc_obj->{'PvMeanPower'}->{'Amount'} - $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600;
         $nextFewHoursSum{'ConsumpRcmd'}   += $fc_obj->{'IsConsumptionRecommended'} ? 1 : 0;
      }

      # If data is for the rest of the current day
      if ( $current_day == $fc_day ) {
         $restOfDaySum{'PV'}            += $fc_obj->{'PvMeanPower'}->{'Amount'};
         $restOfDaySum{'Consumption'}   += $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600;
         $restOfDaySum{'Total'}         += $fc_obj->{'PvMeanPower'}->{'Amount'} - $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600;
         $restOfDaySum{'ConsumpRcmd'}   += $fc_obj->{'IsConsumptionRecommended'} ? 1 : 0;
      }
     
      # If data is for the next day (quick and dirty: current day different from this object's day)
      # Assuming only the current day and the next day are returned from Sunny Portal
      if ( $current_day != $fc_day ) {
         $tomorrowSum{'PV'}            += $fc_obj->{'PvMeanPower'}->{'Amount'} if(exists($fc_obj->{'PvMeanPower'}->{'Amount'}));
         $tomorrowSum{'Consumption'}   += $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600;
         $tomorrowSum{'Total'}         += $fc_obj->{'PvMeanPower'}->{'Amount'} - $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600 if ($fc_obj->{'PvMeanPower'}->{'Amount'});
         $tomorrowSum{'ConsumpRcmd'}   += $fc_obj->{'IsConsumptionRecommended'} ? 1 : 0;
      }
     
      # Update values in Fhem if less than 24 hours in the future
      if($dl >= 2) {
          if ($obj_nr < 24) {
              my $time_str = "ThisHour";
              $time_str = "NextHour".sprintf("%02d", $obj_nr) if($fc_diff_hours>0);
              if($time_str =~ /NextHour/ && $dl >= 4) {
                  readingsBulkUpdate( $hash, "L4_${time_str}_Time", UTC2LocalString($hash,$fc_obj->{'TimeStamp'}->{'DateTime'}) );
                  readingsBulkUpdate( $hash, "L4_${time_str}_PvMeanPower", int( $fc_obj->{'PvMeanPower'}->{'Amount'} ) );
                  readingsBulkUpdate( $hash, "L4_${time_str}_Consumption", int( $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600 ) );
                  readingsBulkUpdate( $hash, "L4_${time_str}_IsConsumptionRecommended", ($fc_obj->{'IsConsumptionRecommended'} ? "yes" : "no") );
                  readingsBulkUpdate( $hash, "L4_${time_str}", int( $fc_obj->{'PvMeanPower'}->{'Amount'} - $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600 ) );
              }
              if($time_str =~ /ThisHour/ && $dl >= 2) {
                  readingsBulkUpdate( $hash, "L2_${time_str}_Time", UTC2LocalString($hash,$fc_obj->{'TimeStamp'}->{'DateTime'}) );
                  readingsBulkUpdate( $hash, "L2_${time_str}_PvMeanPower", int( $fc_obj->{'PvMeanPower'}->{'Amount'} ) );
                  readingsBulkUpdate( $hash, "L2_${time_str}_Consumption", int( $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600 ) );
                  readingsBulkUpdate( $hash, "L2_${time_str}_IsConsumptionRecommended", ($fc_obj->{'IsConsumptionRecommended'} ? "yes" : "no") );
                  readingsBulkUpdate( $hash, "L2_${time_str}", int( $fc_obj->{'PvMeanPower'}->{'Amount'} - $fc_obj->{'ConsumptionForecast'}->{'Amount'} / 3600 ) );
              }
          }
      }

      # Increment object counter
      $obj_nr++;
  }

  #MS: publish integrated PV and consumption forecast values
  readingsBulkUpdate($hash,"L1_Forecast-Today-Consumption", $consum_sum);
  readingsBulkUpdate($hash,"L1_Forecast-Today-PV", $PV_sum);


Ergebnis passt!

Grüße Marcel
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

Xguide

#366
Ich habe den Dark-Style auch mit integriert, reines Copy+Paste  ==> funktioniert.
Ich habe ein Attribut "portalAsHtml_Design" mit der Selektion default und dark angelegt, je nach Auswahl wird dann der WL generiert.
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

DS_Starter

Ich habe es mir runtergeladen zur Integration, kannst die Datei wieder entfernen.  :)
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

Xguide

Gesagt getan - schönen Feiertag.
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

Xguide

Mist, völlig übersehen, Du hattest die Variablendeklaration schon drin, allerdings wurden die nicht verwendet.

  my $PV_sum = 0;
  my $consum_sum = 0;

nur einmal deklarieren  :(
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

DS_Starter

Danke ... dir auch schönen Feiertag !
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

Xguide

Zum Abschluss ein Screenshot. Like!
Habe mal gleich die anderen drei Module entsorgt  ;D

FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

Wzut

eigentlich schön ( was soll ich auch anderes sagen ... ) aber warum ist bei dir die Glühbirne  und die Stundenwerte nicht zentriert unter dem Balken ?
Mein Fehler oder deine Absicht ?
Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher

Xguide

Hallo Wzut,

ist mir auch schon störend aufgefallen. Habe Deinen Code 1zu1 im Modul übernommen.
Muss ich mir noch mal ansehen. Definitiv keine Absicht.

Gruß Marcel
FHEM 5.9 - Intel NUC i3 mit Proxmox im Stretch Container
HomeMatic - VCCU mit 2 x HM-LAN-CFG
Module: SMA Peripheries - Sonos - IPCam(s) - Philips Hue - Sprinkler - TabletUI - DBlog -

Wzut

dann sollte man zur Sicherheit noch jedem TD entweder align="center" mitgeben oder style erweitern um  text-align:center
Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher