diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index dd9218c16..889fba140 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -6949,28 +6949,11 @@ sub _attrInverterDev { ## no critic "not used" if ($in ne '01' && !AttrVal ($name, 'setupInverterDev01', '')) { return qq{Set the first Inverter device with attribute 'setupInverterDev01'}; } - - if (!$h->{pv} || !$h->{etotal} || !$h->{capacity}) { - return qq{One or more of the keys 'pv, etotal, capacity' are missing. Please consider the commandref.}; - } - - if (!isNumeric($h->{capacity})) { - return qq{The value of key 'capacity' must be numeric. Please consider the commandref.}; - } - - if ($h->{limit}) { - if (!isNumeric($h->{limit}) || $h->{limit} < 0 || $h->{limit} > 100) { - return qq{The value of key 'limit' is not valid. Please consider the commandref.}; - } - } - - if ($h->{feed} && $h->{feed} !~ /^grid|bat$/xs) { - return qq{The value of key 'feed' is not valid. Please consider the commandref.}; - } - + + my $none = 0; + if ($h->{strings}) { - my $none = 0; - my @as = split ',', $h->{strings}; + my @as = split ',', $h->{strings}; for my $s (@as) { if ($s eq 'none') { @@ -6988,6 +6971,24 @@ sub _attrInverterDev { ## no critic "not used" } } + if (!$h->{pv} || (!$h->{etotal} && !$none) || !$h->{capacity}) { + return qq{One or more of the keys 'pv, etotal, capacity' are missing. Please consider the commandref.}; + } + + if (!isNumeric($h->{capacity})) { + return qq{The value of key 'capacity' must be numeric. Please consider the commandref.}; + } + + if ($h->{limit}) { + if (!isNumeric($h->{limit}) || $h->{limit} < 0 || $h->{limit} > 100) { + return qq{The value of key 'limit' is not valid. Please consider the commandref.}; + } + } + + if ($h->{feed} && $h->{feed} !~ /^grid|bat$/xs) { + return qq{The value of key 'feed' is not valid. Please consider the commandref.}; + } + $data{$name}{circular}{99}{attrInvChangedTs} = int time; delete $data{$name}{inverters}{$in}{invertercap}; @@ -9887,8 +9888,13 @@ sub _transferInverterValues { my ($err, $indev, $h) = isDeviceValid ( { name => $name, obj => 'setupInverterDev'.$in, method => 'attr' } ); next if($err); - my ($pvread,$pvunit) = split ":", $h->{pv}; # Readingname/Unit für aktuelle PV Erzeugung - my ($edread,$etunit) = split ":", $h->{etotal}; # Readingname/Unit für Energie total (PV Erzeugung) + my ($pvread, $pvunit) = split ":", $h->{pv}; # Readingname/Unit für aktuelle PV Erzeugung + my $source = defined $h->{strings} && $h->{strings} eq 'none' ? 'bat' : 'pv'; # Energie-Bezug PV oder aus Batterie + + delete $h->{etotal} if($source eq 'bat'); # Batteriewechselrichter ohne PV-Erzeugung + + $h->{etotal} = defined $h->{etotal} ? $h->{etotal} : 'dum_rdng_no_etot:Wh'; # Dummy Reading für Batterie-Inverter ohne PV-Erzeugung + my ($edread, $etunit) = split ":", $h->{etotal}; # Readingname/Unit für Energie total (PV Erzeugung) next if(!$pvread || !$edread); @@ -9899,8 +9905,7 @@ sub _transferInverterValues { my $etuf = $etunit =~ /^kWh$/xi ? 1000 : 1; my $etotal = ReadingsNum ($indev, $edread, 0) * $etuf; # Erzeugung total (Wh) my $histetot = HistoryVal ($hash, $day, sprintf("%02d",$nhour), 'etotali'.$in, 0); # etotal zu Beginn einer Stunde - my $source = defined $h->{strings} && $h->{strings} eq 'none' ? 'bat' : 'pv'; # Energie-Bezug PV oder aus Batterie - + my ($ethishour, $etotsvd); if (!$histetot) { # etotal der aktuelle Stunde gesetzt ? @@ -9956,7 +9961,7 @@ sub _transferInverterValues { writeToHistory ( { paref => $paref, key => 'pvrl'.$in, val => $ethishour, hour => $nhour } ); - debugLog ($paref, "collectData", "collect Inverter $in data - device: $indev, delivery: $feed =>"); + debugLog ($paref, "collectData", "collect Inverter $in data - device: $indev, source: $source, delivery: $feed =>"); debugLog ($paref, "collectData", "pv: $pv W, etotal: $etotal Wh"); } @@ -11582,11 +11587,13 @@ sub _createSummaries { my $pv2grid = 0; # PV-Erzeugung zu Grid-only for my $in (1..MAXINVERTER) { # Summe alle Inverter - $in = sprintf "%02d", $in; - my $pvi = InverterVal ($name, $in, 'igeneration', 0); - my $feed = InverterVal ($name, $in, 'ifeed', ''); - $pvgen += $pvi; - $pv2grid += $pvi if($feed eq 'grid'); + $in = sprintf "%02d", $in; + my $pvi = InverterVal ($name, $in, 'igeneration', 0); + my $feed = InverterVal ($name, $in, 'ifeed', ''); + my $source = InverterVal ($name, $in, 'isource', 'pv'); + $pvgen += $pvi; + $pv2grid += $pvi if($feed eq 'grid'); + $batout -= $pvi if($source eq 'bat'); # Doppelgenerierung vermeiden ! } my $othprod = 0; # Summe Otherproducer @@ -26021,6 +26028,7 @@ to ensure that the system configuration is correct.