2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

76_SMAInverter: contrib 2.14.0

git-svn-id: https://svn.fhem.de/fhem/trunk@20332 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2019-10-08 16:03:44 +00:00
parent bccc3763f9
commit b9dd959d44

View File

@ -1,5 +1,5 @@
#################################################################################################################
# $Id: 76_SMAInverter.pm 20042 2019-08-22 09:34:18Z DS_Starter $
# $Id: 76_SMAInverter.pm 20080 2019-09-22 22:00:00Z DS_Starter $
#################################################################################################################
#
# Copyright notice
@ -32,7 +32,10 @@ eval "use FHEM::Meta;1" or my $modMetaAbsent = 1;
# Versions History by DS_Starter
our %SMAInverter_vNotesIntern = (
"2.13.2" => "27.08.2019 ",
"2.14.0" => "08.10.2019 readings bltotal, bltoday included by 300P",
"2.13.4" => "30.08.2019 STP10.0-3AV-40 298 included into %SMAInverter_devtypes ",
"2.13.3" => "28.08.2019 commandref revised ",
"2.13.2" => "27.08.2019 fix WARNING: Use of uninitialized value \$_ in substitution (s///) at /opt/fhem//FHEM/Blocking.pm line 238 ",
"2.13.1" => "22.08.2019 commandref revised ",
"2.13.0" => "20.08.2019 support of Meta.pm ",
"2.12.0" => "20.08.2019 set warning to log if SPOT_ETODAY, SPOT_ETOTAL was not delivered or successfully ".
@ -118,6 +121,8 @@ our %SMAInverter_vNotesIntern = (
# $inv_TEMP # Inverter temperature
# $inv_GRIDRELAY # Grid Relay/Contactor Status
# $inv_STATUS # Inverter Status
# $inv_SPOT_BATTERYLOAD_TODAY # Today Batteryload
# $inv_SPOT_BATTERYLOAD_TOTAL # Total Batteryload
# Aufbau Wechselrichter Type-Hash
my %SMAInverter_devtypes = (
@ -246,6 +251,7 @@ my %SMAInverter_devtypes = (
9345 => "STP5.0-3AV-40 (Sunny Tripower 5.0)",
9346 => "STP6.0-3AV-40 (Sunny Tripower 6.0)",
9347 => "STP8.0-3AV-40 (Sunny Tripower 8.0)",
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)",
9366 => "STP3.0-3AV-40 (Sunny Tripower 3.0)",
@ -301,6 +307,7 @@ sub SMAInverter_Initialize($) {
"target-susyid " .
"target-serial " .
$readingFnAttributes;
$hash->{AttrFn} = "SMAInverter_Attr";
eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html)
@ -373,7 +380,6 @@ sub SMAInverter_Undef($$) {
return undef;
}
###############################################################
# SMAInverter Get
###############################################################
@ -526,7 +532,9 @@ sub SMAInverter_getstatusDoParse($) {
$sup_OperationTime,
$sup_InverterTemperature,
$sup_GridRelayStatus,
$sup_SpotBatteryLoad,
$sup_DeviceStatus);
my ($inv_TYPE, $inv_CLASS,
$inv_SPOT_ETODAY, $inv_SPOT_ETOTAL,
$inv_susyid,
@ -542,7 +550,9 @@ sub SMAInverter_getstatusDoParse($) {
$inv_BAT_UDC, $inv_BAT_IDC,
$inv_BAT_CYCLES,
$inv_BAT_TEMP,
$inv_SPOT_BATTERYLOAD_TODAY, $inv_SPOT_BATTERYLOAD_TOTAL,
$inv_SPOT_FREQ, $inv_SPOT_OPERTM, $inv_SPOT_FEEDTM, $inv_TEMP, $inv_GRIDRELAY, $inv_STATUS,);
my @row_array;
my @array;
my $avg = 0;
@ -579,6 +589,14 @@ sub SMAInverter_getstatusDoParse($) {
BlockingInformParent("SMAInverter_setReadingFromBlocking", [$name, ".etotal_yesterday", $val], 0);
}
# BATTERYLOAD_TOTAL speichern für BATTERYLOAD_TODAY-Berechnung wenn WR BATTERYLOAD_TODAY nicht liefert
if ($dt_now >= $oper_stop) {
my $val = 0;
$val = ReadingsNum($name, "bltotal", 0)*1000 if (exists $defs{$name}{READINGS}{bltotal});
$val = ReadingsNum($name, "SPOT_BATTERYLOAD_TOTAL", 0) if (exists $defs{$name}{READINGS}{SPOT_BATTERYLOAD_TOTAL});
BlockingInformParent("SMAInverter_setReadingFromBlocking", [$name, ".bltotal_yesterday", $val], 0);
}
if (($oper_start <= $dt_now && $dt_now <= $oper_stop) || AttrVal($name,"suppressSleep",0)) {
# normal operation or suppressed sleepmode
@ -602,6 +620,7 @@ sub SMAInverter_getstatusDoParse($) {
push(@commands, "sup_SpotDCVoltage"); # Check SpotDCVoltage
push(@commands, "sup_SpotACVoltage"); # Check SpotACVoltage
push(@commands, "sup_BatteryInfo"); # Check BatteryInfo
push(@commands, "sup_SpotBatteryLoad"); # Check Batteryload
}
if($detail_level > 1) {
@ -667,6 +686,9 @@ sub SMAInverter_getstatusDoParse($) {
elsif ($i eq "sup_DeviceStatus") {
($sup_DeviceStatus,$inv_STATUS,$inv_susyid,$inv_serial) = SMAInverter_SMAcommand($hash, $hash->{HOST}, 0x51800200, 0x00214800, 0x002148FF);
}
elsif ($i eq "sup_SpotBatteryLoad") {
($sup_SpotBatteryLoad,$inv_SPOT_BATTERYLOAD_TODAY,$inv_SPOT_BATTERYLOAD_TOTAL,$inv_susyid,$inv_serial) = SMAInverter_SMAcommand($hash, $hash->{HOST}, 0x54000200, 0x00461F00, 0x00461FFF);
}
}
# nothing more to do, just log out
@ -762,6 +784,7 @@ sub SMAInverter_getstatusDoParse($) {
if($sup_ChargeStatus) {
push(@row_array, "chargestatus ".$inv_ChargeStatus."\n");
}
if($inv_CLASS && $inv_CLASS eq 8007 && defined($inv_SPOT_PACTOT)) { # V2.10.1 28.04.2019
if($inv_SPOT_PACTOT < 0) {
push(@row_array, "power_out "."0"."\n");
@ -792,6 +815,10 @@ sub SMAInverter_getstatusDoParse($) {
push(@row_array, "bat_udc ".$inv_BAT_UDC."\n");
push(@row_array, "bat_idc ".$inv_BAT_IDC."\n");
}
if($sup_SpotBatteryLoad) {
push(@row_array, "bltotal ".($inv_SPOT_BATTERYLOAD_TOTAL/1000)."\n");
push(@row_array, "bltoday ".($inv_SPOT_BATTERYLOAD_TODAY/1000)."\n");
}
}
if($detail_level > 1) {
@ -832,6 +859,7 @@ sub SMAInverter_getstatusDoParse($) {
push(@row_array, "device_status ".SMAInverter_StatusText($inv_STATUS)."\n");
}
}
} else { # kein SBFSpot Compatibility Mode
if($sup_EnergyProduction) {
push(@row_array, "SPOT_ETOTAL ".$inv_SPOT_ETOTAL."\n");
@ -882,6 +910,10 @@ sub SMAInverter_getstatusDoParse($) {
push(@row_array, "BAT_UDC ".$inv_BAT_UDC."\n");
push(@row_array, "BAT_IDC ".$inv_BAT_IDC."\n");
}
if($sup_SpotBatteryLoad) {
push(@row_array, "SPOT_BATTERYLOAD_TOTAL ".$inv_SPOT_BATTERYLOAD_TOTAL."\n");
push(@row_array, "SPOT_BATTERYLOAD_TODAY ".$inv_SPOT_BATTERYLOAD_TODAY."\n");
}
}
if($detail_level > 1) {
@ -1053,6 +1085,7 @@ sub SMAInverter_SMAcommand($$$$$) {
$inv_BAT_UDC, $inv_BAT_IDC,
$inv_BAT_CYCLES,
$inv_BAT_TEMP,
$inv_SPOT_BATTERYLOAD_TODAY, $inv_SPOT_BATTERYLOAD_TOTAL,
$inv_SPOT_FREQ, $inv_SPOT_OPERTM, $inv_SPOT_FEEDTM, $inv_TEMP, $inv_GRIDRELAY, $inv_STATUS);
my $mysusyid = $hash->{HELPER}{MYSUSYID};
my $myserialnumber = $hash->{HELPER}{MYSERIALNUMBER};
@ -1177,6 +1210,38 @@ sub SMAInverter_SMAcommand($$$$$) {
return (1,$inv_SPOT_ETODAY,$inv_SPOT_ETOTAL,$inv_susyid,$inv_serial);
}
####300?
if($data_ID eq 0x461F) {
if (length($data) >= 66) {
$inv_SPOT_BATTERYLOAD_TOTAL = unpack("V*", substr($data, 62, 4));
} else {
Log3 $name, 3, "$name - WARNING - BATTERYLOAD_TOTAL wasn't deliverd ... set it to \"0\" !";
$inv_SPOT_ETOTAL = 0;
}
if (length($data) >= 82) {
$inv_SPOT_BATTERYLOAD_TODAY = unpack("V*", substr ($data, 78, 4));
} 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, ".bltotal_yesterday", undef);
if(defined $bltotold && $inv_SPOT_BATTERYLOAD_TOTAL > $bltotold) {
$inv_SPOT_BATTERYLOAD_TODAY = $inv_SPOT_BATTERYLOAD_TOTAL - $bltotold;
Log3 $name, 3, "$name - BATTERYLOAD_TODAY calculated successfully !";
} else {
Log3 $name, 3, "$name - WARNING - unable to calculate BATTERYLOAD_TODAY ... set it to \"0\" !";
$inv_SPOT_BATTERYLOAD_TODAY = 0;
}
}
Log3 $name, 5, "$name - Data SPOT_BATTERYLOAD_TOTAL=$inv_SPOT_BATTERYLOAD_TOTAL and BATTERYLOAD_TODAY=$inv_SPOT_BATTERYLOAD_TODAY";
return (1,$inv_SPOT_BATTERYLOAD_TODAY,$inv_SPOT_BATTERYLOAD_TOTAL,$inv_susyid,$inv_serial);
}
if($data_ID eq 0x251E) {
$inv_SPOT_PDC1 = unpack("V*", substr $data, 62, 4);
if($size < 90) {$inv_SPOT_PDC2 = 0; } else {$inv_SPOT_PDC2 = unpack("V*", substr $data, 90, 4); } # catch short response, in case PDC2 not supported
@ -1572,12 +1637,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 20042 2019-08-22 09:34:18Z DS_Starter $ im Kopf komplett! vorhanden )
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 )
$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 20042 2019-08-22 09:34:18Z DS_Starter $ im Kopf komplett! vorhanden )
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 )
if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) {
# es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen
# mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden
@ -1711,8 +1776,7 @@ This module requires:
<b>Operation method</b>
<ul>
The module sends commands to the inverter and checks if they are supported by the inverter.<br>
In case of a positive answer the data is collected and displayed in the readings according to the detail-level. <br>
If more than one inverter is installed, set attributes "target-susyid" and "target-serial" with an appropriate value. <br><br>
In case of a positive answer the data is collected and displayed in the readings according to the detail-level. <br><br>
The normal operation time of the inverter is supposed from sunrise to sunset. In that time period the inverter will be polled.
The time of sunrise and sunset will be calculated by functions of FHEM module 99_SUNRISE_EL.pm which is loaded automatically by default.
@ -1851,6 +1915,9 @@ The retrieval of the inverter will be executed non-blocking. You can adjust the
<li><b>BAT_TEMP / bat_temp</b> : Battery temperature </li>
<li><b>BAT_UDC / bat_udc</b> : Battery Voltage </li>
<li><b>ChargeStatus / chargestatus</b> : Battery Charge status </li>
<li><b>SPOT_BATTERYLOAD_TODAY</b> : Battery Load Today </li>
<li><b>SPOT_BATTERYLOAD_TOTAL</b> : Battery Load Total </li>
<li><b>ChargeStatus / chargestatus</b> : Battery Charge status </li>
<li><b>CLASS / device_class</b> : Inverter Class </li>
<li><b>PACMAX1 / pac_max_phase_1</b> : Nominal power in Ok Mode </li>
<li><b>PACMAX1_2 / pac_max_phase_1_2</b> : Maximum active power device (Some inverters like SB3300/SB1200) </li>
@ -1941,9 +2008,7 @@ Dieses Modul benötigt:
<b>Arbeitsweise</b>
<ul>
Das Modul schickt Befehle an den Wechselrichter und überprüft, ob diese unterstützt werden.<br>
Bei einer positiven Antwort werden die Daten gesammelt und je nach Detail-Level in den Readings dargestellt. <br>
Sind mehr als ein Wechselrichter installiert, sind die Attribute "target-susyid" und "target-serial" entsprechend zu setzen um die korrekte
Funktion zu gewährleisten. <br><br>
Bei einer positiven Antwort werden die Daten gesammelt und je nach Detail-Level in den Readings dargestellt. <br><br>
Die normale Betriebszeit des Wechselrichters wird in der Zeit vom Sonnenaufgang bis Sonnenuntergang angenommen. In dieser Periode werden die Wechselrichterdaten
abgefragt. Die Ermittlung von Sonnenaufgang / Sonnenuntergang wird über die Funktionen des FHEM-Moduls 99_SUNRISE_EL.pm vorgenommen. Zu diesem Zweck sollten die globalen
@ -2084,6 +2149,8 @@ Die Abfrage des Wechselrichters wird non-blocking ausgeführt. Der Timeoutwert f
<li><b>BAT_TEMP / bat_temp</b> : Akku Temperatur </li>
<li><b>BAT_UDC / bat_udc</b> : Akku Spannung </li>
<li><b>ChargeStatus / chargestatus</b> : Akku Ladestand </li>
<li><b>SPOT_BATTERYLOAD_TODAY</b> : Battery Load Today </li>
<li><b>SPOT_BATTERYLOAD_TOTAL</b> : Battery Load Total </li>
<li><b>CLASS / device_class</b> : Wechselrichter Klasse </li>
<li><b>PACMAX1 / pac_max_phase_1</b> : Nominelle Leistung in Ok Mode </li>
<li><b>PACMAX1_2 / pac_max_phase_1_2</b> : Maximale Leistung (für einige Wechselrichtertypen) </li>