Skip to content

Commit

Permalink
add formular to tariff-base, add math
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Nov 5, 2024
1 parent 03ad8e8 commit 1de1548
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions evcc.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ tariffs:
# uri: https://example.org/price.json
# jq: .price.current

# type: template
# template: energy-charts-api # epex spot market prices
# bzn: DE-LU
# charges: 0.15
# tax: 0.1
# formula: math.Min((price + charges) * (1 + tax), 0.5)

feedin:
# rate for feeding excess (pv) energy to the grid
type: fixed
Expand Down
4 changes: 4 additions & 0 deletions tariff/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (t *embed) init() error {
return err
}

if _, err := vm.Eval(`import "math"`); err != nil {
return err
}

if _, err := vm.Eval("var price, charges, tax float64"); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions util/templates/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ presets:
help:
de: Zusätzlicher prozentualer Aufschlag (z.B. 0.2 für 20%)
en: Additional percentage charge (e.g. 0.2 for 20%)
- name: formula
type: string
help:
de: Individuelle Formel zur Berechnung des Preises
en: Individual formula for calculating the price
example: "math.Max((price + charges) * (1 + tax), 0.0)"
eebus:
params:
- name: ski
Expand Down
3 changes: 3 additions & 0 deletions util/templates/includes/tariff-base.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ charges: {{ .charges }}
{{- if .tax }}
tax: {{ .tax }}
{{- end }}
{{- if .formula }}
formula: {{ .formula }}
{{- end }}
{{- end }}

0 comments on commit 1de1548

Please sign in to comment.