Feature request: integrate Tibber for vehicle data, especially from Volkswagen Konzern
Is your feature request related to a problem? Please describe. The connection to vehicles of Volkswagen/Audi/Skoda/Cupra using there API will be limited. Only commercial services can access the car data using their API in the future.
Describe the solution you'd like Tibber is one of the commercial services, which can access the VW API officially. And Tibber also has a documented API, which allows to access the vehicle data as well. It is even possible to register to the Tibber services without having a contract with Tibber. It would be nice to offer a vehicle connection via Tibber into EVCC. This would work for any vehicle, which is supported in Tibber.
Describe alternatives you've considered There is a possibility to access data from Volkswagen/Skoda etc. via the new EU data connection, but this does not provide the data in the required frequency.
Additional context The docs for the new Tibber Data API is described here: https://data-api.tibber.com/docs/ It can be accessed using an OAuth2 client.
pressure Volkswagen to fix the world via https://www.bundesnetzagentur.de/_tools/05_Digitalisierung/DataAct/Form01_Beschwerde_II_III/node.html
otherwise we soon need to ask the smart refrigerator for the SOC via tibber via home assistant
There is always an integration to Tibber existing in EVCC using the old API (only for dynamic tariffs and other data). Why not replacing the old API by the new API and getting more options from Tibber? The new API contains the data, which is already used by EVCC + additional data (e.g. vehicle, PV, battery,…)
pressure Volkswagen to fix the world via https://www.bundesnetzagentur.de/_tools/05_Digitalisierung/DataAct/Form01_Beschwerde_II_III/node.html
Volkswagen already provides data access based on EU data act, but this seems to be not sufficient for our use cases.
the point is: if Volkswagen can provide useful data via tibber, it should provide it to every car owner.
You can already do this if you have Home Assistant. I quickly connected my ID7 through my Tibber account (I don't even have a contract with Tibber yet). Then I went into Home Assistant and installed the Tibber integration. You should then see the VW ID. If that worked, you can select a new vehicle under EVCC and choose Home Assistant. Log in there and add the necessary sensors. Reboot complete....
In German, they say "through the chest and into the eye," but it works...
The docs for the new Tibber Data API is described here:
Needs an account for testing (send to [email protected]). Happy to accept a PR.
Got this working end-to-end, so here's a complete recipe for anyone who wants their car's SoC in evcc via the new Tibber Data API. Works for any vehicle Tibber supports (I'm on an Audi e-tron, i.e. VW Group, where the direct connection is dying anyway). No native evcc support needed - we wire it up as a custom vehicle.
What you need:
- A Tibber account with your car already added in the Tibber app (you should see the SoC there).
- evcc running on something with
bash+curl(Raspberry Pi here).
1. Create an OAuth2 client
Go to https://data-api.tibber.com/clients/manage and log in with the same Tibber account your car lives in.
Create a client:
- Redirect URI:
http://localhost - Scopes:
openid,profile,email,offline_access,data-api-user-read,data-api-homes-read,data-api-vehicles-read
The data-api-vehicles-read scope is the one that matters - that's the car. Copy the Client ID and Client Secret (the secret is shown only once).
2. One-time browser login
Open this in a browser (paste your client id in):
https://thewall.tibber.com/connect/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost&scope=openid%20profile%20email%20offline_access%20data-api-user-read%20data-api-homes-read%20data-api-vehicles-read&state=evcc
Approve it. Your browser then jumps to http://localhost/?code=...&state=evcc - the page won't load (there's no server), that's fine. Copy the value between code= and &state out of the address bar.
3. Trade the code for tokens
Do this quickly, the code expires in a few minutes:
curl -s -X POST https://thewall.tibber.com/connect/token \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=YOUR_CODE" \
--data-urlencode "redirect_uri=http://localhost/" \
--data-urlencode "client_id=YOUR_CLIENT_ID" \
--data-urlencode "client_secret=YOUR_CLIENT_SECRET"
You get back JSON with an access_token and a refresh_token. Keep the refresh_token - that's the long-lived one the script uses.
4. Find your home id and device id
Stick the access_token from step 3 into a variable, then list your homes:
export TOK="PASTE_ACCESS_TOKEN"
curl -s -H "Authorization: Bearer $TOK" https://data-api.tibber.com/v1/homes
Grab the home id, then list its devices - your car shows up here (EVs appear on every home you have):
curl -s -H "Authorization: Bearer $TOK" https://data-api.tibber.com/v1/homes/YOUR_HOME_ID/devices
Note the car's id (a long base64-looking string). To see what's available, query the device directly:
curl -s -H "Authorization: Bearer $TOK" "https://data-api.tibber.com/v1/homes/YOUR_HOME_ID/devices/YOUR_DEVICE_ID"
You'll find the SoC under the capability storage.stateOfCharge, plus range.remaining (in metres), plug status, charging status etc.
5. The script
This pulls a fresh access token when needed (and automatically rotates the refresh token, which Tibber invalidates on every use), caches the device response for 30 s so soc and range don't cost two API calls, and prints just the number evcc wants.
Pick a directory your evcc user can read/write (see note below). Save your current refresh token there first:
sudo mkdir -p /opt/tibber
echo 'YOUR_REFRESH_TOKEN' | sudo tee /opt/tibber/refresh_token >/dev/null
Then create /opt/tibber/tibber-car.sh:
#!/bin/bash
# Tibber Data API -> car SoC/range for evcc. Usage: tibber-car.sh [soc|range]
DIR="/opt/tibber"
CLIENT_ID="YOUR_CLIENT_ID"
CLIENT_SECRET="YOUR_CLIENT_SECRET"
HOME_ID="YOUR_HOME_ID"
DEVICE_ID="YOUR_DEVICE_ID"
TOKEN_URL="https://thewall.tibber.com/connect/token"
API="https://data-api.tibber.com/v1/homes/$HOME_ID/devices/$DEVICE_ID"
FIELD="${1:-soc}"
now=$(date +%s)
TOK=""
if [[ -f "$DIR/access_token" && -f "$DIR/access_expiry" ]]; then
exp=$(cat "$DIR/access_expiry")
if (( exp - now > 120 )); then TOK=$(cat "$DIR/access_token"); fi
fi
if [[ -z "$TOK" ]]; then
RT=$(cat "$DIR/refresh_token")
RESP=$(curl -s -X POST "$TOKEN_URL" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "refresh_token=$RT" \
--data-urlencode "client_id=$CLIENT_ID" \
--data-urlencode "client_secret=$CLIENT_SECRET")
TOK=$(echo "$RESP" | grep -oP '"access_token":"\K[^"]+' || true)
NEWRT=$(echo "$RESP" | grep -oP '"refresh_token":"\K[^"]+' || true)
EXPIN=$(echo "$RESP" | grep -oP '"expires_in":\K[0-9]+' || true)
if [[ -z "$TOK" || -z "$NEWRT" ]]; then echo "ERROR refresh: $RESP" >&2; exit 1; fi
echo "$TOK" > "$DIR/access_token"
echo "$NEWRT" > "$DIR/refresh_token"
echo $(( now + EXPIN )) > "$DIR/access_expiry"
fi
CACHE="$DIR/device_cache.json"
if [[ -f "$CACHE" ]] && (( now - $(stat -c %Y "$CACHE") < 30 )); then
DATA=$(cat "$CACHE")
else
DATA=$(curl -s -H "Authorization: Bearer $TOK" "$API")
echo "$DATA" > "$CACHE"
fi
case "$FIELD" in
soc)
V=$(echo "$DATA" | grep -oP '"id":"storage\.stateOfCharge"[^}]*"value":\K[0-9]+' || true) ;;
range)
M=$(echo "$DATA" | grep -oP '"id":"range\.remaining"[^}]*"value":\K[0-9]+' || true)
[[ -n "$M" ]] && V=$(( M / 1000 )) ;;
*) echo "unknown field: $FIELD" >&2; exit 1 ;;
esac
if [[ -z "$V" ]]; then echo "ERROR $FIELD: $DATA" >&2; exit 1; fi
echo "$V"
Make it executable and hand the whole directory to evcc's user (find it with systemctl show -p User --value evcc - it's usually evcc, not your login user):
sudo chmod +x /opt/tibber/tibber-car.sh
sudo chown -R evcc:evcc /opt/tibber
sudo chmod 750 /opt/tibber
Test it as the evcc user - this is exactly how evcc runs it:
sudo -u evcc /opt/tibber/tibber-car.sh soc
sudo -u evcc /opt/tibber/tibber-car.sh range
You should get the SoC (e.g. 83) and range in km (e.g. 324).
6. Wire it into evcc
In your vehicles: section:
- type: custom
title: My Car
capacity: 95 # your battery kWh
name: mycar
soc:
source: script
cmd: /opt/tibber/tibber-car.sh soc
timeout: 30s
cache: 1m
range:
source: script
cmd: /opt/tibber/tibber-car.sh range
timeout: 30s
cache: 1m
Restart evcc and you're done.
Notes / gotchas
- Refresh token rotates. Tibber hands out a new refresh token on every refresh and kills the old one. The script writes the new one back to
refresh_token, so you never touch it again - as long as the script keeps running. - ~30-day expiry. If evcc (and the script) sits idle for longer than ~30 days, the refresh token expires and you redo the one-time browser login from step 2. In normal 24/7 operation this never happens.
- Polling faster than ~1 min is pointless. The car only reports to Tibber every few minutes (and rarely while parked), and evcc extrapolates the SoC from your wallbox's energy meter between fetches anyway.
cache: 1mis a sensible floor; the device cache keeps it to one real API call per minute regardless. - Stick to SoC (+ optionally range). Plug/charging status from Tibber only tells you the car is plugged in somewhere, not at your box - let your wallbox report that. Don't bother importing it.
Hope this saves someone the reverse-engineering. 🔌
Cheers, Mirko P.S. - honestly, VW kind of had this coming. Their own works club, VfL Wolfsburg, just got relegated from the Bundesliga, and I'm choosing to read that as divine punishment for locking down the car API and ignoring open data. 😇 Meanwhile, a warm welcome to Paderborn and tiny SV Elversberg (who earned their first-ever Bundesliga promotion the honest way.) ⚽
a warm welcome to Paderborn and tiny SV Elversberg (who earned their first-ever Bundesliga promotion the honest way.) ⚽
Even though I'm not a soccer fan, as someone from the Saarland, I was happy to see us back in the "ersten Bundesliga".
Sorry for off-topic
Thanks for the recipe, but I am stuck. First obstackle was, creating an account. It seems this is not possible on the website, but only in the mobile app. Then, after setting everything up and creating the clients, this does not work:
2. One-time browser login
Open this in a browser (paste your client id in):
https://thewall.tibber.com/connect/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost&scope=openid%20profile%20email%20offline_access%20data-api-user-read%20data-api-homes-read%20data-api-vehicles-read&state=evcc
When pasting a valid client ID, I get "Entschuldigung, es ist ein Fehler aufgetreten : invalid_request" When pasting an imaginary non-existent client id, at least it shows: "unauthorized_client"
Any clue?
It would be so much easier for users to put this into a proper integration: https://github.com/evcc-io/evcc/issues/30468#issuecomment-4614079095
Finally I get the soc into evcc, but involving home-assistant. So my dataflow is like: Car->cariad->tibber->home-assistant->evcc
One thing about the chargingstate: evcc uses values A,B&C, but the tibber ha-integration uses two binary sensors: binary_sensor.id_3_stecker and binary_sensor.id_3_ladestatus
So, I mapped it in the vehicle section in evcc.yaml like:
status: source: template template: | {% if is_state('binary_sensor.dein_tibber_charging_status', 'on') %} C {% elif is_state('binary_sensor.dein_tibber_connected_status', 'on') %} B {% else %} A {% endif %}
This seems so work so far, but how does the automatic vehicle detection work? Before, when using the VW connect integration, the vehicle was detected, now, the spinner keeps spinning and I have to manually select the car.
@Seichobob do you know if reading vehicles for unknown home is possible without the read-homes scope?
PR up for testing. The account that was kindly shared with me doesn't have vehicle associated so I couldn't fully test this.
@Seichobob do you know if reading vehicles for unknown home is possible without the read-homes scope?
@andig: Just checked my script, it works even without "data-api-homes-read" permission.
PR up for testing. The account that was kindly shared with me doesn't have vehicle associated so I couldn't fully test this.
Looks perfect, SoC is available 👍
I did a HomeAssistant integration in EVCC with the HA Tibber integration, didn't try this PR yet, but I did notice the following:
If the car is connected without enough solar surplus in solar mode, my VW app gives an error that there is an issue with the charger. As the Tibber API is read-only, we can't send a charge.start or charge.stop as the VW integration used to do. Hence, a welcome charge was needed at my end to get rid of that issue. This might need to be included in the native evcc Tibber integration.
Also, I can confirm that HA-integrated tibber with evcc works like a charm for charging my ID7.