The Tibber template does not use “formula”.
Description
According to the documentation, the Tibber price should be adjustable using a formula:
tariffs:
grid:
type: template
template: tibber
token: *** # API Token
homeid: *** # Home ID, Nur erforderlich, wenn du mehrere Häuser in deinem Tibber-Konto hast. (optional)
charges: # Aufschlag, Zusätzlicher fester Aufschlag pro kWh (z.B. 0.05 für 5 Cent) (optional)
tax: # Steuer, Zusätzlicher prozentualer Aufschlag (z.B. 0.2 für 20%) (optional)
formula: math.Max((price + charges) * (1 + tax), 0.0) # Formel, Individuelle Formel zur Berechnung des Preises (optional)
I have entered a corresponding formula in the “grid” in the UI:
grid:
type: template
template: tibber
token: *****
formula: if ts.Hour() < 6 { price = price - 0.1069 } else if ts.Hour() >= 15 && ts.Hour() < 20 { price = price + 0.0587 }
There is no error message, but the formula is not applied. Neither immediately nor when new rates are retrieved from the Tibber API.
I can't find any indication as to whether formulas are applied immediately or when new rates come into effect. However, I was able to rule out this functionality in both cases.
Thank you very much for your support! -Boris
Steps to Reproduce
- Go to Config-UI
- Add Formula to Tariff Tibber
- Doesn´t work as expected.
Configuration (YAML)
# open evcc at http://evcc.local:7070
network:
schema: http
host: ***** # .local suffix announces the hostname on MDNS
port: 7070
#log: info
log: debug
levels:
cache: error
# unique installation id
plant: *****
# database configuration for persisting charge sessions and settings
database:
type: sqlite
dsn: /var/lib/evcc/evcc.db
mqtt:
broker: *****:1883
topic: evcc
interval: 30s # control cycle interval
#tariffs:
# currency: EUR # (default EUR)
# grid:
# type: template
# template: tibber
# token: *****
# formula: if ts.Hour() < 6 { price = price - 0.1069 } else if ts.Hour() >= 15 && ts.Hour() < 20 { price = price + 0.0587 };
# static grid price
# type: fixed
# price: 0.2899 # [currency]/kWh
# feedin:
# # rate for feeding excess (pv) energy to the grid
# type: fixed
# price: 0.08 # [currency]/kWh
# co2:
# type: grünstromindex
# zip: *****
# solar:
# type: template
# template: forecast-solar
# lat: *****
# lon: *****
# dec: 20 # 0 = horizontal, 90 = vertikal
# az: 20 # -180 = Norden, -90 = Osten, 0 = Süden, 90 = Westen, 180 = Norden
# kwp: 12,45
meters:
#- type: template
# template: tasmota
# id: 1
# host: *****
# usage: grid
# name: grid1
#- type: template
# template: sungrow-inverter
# id: 1
# host: *****
# port: 502
# usage: pv
# modbus: tcpip
# name: pv2
- type: template
template: deye
host: *****
port: 80
user: *****
password: *****
usage: pv
name: bkw
#- type: template
# template: deye-mi
# usage: pv
# # Modbus TCP
# modbus: tcpip
# id: 1
# host: ***** # Hostname
# port: 8899 # 502 # Port
# name: bkw
#
#
##### Neuer Deye Hybrid:
#- name: deye-hybrid_grid
# type: template
# template: deye-hybrid-3p
# usage: grid
# # Modbus TCP
# modbus: tcpip
# id: 1
# host: ***** # IP of deye-mbusd
# port: 502 # Port
# minsoc: 25 # Ladung mit maximaler Geschwindigkeit bis zu dem angegeben Ladestand unabhängig PV-Erzeugung, wenn der Lademodus nicht auf 'Aus' steht (optional)
# maxsoc: # optional
- name: deye-hybrid_grid
type: template
template: deye-hybrid-3p
usage: grid
modbus: tcpip
id: 1
host: ***** # IP of deye-mbusd
port: 502 # Port
- name: deye-hybrid_pv
type: template
template: deye-hybrid-3p
usage: pv
# Modbus TCP
modbus: tcpip
id: 1
host: ***** # IP of deye-mbusd
port: 502 # Port
- name: deye-hybrid_battery
type: template
template: deye-hybrid-3p
usage: battery
# Modbus TCP
modbus: tcpip
id: 1
host: ***** # IP of deye-mbusd
port: 502 # Port
capacity: 30 # Akkukapazität in kWh (optional)
minsoc: 10 # Ladung mit maximaler Geschwindigkeit bis zu dem angegeben Ladestand unabhängig PV-Erzeugung, wenn der Lademodus nicht auf 'Aus' steht (optional)
maxsoc: 95 # optional
maxacpower: 7400 # W
# maxchargepower: 7400 # W
# maxdischargepower: 7400 # W
chargers:
#- type: template
# template: ellipro
# ski: *****
# ip: *****
# name: wallbox4
#- type: template
# template: ellipro
# ski: *****
# ip: *****
# name: wallbox5
- type: eebus
ski: xxx
meter: true
chargedEnergy: false
ip: *****
name: wallbox4
- type: eebus
ski: xxx
meter: true
chargedEnergy: false
ip: *****
name: wallbox5
#- name: bat_sperre
# type: template
# template: demo-charger
# status: C
# enabled: true
#- name: e-bike
# type: template
# template: tasmota
# host: ***** # IP-Adresse oder Hostname
# channel: 1 # Nummer des Schaltkanals (1-8), bei Geräten mit mehr als einem Schalter
#vehicles:
# - name: ev3
# type: template
# template: tesla
# title: Lightning
# accessToken: *****
# refreshToken: *****
# vin: *****
# commandProxy: http://*****:8080/
#vehicles:
#- type: template
# template: tesla
# title: Lightning
# accessToken: *****
# refreshToken: *****
# vin: *****
# capacity: 82
# name: ev3
# icon: car
#- name: ranger
# type: custom
# icon: bike
# title: Cyrusher Ranger # display name for UI
# capacity: 1 # byttery capacity (kWh)
loadpoints:
- title: WB-Boris
charger: wallbox4
mode: pv
# phases: 3
# mincurrent: 6
# maxcurrent: 16
# resetOnDisconnect: false
circuit: outbuilding
priority: 10
- title: WB-Maren
charger: wallbox5
mode: pv
# phases: 3
# mincurrent: 6
# maxcurrent: 16
# resetOnDisconnect: false
circuit: outbuilding
priority: 5
#- title: Nebengebäude
# vehicle: ranger
# charger: e-bike
# mode: pv
# phases: 1
# resetOnDisconnect: false
#- title: "Hausbatterie Sperre"
# charger: bat_sperre
# mode: pv
site:
title: Passivhaus im Siegbogen
meters:
grid: deye-hybrid_grid
battery: deye-hybrid_battery
pv:
- deye-hybrid_pv
- bkw
eebus:
certificate:
private: |
-----BEGIN EC PRIVATE KEY-----
-----END EC PRIVATE KEY-----
public: |
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
Configuration (UI)
{
"site": {
"title": "Passivhaus im Siegbogen",
"grid": "deye-hybrid_grid",
"pv": ["deye-hybrid_pv","bkw"],
"battery": ["deye-hybrid_battery"],
"aux": null,
"ext": null
},
"loadpoints": [],
"charger": [],
"meter": [],
"vehicle": [
{"config":{"capacity":82,"icon":"car","port":"8080","template":"tesla-ble","title":"Lightning","url":"http://*****","vin":"*****"},"id":1,"name":"db:1","type":"template"}
],
"circuits": "- name: main
title: Hauptsicherung
maxCurrent: 50
meter: deye-hybrid_grid # optional
- name: outbuilding
title: Nebengebäude
maxCurrent: 32
parent: main",
"eebus": "uri: :4712
shipid: \"\"
interfaces: []
certificate:
public: |
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
private: |
-----BEGIN EC PRIVATE KEY-----
-----END EC PRIVATE KEY-----",
"tariffs": "currency: EUR
grid:
type: template
template: tibber
token: *****
# formula: math.Max(price + 5, 0.0)
formula: if ts.Hour() < 6 { price = price - 0.1069 } else if ts.Hour() >= 15 && ts.Hour() < 20 { price = price + 0.0587 }
# formula: extra := 0.0; if ts.Hour() > 0 || ts.Hour() < 6 { extra = 0.1069 }; price - extra
# formula: extra := 0.0; if ts.Hour() >= 0 || ts.Hour() <= 6 { extra = -0.1069 } else if ts.Hour() >= 15 || ts.Hour() <= 20 { extra = 0.0587 }; price + extra
feedin:
type: fixed
price: 0.08
co2:
type: grünstromindex
zip: 53773
solar:
type: template
template: solcast
site: *****
token: ***** # Solcast API Token"
}
Logs
[circuit-main] DEBUG 2025/10/23 17:00:26 power: 21W
[circuit-main] DEBUG 2025/10/23 17:00:26 current: 2.51A
[site ] DEBUG 2025/10/23 17:00:26 pv 2 power: 13W
[site ] DEBUG 2025/10/23 17:00:26 grid power: 21W
[site ] DEBUG 2025/10/23 17:00:26 battery 1 power: 882W
[site ] DEBUG 2025/10/23 17:00:29 battery 1 soc: 87%
[site ] DEBUG 2025/10/23 17:00:29 pv 1 power: 11W
[site ] DEBUG 2025/10/23 17:00:29 grid currents: [2.12 2.17 2.51]A
[site ] DEBUG 2025/10/23 17:00:30 pv power: 24W
[site ] DEBUG 2025/10/23 17:00:30 !! solar production: accumulate set deye-hybrid_pv 15093.400kWh meter total (was: Accumulated: 5728.500kWh updated: 2025-10-23 17:00:00 +0200 CEST meter: 15093.400kWh)
[site ] DEBUG 2025/10/23 17:00:30 !! solar production: accumulate moved deye-hybrid_pv from 5728.500 to 5728.500
[site ] DEBUG 2025/10/23 17:00:30 !! solar production: accumulate set bkw 1793.300kWh meter total (was: Accumulated: 305.691kWh updated: 2025-10-23 17:00:00 +0200 CEST meter: 1793.300kWh)
[site ] DEBUG 2025/10/23 17:00:30 !! solar production: accumulate moved bkw from 305.691 to 305.691
[site ] DEBUG 2025/10/23 17:00:30 site power: 1003W
[lp-1 ] DEBUG 2025/10/23 17:00:30 charger status: A
[site ] DEBUG 2025/10/23 17:00:30 solar forecast: accumulated 0.003Wh from 2025-10-23 17:00:00 +0200 CEST to 2025-10-23 17:00:30 +0200 CEST
[site ] DEBUG 2025/10/23 17:00:30 solar forecast: produced 6034.191
[site ] DEBUG 2025/10/23 17:00:30 solar forecast: accumulated 6239.109kWh, produced 6034.191kWh, scale 0.967
[site ] DEBUG 2025/10/23 17:00:55 ----
[lp-2 ] DEBUG 2025/10/23 17:00:55 charge power: 0W
[lp-2 ] DEBUG 2025/10/23 17:00:55 charge currents: [0 0 0]A
[lp-1 ] DEBUG 2025/10/23 17:00:55 charge power: 0W
[lp-1 ] DEBUG 2025/10/23 17:00:55 charge currents: [0 0 0]A
[circuit-outbuilding] DEBUG 2025/10/23 17:00:55 power: 0W
[circuit-outbuilding] DEBUG 2025/10/23 17:00:55 current: 0A
Version
v0.209.3
Tibber is a bit odd as we're using different base fields if formula or not:
price := r.Total
if t.Charges != 0 || t.Tax != 0 {
price = t.totalPrice(r.Energy, r.StartsAt)
}
This check needs to check if formula is set, too. Happy to take a PR. Always easier when you know where to look...
Tibber is a bit odd as we're using different base fields if formula or not:
price := r.Total if t.Charges != 0 || t.Tax != 0 { price = t.totalPrice(r.Energy, r.StartsAt) }This check needs to check if formula is set, too. Happy to take a PR.
Great that the bug was found. Unfortunately, I'm the infrastructure and hardware guy and probably the worst programmer in the world. So I don't feel confident enough to do a PR. But I'm happy to test.
No problem, closed in 439bb308efb200babd738429ca4a770e435b0246
Hey @andig, I tried this today with the latest Nightly build.
The formula is now being applied. However, I now have a different strange result.
Normally, the Tibber API always provides the price including grid fees.
Without formula:
When I activate my formula, the price is calculated based on the price without grid fees. They just suddenly disappear. Even when I explicitly add “tax” and “charges” again, the variables appear to be empty.
formula: if ts.Hour() < 6 { price = price + charges + tax - 0.1069 } else if ts.Hour() >= 15 && ts.Hour() < 20 { price = price + charges + tax + 0.0587 } else { price = price + charges + tax }
With formula:
Approximately 21 cents in taxes and network charges have suddenly disappeared. However, my formula now calculates correctly with the wrong "offset".
I would really appreciate some help. Maybe I'm just too stupid and misunderstanding something.
Thanks! -Boris
Tats what I‘ve said before: https://github.com/evcc-io/evcc/issues/24673#issuecomment-3442077908
Tats what I‘ve said before: #24673 (comment)
Thanks, I just didn't understand that comment. It makes sense if you only have the electricity price and want to correct something with an individual tax/grid fee.
It doesn't work in my case. As a workaround, I've now simply defined 21.5 cents as charges and added them. It looks reasonably correct.
Thanks for your support!
As a workaround, I've now simply defined 21.5 cents as charges and added them
That‘s what they‘re there for.