evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Volvo authentication is expiring every 7 days

Open yareblo opened this issue 1 year ago • 16 comments

Describe the bug

Hi, I am using evcc 0.205.0 with the new Volvo connector. Normally it is working very good. Unfortunately, every ~7 days the connection is lost. It can be restarted manually very quickly by:

  1. restart the evcc-service
  2. scan the log and call http://openhabian:7070/oauth/login?id=SuperSecret123
  3. approve everything until you get to the error page
  4. remove the "s" from the callback (httpS://openhabian...)
  5. restart the evcc-service

This works quite reliable. However, it is a bit annoying that evcc does not respect the charging limit and (maybe) charging plans when the connection is lost. It charges the vehicle to 100%.

Is there a way to avoid the expitation? Is the "s" in httpS the problem and how can it be fixed? Or, as a workaround, get the expiration date somewhere and refresh the token manually before it expires?

Steps to reproduce

  1. Use the Volvo connector
  2. Wait 7 days

...

Configuration details

[main  ] INFO 2025/07/27 10:15:29 using config file: /etc/evcc.yaml
[db    ] INFO 2025/07/27 10:15:29 using sqlite database: /var/lib/evcc/evcc.db
[oauth-generic] DEBUG 2025/07/27 10:15:29 loading token for Blubber from database
[oauth2redirect] INFO 2025/07/27 10:15:29 registering oauth provider at /oauth/login?id=Blubber 
[lp-1  ] WARN 2025/07/27 10:15:29 poll mode '{always 6m0s}' may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.
[lp-1  ] DEBUG 2025/07/27 10:15:30 charge total import: 674.259kWh

Konfiguration (/etc/evcc.yaml):

# open evcc at http://evcc.local:7070
network:
  schema: http
  host: evcc.local # .local suffix announces the hostname on MDNS
  port: 7070

log: debug
levels:
  cache: info

# unique installation id
plant: *****

interval: 30s # control cycle interval

meters:
- type: template
  template: rct-power
  usage: grid
  host: 192.168.178.6
  name: grid1
- type: template
  template: rct-power
  usage: pv
  host: 192.168.178.6
  name: pv2
- type: template
  template: rct-power
  usage: battery
  host: 192.168.178.6
  name: battery3

chargers:
- type: template
  template: homematic
  host: 192.168.178.4
  port: 2010
  device: '*****'
  user: *****
  password: *****
  standbypower: 15
  name: wallbox

loadpoints:
- title: Garage
  charger: wallbox
  mode: pv
  vehicle: db:1
  soc:
    poll:
      mode: always
      interval: 6m
  enable:
    threshold: 0
    delay: 10m
  disable:
    threshold: 0
    delay: 15m

site:
  title: My home
  meters:
    grid: grid1
    pv:
    - pv2
    battery:
    - battery3

tariffs:
  currency: EUR # (default EUR)
  grid:
    type: fixed
    price: 0.***** # EUR/kWh
  feedin:
    type: fixed
    price: 0.08 # EUR/kWh
  co2:
    type: template
    template: grünstromindex # Beispiel GrünstromIndex (nur Deutschland)
    zip: *****
    token: *****
  solar:
    - type: template
      template: forecast-solar
      lat: *****
      lon: *****
      dec: ***** # 0 = horizontal, 90 = vertikal
      kwp: ***** 
      az: - ***** # -180 = Norden, -90 = Osten, 0 = Süden, 90 = Westen, 180 = Norden
    - type: template
      template: forecast-solar
      lat: *****
      lon: *****
      dec: ***** # 0 = horizontal, 90 = vertikal
      kwp: ***** 
      az: ***** # -180 = Norden, -90 = Osten, 0 = Süden, 90 = Westen, 180 = Norden

vehicles:
  - name: guest_car
    title: Gast-Auto
    type: template
    template: offline
    capacity: *****  # in kWh

Version: `0.205.0`

Log details

Maybe this is the part:


Jul 26 16:42:38 openhabian evcc[3929]: [oauth-generic] DEBUG 2025/07/26 16:42:38 refreshing token for ****
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] WARN 2025/07/26 16:42:39 vehicle soc: Get "https://api.volvocars.com/energy/v2/vehicles/****/state": oauth2: "invalid_grant" "unknown, invalid, or expired re>
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] DEBUG 2025/07/26 16:42:39 soc estimated: 85.00% (vehicle: 85.00%)
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] DEBUG 2025/07/26 16:42:39 vehicle soc: 85%
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] ERROR 2025/07/26 16:42:39 vehicle soc limit: Get "https://api.volvocars.com/energy/v2/vehicles/****/state": oauth2: "invalid_grant" "unknown, invalid, or exp>
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] ERROR 2025/07/26 16:42:39 vehicle range: Get "https://api.volvocars.com/energy/v2/vehicles/****/state": oauth2: "invalid_grant" "unknown, invalid, or expired>
Jul 26 16:42:39 openhabian evcc[3929]: [lp-1  ] DEBUG 2025/07/26 16:42:39 limitSoc reached: 85.0% > 85%
J

What type of operating system or environment does evcc run on?

Linux

External automation

  • [x] I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.

Nightly build

  • [x] I have verified that the issue is reproducible with the latest nightly build

Version

0.205.0

yareblo avatar Jul 27 '25 08:07 yareblo

Is there a way to avoid the expitation?

As Volvo... We canm only make it simpler with https://github.com/evcc-io/evcc/pull/21266.

andig avatar Jul 27 '25 14:07 andig

