From 93210dd021ad4d534fd020895d7889d798af7b4e Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 7 Dec 2024 14:28:32 +0100 Subject: [PATCH] Add Nordpool tariff api (#17628) --- templates/definition/tariff/nordpool.yaml | 79 +++++++++++++++++++++++ util/format.go | 1 + util/format_functions.go | 4 ++ 3 files changed, 84 insertions(+) create mode 100644 templates/definition/tariff/nordpool.yaml diff --git a/templates/definition/tariff/nordpool.yaml b/templates/definition/tariff/nordpool.yaml new file mode 100644 index 000000000..11fbfc0f4 --- /dev/null +++ b/templates/definition/tariff/nordpool.yaml @@ -0,0 +1,79 @@ +template: nordpool +products: + - brand: Nordpool spot prices +requirements: + description: + de: "Nordpool Spot Preise im Day-Ahead-Markt für alle Märkte in der Nordpool-Region." + en: "Nordpool spot prices in day-ahead market for all markets in the Nordpool region." + evcc: ["skiptest"] +group: price +params: + - name: region + example: GER + validvalues: + [ + "EE", + "LT", + "LV", + "AT", + "BE", + "FR", + "GER", + "NL", + "PL", + "DK1", + "DK2", + "FI", + "NO1", + "NO2", + "NO3", + "NO4", + "NO5", + "SE1", + "SE2", + "SE3", + "SE4", + "TEL", + "SYS", + ] + - name: currency + default: EUR + validvalues: ["DKK", "EUR", "NOK", "PLN", "RON", "SEK"] + - preset: tariff-base +render: | + type: custom + forecast: + source: go + script: | + // concat today and tomorrow + "[" + strings.Trim(strings.Trim(today, "[]") + "," + strings.Trim(tomorrow, "[]"), ",") + "]" + in: + - name: today + type: string + config: + source: http + uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?market=DayAhead&date={{ `{{ now.Local | date "2006-01-02" }}` }}&deliveryArea={{ .region }}¤cy={{ .currency }} + jq: | + .multiAreaEntries | [ + .[] | + { + "start": .deliveryStart, + "end": .deliveryEnd, + "price": .entryPerArea.{{ .region }} + } + ] | tostring + - name: tomorrow + type: string + config: + source: http + uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?market=DayAhead&date={{ `{{ addDate (now.Local) 0 0 1 | date "2006-01-02" }}` }}&deliveryArea={{ .region }}¤cy={{ .currency }} + jq: | + .multiAreaEntries | [ + .[] | + { + "start": .deliveryStart, + "end": .deliveryEnd, + "price": .entryPerArea.{{ .region }} + } + ] | tostring + {{ include "tariff-base" . }} diff --git a/util/format.go b/util/format.go index a825612f4..5adaec3b8 100644 --- a/util/format.go +++ b/util/format.go @@ -53,6 +53,7 @@ func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) { Funcs(sprig.TxtFuncMap()). Funcs(map[string]any{ "timeRound": timeRound, + "addDate": addDate, }).Parse(s) if err != nil { return s, err diff --git a/util/format_functions.go b/util/format_functions.go index 2ba39ea2c..db7ed9eb9 100644 --- a/util/format_functions.go +++ b/util/format_functions.go @@ -12,3 +12,7 @@ func timeRound(d time.Duration, round string) time.Duration { return d } } + +func addDate(ts time.Time, y, m, d int) time.Time { + return ts.AddDate(y, m, d) +}