Skip to content

Commit

Permalink
Add Frauenhofer ISE energy-charts-api | day ahead price (evcc-io#13706)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdkeil authored May 7, 2024
1 parent 1ff1513 commit 81ba7dc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

var (
//go:embed dist
// go:embed dist
web embed.FS

//go:embed i18n/*.toml
// go:embed i18n/*.toml
i18n embed.FS
)

Expand Down
14 changes: 13 additions & 1 deletion provider/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"math"
"strconv"
"strings"
"text/template"
"time"

"github.com/42atomys/sprout"
"github.com/evcc-io/evcc/provider/pipeline"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
Expand Down Expand Up @@ -162,8 +164,18 @@ func (p *HTTP) request(url string, body ...string) ([]byte, error) {
b = strings.NewReader(body[0])
}

tmpl, err := template.New("url").Funcs(sprout.TxtFuncMap()).Parse(url)
if err != nil {
return nil, err
}

builder := new(strings.Builder)
if err := tmpl.Execute(builder, nil); err != nil {
return nil, err
}

// empty method becomes GET
req, err := request.New(strings.ToUpper(p.method), url, b, p.headers)
req, err := request.New(strings.ToUpper(p.method), builder.String(), b, p.headers)
if err != nil {
return []byte{}, err
}
Expand Down
41 changes: 41 additions & 0 deletions templates/definition/tariff/energy-charts-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
template: energy-charts-api
products:
- brand: Fraunhofer ISE
description:
de: "Day-ahead Energiepreise (je kWh) an der Börse. Kann ohne vorherige Anmeldung auf https://api.energy-charts.info/ abgerufen werden. Nutzbar u.a. für dynamische Stromtarife, wo der Anbieter bis dato auf der Kundenschnittstelle noch kein Preis-Vorhersagen anbietet."
en: "Day-ahead forecast of energy prices (per kWh) on the exchange. No prior registration for https://api.energy-charts.info/ necessary. Can be used for dynamic electricity tariffs, for example, where the supplier does not yet offer a price forecast on the customer interface."
params:
- name: bzn
type: string
required: true
validvalues:
[
"AT",
"BE",
"CH",
"CZ",
"DE-LU",
"DE-AT-LU",
"DK1",
"DK2",
"FR",
"HU",
"IT-NORTH",
"NL",
"NO2",
"PL",
"SE4",
"SI",
]
default: DE-LU
description:
de: "Gebotszonen - https://api.energy-charts.info/#/prices/day_ahead_price_price_get"
en: "Bidding zones - https://api.energy-charts.info/#/prices/day_ahead_price_price_get"
- preset: tariff-base
render: |
type: custom
{{ include "tariff-base" . }}
forecast:
source: http
uri: https://api.energy-charts.info/price?bzn={{ .bzn }}&end={{ now | dateModify "+24h" | date "2006-01-02" }}
jq: '[.unix_seconds, .price] | transpose | map({ "start": (.[0] | todate), "end": ((.[0]+3600) | todate), "price": (.[1]/1000)}) | tostring'

0 comments on commit 81ba7dc

Please sign in to comment.