As the developer of Volvo4EVCC i am also running into this same issue ,

And this is against the documentation of Volvo , as they claim with refresh key rotation the tokens should be valid longer than 7 days.

By default, refresh token rotation is enabled. Each time you call the Refresh endpoint, a new refresh token is created, and the old token is invalidated. If not rotated, the refresh_token is valid for 7 days. After that, the user has to re-authenticate.

I am expirimenting with cold tokens to not keep the token hot to see if that brings a differance and we are in conversation with Volvo as this seems a bug / not correctly implemented from their end when they switched to the V2 and shortend the lifespan of the active token. (i am only a few days in the expiriment so will take some more time till i have the results)

But they are on holiday for atleast another month so we have to wait till volvo somes back.

MartijnvanGeffen13 avatar Aug 07 '25 13:08 MartijnvanGeffen13

small update

20250810-1625 Info: Just a Evcc pull and token test no action taken - Token valid for another : -9.4 minutes 20250810-1625 Info: Connected - Not charging - Slow refresh of volvo SOC data 20250810-1625 Info: Token is expired trying to get new one 20250810-1625 Warning: { "error_description": "unknown, invalid, or expired refresh token", "error": "invalid_grant" }

Keeping tokens cold still expires the refresh token , hence Volvo docs is now incorrect with the working of their API.

So they either have a new policy that is not communicated or someone made a boe boe when configuring the new token API shorter lifetime and also decreased the refresh token life time accidently.

MartijnvanGeffen13 avatar Aug 11 '25 09:08 MartijnvanGeffen13

One thing I always do when coding against external API's is I take x amount of time from the given expiration time (most api's return an expiration with the token response).

Does the response body contain an expiration and does it match up with the 7 days?

ThaDaVos avatar Oct 27 '25 12:10 ThaDaVos

I tried going through the code - but couldn't find where it does the refresh handling of the refresh token that quickly - but I would recommended trying to refresh the token every 3 days - that way we are in the refresh time limit (hopefully) and it should keep running

ThaDaVos avatar Oct 27 '25 12:10 ThaDaVos

I tried going through the code - but couldn't find where it does the refresh handling of the refresh token that quickly - but I would recommended trying to refresh the token every 3 days - that way we are in the refresh time limit (hopefully) and it should keep running

Volvo has , (even though not documented ) changed there policy.

The token is now only valid for a few minutes and the chain gets invalidated for after 6,5 days. And than permissions have to be granted again via user flow.

So there is no way to automate this. And to your question , yes EVCC takes token expiration and renews for as long as the chain allows.

Btw never had a response from Volvo on the policy change or the now "conflict" with the documentation.

MartijnvanGeffen13 avatar Oct 27 '25 12:10 MartijnvanGeffen13

Sounds like a bug - but I also read something about PKCE being required now:

Image

Docs still say 7 days though:

Image

Still also sounds like rotation can be disabled - but cannot find it anywhere in the docs

ThaDaVos avatar Oct 27 '25 12:10 ThaDaVos

Sent Volvo and email myself - let's hope I get a response

ThaDaVos avatar Oct 27 '25 12:10 ThaDaVos

Sounds like a bug - but I also read something about PKCE being required now: Docs still say 7 days though: Still also sounds like rotation can be disabled - but cannot find it anywhere in the docs

This was all changed when they moved to the new V2 API about 2-3 months ago

It does not describe token chain lifetime, and the access token now is thought 10/15 mins top of mind. This means for continues pull you need a new refresh token every 15 min as you rotate when you request a new access token.

This is currently in place in EVCC together with PKCE. (Also build this in into my own app).

but afther about 6,5 days the Token chain gets invalidated by Volvo to make sure the enduser keeps in controle and needs to regrant permissions to the API key use by EVCC.

This breaks the automation as its user initiated. (There are some "robot" ways to automate but thats not native in EVCC at the moment.)

MartijnvanGeffen13 avatar Oct 27 '25 12:10 MartijnvanGeffen13

It would be nice to document the need for manual refresh in the template.

andig avatar Oct 27 '25 19:10 andig

I tried going through the code - but couldn't find where it does the refresh handling of the refresh token that quickly - but I would recommended trying to refresh the token every 3 days - that way we are in the refresh time limit (hopefully) and it should keep running

Added in https://github.com/evcc-io/evcc/pull/24857

andig avatar Oct 30 '25 08:10 andig

Haven't received a mail back from Volvo sadly

ThaDaVos avatar Nov 01 '25 12:11 ThaDaVos

Has something changed? Mine has been running for days now without needing to re-authenticate - I am gonna keep monitoring it, but I am hopeful!

ThaDaVos avatar Dec 08 '25 09:12 ThaDaVos

Question should be asked to Volvo support!

andig avatar Dec 08 '25 09:12 andig

Volvo support who doesn't answer? But still, asking here cause I am curious if others have noticed the same - or if there is a certain trigger which causes the re-auth, hence why I said I am monitoring it.

ThaDaVos avatar Dec 08 '25 09:12 ThaDaVos

Volvo’s documentation on the refresh token has recently changed. There does indeed seem to be an update to their policy:

By default, refresh token rotation is enabled. Each time you call the Refresh endpoint, a new refresh token is created, and the old token is invalidated. The refresh_token must be used within 7 days or else it will be invalidated. The maximum lifetime of the grant is 6 months, if refreshed continuously. After that, the user has to re-authenticate.

fyrts avatar Dec 08 '25 09:12 fyrts