From 3020e1a03accbb21489f3819313394005392fa01 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 11 Feb 2025 13:20:38 +0100 Subject: [PATCH] Solar forecast: use energy instead of power (#18733) --- tariff/solcast.go | 22 ++++++++++++++----- .../definition/tariff/forecast-solar.yaml | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tariff/solcast.go b/tariff/solcast.go index 2278ed0b5..61e1b54c0 100644 --- a/tariff/solcast.go +++ b/tariff/solcast.go @@ -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) diff --git a/templates/definition/tariff/forecast-solar.yaml b/templates/definition/tariff/forecast-solar.yaml index e0b947ff5..2fcdef80c 100644 --- a/templates/definition/tariff/forecast-solar.yaml +++ b/templates/definition/tariff/forecast-solar.yaml @@ -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