Solar forecast: use energy instead of power (#18733)

This commit is contained in:
andig 2025-02-11 13:20:38 +01:00 • committed by GitHub
parent 0a42b7a753
commit 3020e1a03a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport"
"github.com/jinzhu/now"
)
type Solcast struct {
@ -77,7 +78,7 @@ func (t *Solcast) run(done chan error) {
if err := backoff.Retry(func() error {
for _, site := range t.sites {
uri := fmt.Sprintf("https://api.solcast.com.au/rooftop_sites/%s/forecasts?format=json", site)
uri := fmt.Sprintf("https://api.solcast.com.au/rooftop_sites/%s/forecasts?period=PT60M&format=json", site)
if err := t.GetJSON(uri, &res); err != nil {
return err
}
@ -94,12 +95,23 @@ func (t *Solcast) run(done chan error) {
data := make(api.Rates, 0, len(res.Forecasts))
NEXT:
for _, r := range res.Forecasts {
data = append(data, api.Rate{
Start: r.PeriodEnd.Add(-r.Period.Duration()).Local(),
End: r.PeriodEnd.Local(),
start := now.With(r.PeriodEnd.Add(-r.Period.Duration())).BeginningOfHour().Local()
rr := api.Rate{
Start: start,
End: start.Add(time.Hour),
Price: r.PvEstimate * 1e3,
})
}
if r.Period.Duration() != time.Hour {
for i, r := range data {
if r.Start.Equal(rr.Start) {
data[i].Price = (r.Price + rr.Price) / 2
continue NEXT
}
}
}
data = append(data, rr)
}
mergeRates(t.data, data)

View file

@ -24,7 +24,7 @@ render: |
source: http
uri: https://api.forecast.solar/{{ if .apikey }}{{ .apikey }}/{{ end }}estimate/{{ .lat }}/{{ .lon }}/{{ .dec }}/{{ .az }}/{{ .kwp }}?time=utc&no_sun=1
jq: |
[ .result.watts | to_entries.[] | {
[ .result.watt_hours_period | to_entries.[] | {
"start": (.key | strptime("%FT%T%z") | strftime("%FT%TZ")),
"end": (.key | strptime("%FT%T%z") | mktime+3600 | strftime("%FT%TZ")),
"price": .value