Autor Thema: Anwendungsbeispiel JsonMod - SolCast Solar-Vorhersage abrufen  (Gelesen 8399 mal)

Offline Torxgewinde

  • New Member
  • *
  • Beiträge: 38
Antw:Anwendungsbeispiel JsonMod - SolCast Solar-Vorhersage abrufen
« Antwort #60 am: 21 Oktober 2022, 20:00:57 »
Vielen Dank für die Definition für Solcast.
Ich denke es gibt noch einen Punkt bei der Zeitzone der nicht genau stimmt. Ich habe den aktuell gültigen Wert als UserReading dargestellt und musste dabei den Offset der Zeitzone mit einberechnen:

defmod Solcast JsonMod https://api.solcast.com.au/rooftop_sites/AAAA-BBBB-CCCC-DDDD/forecasts?format=json&api_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ&hours=72
attr Solcast group Strom
attr Solcast interval 1,31 * * * *
attr Solcast readingList multi(jsonPath('$.forecasts[*]'), concat('pv_estimate_', property('period_end')), property('pv_estimate'));;\
single(jsonPath('$.forecasts[0].period'),'period','');;
attr Solcast stateFormat Jetzt: forecast_now W, Heute: forecast_today kWh, Morgen: forecast_tomorrow kWh, Übermorgen: forecast_overmorrow kWh
attr Solcast userReadings forecast_now {\
my $period = ReadingsVal($NAME, "period", 0);;\
$period =~ s/.*(\d\d).*/$1/;;\
\
my $offset = timegm(localtime()) - timelocal(localtime());;\
\
my ($date, $time) = split(" ", FmtDateTime(time()-$offset));;\
my ($hour, $min, $sec) = split(":", $time);;\
$time = $hour . $min . "00";;\
\
my ($date_plus, $time_plus) = split(" ", FmtDateTime(time()+30*60-$offset));;\
my ($hour_plus, $min_plus, $sec_plus) = split(":", $time_plus);;\
$time_plus = $hour_plus . $min_plus . "00";;\
\
my $hash = $defs{$NAME};;\
my $readings = $hash->{READINGS};;\
\
foreach my $reading ( keys %{$readings} ) {\
if ($reading =~ /$date/) {\
my ($dummy, $period_end) = split("T", $reading);;\
$period_end = substr($period_end, 0, 6);;\
\
##Log(0, "period_end: ".$period_end .">". $time ." && ". $time_plus);;\
\
if (($period_end > $time) && ($period_end <= $time_plus)) {\
##Log(0, "Treffer");;\
return round(1000*ReadingsVal($NAME,$reading,0),0);;\
}\
}\
}\
},\
forecast_today {\
my $total = 0;;\
my $period = ReadingsVal($NAME, "period", 0);;\
$period =~ s/.*(\d\d).*/$1/;;\
my ($date, $time) = split(" ", FmtDateTime(time()));;\
my ($hour, $min, $sec) = split(":", $time);;\
$time = $hour . $min . "00";;\
my $hash = $defs{$NAME};;\
my $readings = $hash->{READINGS};;\
foreach my $reading ( keys %{$readings} ) {\
if ($reading =~ /$date/) {\
my ($dummy, $period_end) = split("T", $reading);;\
$period_end = substr($period_end, 0, 6);;\
\
if ($period_end > $time)\
{\
my $val = ReadingsVal($NAME,$reading,0);;\
$total += $val/(60/$period);;\
}\
}\
}\
return round($total,2);;\
},\
forecast_tomorrow {\
use Time::Piece ();;\
use Time::Seconds;;\
\
my $total = 0;;\
my $period = ReadingsVal($NAME, "period", 0);;\
$period =~ s/.*(\d\d).*/$1/;;\
my ($date, $time) = split(" ", FmtDateTime(time()));;\
$date = Time::Piece->strptime($date, '%Y-%m-%d');;\
$date += ONE_DAY;;\
$date = $date->strftime('%Y-%m-%d');;\
my $hash = $defs{$NAME};;\
my $readings = $hash->{READINGS};;\
foreach my $reading (keys %{$readings}) {\
if ($reading =~ /$date/) {\
my $val = ReadingsVal($NAME, $reading, 0);;\
$total += $val/(60/$period);;\
}\
}\
return round($total,2);;\
},\
forecast_overmorrow {\
use Time::Piece ();;\
use Time::Seconds;;\
\
my $total = 0;;\
my $period = ReadingsVal($NAME, "period", 0);;\
$period =~ s/.*(\d\d).*/$1/;;\
my ($date, $time) = split(" ", FmtDateTime(time()));;\
$date = Time::Piece->strptime($date, '%Y-%m-%d');;\
$date += ONE_DAY;;\
$date += ONE_DAY;;\
$date = $date->strftime('%Y-%m-%d');;\
my $hash = $defs{$NAME};;\
my $readings = $hash->{READINGS};;\
foreach my $reading (keys %{$readings}) {\
if ($reading =~ /$date/) {\
my $val = ReadingsVal($NAME, $reading, 0);;\
$total += $val/(60/$period);;\
}\
}\
return round($total,2);;\
}
attr Solcast webCmd reread

Plotte ich mir die Werte von "forecast_now" now in einem Graphen über den Ertrag, passt das besser.