From 234d2e9b3e300affebd0e199fb02065fb148bd7e Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Wed, 2 Jun 2021 08:08:20 +0000 Subject: [PATCH] 76_SMAInverter: contrib 2.14.2 git-svn-id: https://svn.fhem.de/fhem/trunk@24566 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SMAInverter.pm | 64 ++++++++++++++--------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SMAInverter.pm b/fhem/contrib/DS_Starter/76_SMAInverter.pm index d26d82df6..585158309 100644 --- a/fhem/contrib/DS_Starter/76_SMAInverter.pm +++ b/fhem/contrib/DS_Starter/76_SMAInverter.pm @@ -1,5 +1,5 @@ ################################################################################################################# -# $Id: 76_SMAInverter.pm 20080 2019-09-22 22:00:00Z DS_Starter $ +# $Id: 76_SMAInverter.pm 23909 2021-03-07 20:06:59Z DS_Starter $ ################################################################################################################# # # Copyright notice @@ -32,6 +32,8 @@ eval "use FHEM::Meta;1" or my $modMetaAbsent = 1; # Versions History by DS_Starter our %SMAInverter_vNotesIntern = ( + "2.14.2" => "02.06.2021 new inverter type 9359=SBS6.0-10 ", + "2.14.1" => "27.02.2021 change save .etotal_yesterday, Forum: https://forum.fhem.de/index.php/topic,56080.msg1134664.html#msg1134664 ", "2.14.0" => "08.10.2019 readings bat_loadtotal (BAT_LOADTOTAL), bat_loadtoday (BAT_LOADTODAY) included by 300P, Forum: #topic,56080.msg986302.html#msg986302", "2.13.4" => "30.08.2019 STP10.0-3AV-40 298 included into %SMAInverter_devtypes ", "2.13.3" => "28.08.2019 commandref revised ", @@ -125,6 +127,7 @@ our %SMAInverter_vNotesIntern = ( # $inv_BAT_LOADTOTAL # Total Batteryload # Aufbau Wechselrichter Type-Hash +# https://github.com/SBFspot/SBFspot/blob/master/SBFspot/TagListDE-DE.txt my %SMAInverter_devtypes = ( 0000 => "Unknown Inverter Type", 9015 => "SB 700", @@ -254,6 +257,7 @@ my %SMAInverter_devtypes = ( 9348 => "STP10.0-3AV-40 (Sunny Tripower 10.0)", 9356 => "SBS3.7-1VL-10 (Sunny Boy Storage 3.7)", 9358 => "SBS5.0-10 (Sunny Boy Storage 5.0)", +9359 => "SBS6.0-10 (Sunny Boy Storage 6.0)", 9366 => "STP3.0-3AV-40 (Sunny Tripower 3.0)", 9401 => "SB3.0-1AV-41 (Sunny Boy 3.0 AV-41)", 9402 => "SB3.6-1AV-41 (Sunny Boy 3.6 AV-41)", @@ -570,9 +574,10 @@ sub SMAInverter_getstatusDoParse($) { my ($sunrise_h,$sunrise_m,$sunrise_s) = split(":",sunrise_abs('-'.$offset)); my ($sunset_h,$sunset_m,$sunset_s) = split(":",sunset_abs('+'.$offset)); - my $oper_start = DateTime->new(year=>$year+1900,month=>$mon+1,day=>$mday,hour=>$sunrise_h,minute=>$sunrise_m,second=>$sunrise_s,time_zone=>'local'); - my $oper_stop = DateTime->new(year=>$year+1900,month=>$mon+1,day=>$mday,hour=>$sunset_h,minute=>$sunset_m,second=>$sunset_s,time_zone=>'local'); - my $dt_now = DateTime->now(time_zone=>'local'); + my $oper_start = DateTime->new(year=>$year+1900,month=>$mon+1,day=>$mday,hour=>$sunrise_h,minute=>$sunrise_m,second=>$sunrise_s,time_zone=>'local'); + my $oper_stop = DateTime->new(year=>$year+1900,month=>$mon+1,day=>$mday,hour=>$sunset_h,minute=>$sunset_m,second=>$sunset_s,time_zone=>'local'); + my $oper_start_d = DateTime->new(year=>$year+1900,month=>$mon+1,day=>$mday,hour=>00,minute=>10,second=>00,time_zone=>'local'); + my $dt_now = DateTime->now(time_zone=>'local'); Log3 $name, 4, "$name - current time: ".$dt_now->dmy('.')." ".$dt_now->hms; Log3 $name, 4, "$name - operation time begin: ".$oper_start->dmy('.')." ".$oper_start->hms; @@ -582,18 +587,18 @@ sub SMAInverter_getstatusDoParse($) { my $opertime_stop = $oper_stop->dmy('.')." ".$oper_stop->hms; # ETOTAL speichern für ETODAY-Berechnung wenn WR ETODAY nicht liefert - if ($dt_now >= $oper_stop) { + if ($dt_now <= $oper_start_d) { # V2.14.1, Forum: https://forum.fhem.de/index.php/topic,56080.msg1134664.html#msg1134664 my $val = 0; - $val = ReadingsNum($name, "etotal", 0)*1000 if (exists $defs{$name}{READINGS}{etotal}); - $val = ReadingsNum($name, "SPOT_ETOTAL", 0) if (exists $defs{$name}{READINGS}{SPOT_ETOTAL}); + $val = ReadingsNum($name, "etotal", 0)*1000; + $val = ReadingsNum($name, "SPOT_ETOTAL", 0); BlockingInformParent("SMAInverter_setReadingFromBlocking", [$name, ".etotal_yesterday", $val], 0); } # BATTERYLOAD_TOTAL speichern für BAT_LOADTODAY-Berechnung wenn WR BAT_LOADTODAY nicht liefert - if ($dt_now >= $oper_stop) { + if ($dt_now <= $oper_start_d) { # V2.14.1, Forum: https://forum.fhem.de/index.php/topic,56080.msg1134664.html#msg1134664 my $val = 0; - $val = ReadingsNum($name, "bat_loadtotal", 0)*1000 if (exists $defs{$name}{READINGS}{bat_loadtotal}); - $val = ReadingsNum($name, "BAT_LOADTOTAL", 0) if (exists $defs{$name}{READINGS}{BAT_LOADTOTAL}); + $val = ReadingsNum($name, "bat_loadtotal", 0)*1000; + $val = ReadingsNum($name, "BAT_LOADTOTAL", 0); BlockingInformParent("SMAInverter_setReadingFromBlocking", [$name, ".bat_loadtotal_yesterday", $val], 0); } @@ -1181,27 +1186,30 @@ sub SMAInverter_SMAcommand($$$$$) { # Check the data identifier $data_ID = unpack("v*", substr $data, 55, 2); - Log3 $name, 5, "$name - Data identifier $data_ID"; + Log3 ($name, 5, "$name - Data identifier $data_ID"); if($data_ID eq 0x2601) { if (length($data) >= 66) { $inv_SPOT_ETOTAL = unpack("V*", substr($data, 62, 4)); } else { - Log3 $name, 3, "$name - WARNING - ETOTAL wasn't deliverd ... set it to \"0\" !"; + Log3 ($name, 3, "$name - WARNING - ETOTAL wasn't deliverd ... set it to \"0\" !"); $inv_SPOT_ETOTAL = 0; } if (length($data) >= 82) { $inv_SPOT_ETODAY = unpack("V*", substr ($data, 78, 4)); - } else { + } + else { # ETODAY wurde vom WR nicht geliefert, es wird versucht ihn zu berechnen - Log3 $name, 3, "$name - ETODAY wasn't delivered from inverter, try to calculate it ..."; - my $etotold = ReadingsNum($name, ".etotal_yesterday", undef); - if(defined $etotold && $inv_SPOT_ETOTAL > $etotold) { + Log3 ($name, 3, "$name - ETODAY wasn't delivered from inverter, try to calculate it ..."); + my $etotold = ReadingsNum($name, ".etotal_yesterday", 0); + + if($etotold && $inv_SPOT_ETOTAL > $etotold) { $inv_SPOT_ETODAY = $inv_SPOT_ETOTAL - $etotold; - Log3 $name, 3, "$name - ETODAY calculated successfully !"; - } else { - Log3 $name, 3, "$name - WARNING - unable to calculate ETODAY ... set it to \"0\" !"; + Log3 ($name, 3, "$name - ETODAY calculated successfully !"); + } + else { + Log3 ($name, 3, "$name - WARNING - unable to calculate ETODAY ... set it to \"0\" !"); $inv_SPOT_ETODAY = 0; } } @@ -1213,21 +1221,25 @@ sub SMAInverter_SMAcommand($$$$$) { if($data_ID eq 0x4967) { if (length($data) >= 66) { $inv_BAT_LOADTOTAL = unpack("V*", substr($data, 62, 4)); - } else { + } + else { Log3 $name, 3, "$name - WARNING - BATTERYLOAD_TOTAL wasn't deliverd ... set it to \"0\" !"; $inv_SPOT_ETOTAL = 0; } if (length($data) >= 82) { $inv_BAT_LOADTODAY = unpack("V*", substr ($data, 78, 4)); - } else { + } + else { # BATTERYLOAD_TODAY wurde vom WR nicht geliefert, es wird versucht ihn zu berechnen Log3 $name, 3, "$name - BATTERYLOAD_TODAY wasn't delivered from inverter, try to calculate it ..."; - my $bltotold = ReadingsNum($name, ".bat_loadtotal_yesterday", undef); - if(defined $bltotold && $inv_BAT_LOADTOTAL > $bltotold) { + my $bltotold = ReadingsNum($name, ".bat_loadtotal_yesterday", 0); + + if($bltotold && $inv_BAT_LOADTOTAL > $bltotold) { $inv_BAT_LOADTODAY = $inv_BAT_LOADTOTAL - $bltotold; Log3 $name, 3, "$name - BATTERYLOAD_TODAY calculated successfully !"; - } else { + } + else { Log3 $name, 3, "$name - WARNING - unable to calculate BATTERYLOAD_TODAY ... set it to \"0\" !"; $inv_BAT_LOADTODAY = 0; } @@ -1632,12 +1644,12 @@ sub SMAInverter_setVersionInfo($) { if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) { # META-Daten sind vorhanden $modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{SMAPortal}{META}} - if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 76_SMAInverter.pm 20080 2019-08-30 08:25:27Z DS_Starter $ im Kopf komplett! vorhanden ) + if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 76_SMAInverter.pm 23909 2021-03-07 20:06:59Z DS_Starter $ im Kopf komplett! vorhanden ) $modules{$type}{META}{x_version} =~ s/1.1.1/$v/g; } else { $modules{$type}{META}{x_version} = $v; } - return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 76_SMAInverter.pm 20080 2019-08-30 08:25:27Z DS_Starter $ im Kopf komplett! vorhanden ) + return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 76_SMAInverter.pm 23909 2021-03-07 20:06:59Z DS_Starter $ im Kopf komplett! vorhanden ) if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) { # es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen # mit {->VERSION()} im FHEMWEB kann Modulversion abgefragt werden