hardware:channels:solar_inverters:sma
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
hardware:channels:solar_inverters:sma [2018/08/13 16:10] – URL im Script korrigiert jau | hardware:channels:solar_inverters:sma [2020/12/18 13:30] (aktuell) – [SMA Sunny Boy] wasserma | ||
---|---|---|---|
Zeile 167: | Zeile 167: | ||
</ | </ | ||
+ | == Modifiziertes Script (2. Versuch von Markus) == | ||
+ | Läuft Fix, und berechnet den Eigenverbrauch sehr gut, insbesondere bei Lücken in der AUfzeichnung. | ||
+ | |||
+ | <code bash eigenverbrauch.sh> | ||
+ | # | ||
+ | |||
+ | use Time:: | ||
+ | use LWP:: | ||
+ | use DBI; | ||
+ | # | ||
+ | $debug = 0; | ||
+ | #$debug = 1; | ||
+ | |||
+ | my $dbh = DBI-> | ||
+ | my $ideigen = " | ||
+ | # | ||
+ | # | ||
+ | step_copy_SMA(); | ||
+ | step_max_10(); | ||
+ | step_lin(); | ||
+ | add_missig_dates(1); | ||
+ | step_gesamtverbrauch(); | ||
+ | |||
+ | sub step_get_SMA { # ad300 -> 300 tage | ||
+ | system("/ | ||
+ | } | ||
+ | |||
+ | sub step_copy_SMA { | ||
+ | my $sth = $dbh-> | ||
+ | my $numrows = $sth-> | ||
+ | $dbh-> | ||
+ | |||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub step_clean { | ||
+ | my $sth = $dbh-> | ||
+ | my $numrows = $sth-> | ||
+ | $dbh-> | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub step_max_10 {xRe9AnfH7b9uNPS8 | ||
+ | my $inserted = 0; | ||
+ | # Neue Idee zuerst die 10 Minuten lücken füllen ... | ||
+ | # Danach Linear zur Einspeisung ... | ||
+ | my $sth_4_solar = $dbh-> | ||
+ | my $sth_2_einsp = $dbh-> | ||
+ | my $sth = $dbh-> | ||
+ | |||
+ | $sth_4_solar-> | ||
+ | $sth_2_einsp-> | ||
+ | my $timestamp3 | ||
+ | |||
+ | while (my ($id, $channel_id, | ||
+ | while ( $timestamp3 | ||
+ | $timestamp3_old | ||
+ | $value3_old = $value3; | ||
+ | $timestamp3 | ||
+ | $value3 = $value2/ | ||
+ | # | ||
+ | } | ||
+ | my $time_diff_tot = $timestamp3 | ||
+ | my $einsp_MS = ($value3 | ||
+ | my $time_diff = $timestamp | ||
+ | my $einsp_estim = $value3_old + ( ($time_diff | ||
+ | my $value_eigenv = $value - $einsp_estim ; | ||
+ | |||
+ | if ($debug > 0) { | ||
+ | |||
+ | print " | ||
+ | print localtime($timestamp/ | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " NEW" .localtime($timestamp | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | if ($time_diff_tot< | ||
+ | $inserted += 1; | ||
+ | $sth-> | ||
+ | $sth-> | ||
+ | } | ||
+ | } | ||
+ | $dbh-> | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub step_lin{ | ||
+ | my $inserted = 0; | ||
+ | # Neue Idee zuerst die 10 Minuten lücken füllen ... | ||
+ | # Danach Linear zur Einspeisung ... | ||
+ | my $sth_4_solar = $dbh-> | ||
+ | my $sth_2_einsp = $dbh-> | ||
+ | (SELECT | ||
+ | (SELECT | ||
+ | order by timestamp4" | ||
+ | my $sth = $dbh-> | ||
+ | |||
+ | $sth_4_solar-> | ||
+ | | ||
+ | my $timestamp3 | ||
+ | while (my ($id, $channel_id, | ||
+ | #print localtime($timestamp | ||
+ | while ( $timestamp3 | ||
+ | $timestamp3_old | ||
+ | $value1029_old = $value1029_new; | ||
+ | | ||
+ | $timestamp3 | ||
+ | $value1029_new = $value1029; | ||
+ | | ||
+ | # | ||
+ | } | ||
+ | |||
+ | #my $einsp_MS = ($value3 | ||
+ | #my $time_diff = $timestamp | ||
+ | #my $einsp_estim = $value3_old + ( ($time_diff | ||
+ | #my $value_eigenv = $value - $einsp_estim ; | ||
+ | my $diffeinspeisung = $value1029_new - $value1029_old; | ||
+ | my $differz | ||
+ | my $differz_daz | ||
+ | if ($differz > 0){ | ||
+ | |||
+ | |||
+ | my $anteil | ||
+ | my $diff_ber = $differz_daz * $anteil; | ||
+ | my $value_ber = $diff_ber + $value1029_old; | ||
+ | my $value_ber_einsp = $value- $value_ber; | ||
+ | if ($debug > 0) { | ||
+ | |||
+ | print " | ||
+ | |||
+ | print " | ||
+ | print " ALT:" .localtime($timestamp3_old/ | ||
+ | print " DAZ:" .localtime($timestamp | ||
+ | print " NEU:" .localtime($timestamp3 | ||
+ | print " | ||
+ | print " | ||
+ | print " NEU: $value1029_new\n" | ||
+ | print " ALT: $value1029_old\n" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " NEU: $value4_new\n" | ||
+ | print " ALT: $value4_old\n" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " DAZ: $value\n" | ||
+ | print " ALT: $value4_old\n" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | $inserted += 1; | ||
+ | $sth-> | ||
+ | $sth-> | ||
+ | |||
+ | } | ||
+ | } | ||
+ | $dbh-> | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | |||
+ | sub step_gesamtverbrauch { | ||
+ | #my $sth = $dbh-> | ||
+ | #my $numrows = $sth-> | ||
+ | |||
+ | my $inserted = 0; | ||
+ | # Neue Idee zuerst die 10 Minuten lücken füllen ... | ||
+ | # Danach Linear zur Einspeisung ... | ||
+ | my $sth_4_solar = $dbh-> | ||
+ | my $sth_2_einsp = $dbh-> | ||
+ | my $sth = $dbh-> | ||
+ | |||
+ | $sth_4_solar-> | ||
+ | $sth_2_einsp-> | ||
+ | my $timestamp3 | ||
+ | |||
+ | while (my ($id, $channel_id, | ||
+ | while ( $timestamp3 | ||
+ | $timestamp3_old | ||
+ | $value3_old = $value3; | ||
+ | $timestamp3 | ||
+ | $value3 = $value2; | ||
+ | # | ||
+ | } | ||
+ | my $time_diff_tot = $timestamp3 | ||
+ | my $einsp_MS = ($value3 | ||
+ | my $time_diff = $timestamp | ||
+ | my $einsp_estim = $value3_old + ( ($time_diff | ||
+ | my $value_eigenv = $value/1000 + $einsp_estim ; | ||
+ | |||
+ | if ($debug > 0) { | ||
+ | |||
+ | print " | ||
+ | print localtime($timestamp/ | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " NEW" .localtime($timestamp | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | #if ($time_diff_tot< | ||
+ | $inserted += 1; | ||
+ | $sth-> | ||
+ | # | ||
+ | #} | ||
+ | } | ||
+ | $dbh-> | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | |||
+ | sub add_missig_dates { | ||
+ | my ($id) = @_; | ||
+ | $inserted = 0; | ||
+ | #my $id = 1; | ||
+ | my $timestamp3 | ||
+ | |||
+ | my $sth = $dbh-> | ||
+ | $sth-> | ||
+ | my $sth2 = $dbh-> | ||
+ | |||
+ | my $t = Time:: | ||
+ | print $t-> | ||
+ | for (my $i= $t-> | ||
+ | # print " | ||
+ | my $timestamp = $i*1000; | ||
+ | while ( $timestamp3 | ||
+ | $timestamp3_old | ||
+ | $value3_old = $value3; | ||
+ | $timestamp3 | ||
+ | $value3 = $value2; | ||
+ | # | ||
+ | } | ||
+ | my $time_diff_tot = $timestamp3 | ||
+ | my $einsp_MS | ||
+ | my $time_diff = $timestamp | ||
+ | my $value | ||
+ | |||
+ | if ($time_diff_tot> | ||
+ | if ($debug > 0) { | ||
+ | print " | ||
+ | print localtime($timestamp/ | ||
+ | |||
+ | print " | ||
+ | print "NEW " .localtime($timestamp | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | $inserted += 1; | ||
+ | $sth2-> | ||
+ | } | ||
+ | } | ||
+ | $dbh-> | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | |||
+ | </ | ||
== Modifiziertes Script (Versuch von Wolfgang) == | == Modifiziertes Script (Versuch von Wolfgang) == | ||
<code bash eigenverbrauch.sh> | <code bash eigenverbrauch.sh> | ||
Zeile 984: | Zeile 1262: | ||
</ | </ | ||
+ | |||
+ | ===== SMA Sunny Boy ===== | ||
+ | Den SMA Sunny Boy kann man per URL auslesen, dazu muss man die Default seite von dem Sunny Boy freischalten, | ||
+ | Dann kann man per request die JSON daten abfragen. | ||
+ | |||
+ | http:// | ||
+ | json response example: | ||
+ | < | ||
+ | ... | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | }, | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Hierzu ein python script, dass den aktullen Wert in eine Datei schreibt, die wir dann mit dem vzlogger auslesen können: | ||
+ | |||
+ | < | ||
+ | import requests | ||
+ | import time | ||
+ | import logging | ||
+ | import argparse | ||
+ | |||
+ | |||
+ | logging.basicConfig( | ||
+ | level=logging.INFO, | ||
+ | format=" | ||
+ | handlers=[logging.StreamHandler()], | ||
+ | ) | ||
+ | |||
+ | sma_host = : str = None | ||
+ | out_put_file | ||
+ | |||
+ | def pullData(): | ||
+ | try: | ||
+ | data = requests.get( | ||
+ | " | ||
+ | ).json() | ||
+ | value = data[" | ||
+ | logging.debug(data) | ||
+ | if value: | ||
+ | return value | ||
+ | except Exception as e: | ||
+ | logging.error(" | ||
+ | return -1 | ||
+ | |||
+ | |||
+ | def main(): | ||
+ | while True: | ||
+ | value = pullData() | ||
+ | if value != -1: | ||
+ | if out_put_file: | ||
+ | f = open(out_put_file, | ||
+ | f.write(str(value)) | ||
+ | f.close() | ||
+ | else: | ||
+ | print(value) | ||
+ | time.sleep(5) | ||
+ | |||
+ | |||
+ | if __name__ == " | ||
+ | print(" | ||
+ | parser = argparse.ArgumentParser() | ||
+ | parser.add_argument(" | ||
+ | parser.add_argument(" | ||
+ | args = parser.parse_args() | ||
+ | |||
+ | if not args.sma: | ||
+ | print(" | ||
+ | exit(-1) | ||
+ | |||
+ | #global sma_host | ||
+ | | ||
+ | sma_host = args.sma | ||
+ | print(" | ||
+ | |||
+ | if args.out: | ||
+ | out_put_file = args.out | ||
+ | print(" | ||
+ | else: | ||
+ | print(" | ||
+ | | ||
+ | |||
+ | main() | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | vzlogger.conf file meter: | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ |
hardware/channels/solar_inverters/sma.1534169434.txt.gz · Zuletzt geändert: 2018/08/13 16:10 von jau