evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Hyundai/Kia EU (CCI): two vehicles on the same Bluelink account invalidate each other's token (race on refresh)

Open domwuk opened this issue 3 weeks ago • 2 comments

Describe the bug

Two Hyundai vehicles (INSTER, IONIQ 5) on the same Bluelink EU account, both configured with the real account password and vin. One of the two vehicles regularly loses its connection: on startup, or later after a token rotation, the other vehicle fails with 400 on token refresh or 401 on CCS token exchange and is then shown as a guest when connected.

Follow-up to #34805 (closed after switching to password; switching to password did not help here).

Cause (code inspection, current master): in vehicle/bluelink/cci.go each vehicle creates its own Identity. All of them persist to the same key (settingsKey() → bluelink-cci.<brand>.<user>), but each keeps its own in-memory bundle (settings.Json(v.settingsKey(), &v.bundle)) and refreshes independently (refreshCCI). There is no lock and no shared identity, so:

  1. On startup both vehicles refresh the same persisted refresh token in the same second → the second one gets 400 (token already rotated) and falls back to password login, which then fails as well.
  2. At runtime, when one vehicle rotates the token, the other one's in-memory copy goes stale → ccs token exchange failed: 401 on every poll.

Suggested fix: share one CCI identity/token bundle per brand+user across vehicles (e.g. a package-level map guarded by a mutex), or at least lock per user and re-read the persisted bundle before refreshing.

Steps to reproduce

  1. Configure two hyundai template vehicles with the same user/password (EU), different vin.
  2. Start evcc with an existing persisted CCI token that needs refreshing → both vehicles log cci: refreshing token in the same second; one gets 400 and is not created.
  3. Restart shortly afterwards (token fresh, "using persisted token" twice) → both work, until the next token rotation (~16 h here), after which the other vehicle gets 401 on every status request.

Configuration details

vehicles:
- name: ioniq5
  type: template
  template: hyundai
  title: IONIQ 5
  region: Europe
  capacity: 77
  phases: 3
  cache: 15m
  language: de
  user: ***         # same account for both
  password: ***     # real account password
  vin: ***
- name: inster
  type: template
  template: hyundai
  title: INSTER
  region: Europe
  capacity: 49
  phases: 3
  cache: 15m
  language: de
  user: ***
  password: ***
  vin: ***

chargers:
- name: go-e-gemini
  type: template
  template: go-e-v3
  host: 192.168.x.x

loadpoints:
- title: Garage
  charger: go-e-gemini
  mode: pv

log: info
levels:
  hyundai: debug
  lp-1: debug

Log details

Startup (evcc 0.319.0):

[main  ] INFO  2026/11/14 20:08:21 evcc 0.319.0
[hyundai] DEBUG 2026/11/14 20:08:22 cci: refreshing token
[hyundai] DEBUG 2026/11/14 20:08:22 cci: refreshing token
[hyundai] WARN  2026/11/14 20:08:22 cci: refreshing persisted token failed: cci token refresh failed: unexpected status: 400 (Bad Request) POST https://cci-api-eu.hyundai.com/auth/v2/token-refresh
[hyundai] DEBUG 2026/11/14 20:08:22 cci: logging in via OneApp/CCI password login
[main  ] ERROR 2026/11/14 20:08:22 creating vehicle ioniq5 failed: cannot create vehicle type 'template': cannot create vehicle type 'hyundai': login failed: unexpected redirect after signin: https://idpconnect-eu.hyundai.com/auth/api/v2/user/oauth2/authorize?...
[hyundai] DEBUG 2026/11/14 20:08:22 cci: refresh successful
[site  ] INFO  2026/11/14 20:08:23     vehicle 1: range ✓ status ✓ climate ✓ wakeup ✓
[site  ] INFO  2026/11/14 20:08:23     vehicle 2: range ✗ status ✗ climate ✗ wakeup ✗

Restart three minutes later (both OK):

[hyundai] DEBUG 2026/11/14 20:11:01 cci: using persisted token
[hyundai] DEBUG 2026/11/14 20:11:01 cci: using persisted token
[site  ] INFO  2026/11/14 20:11:02     vehicle 1: range ✓ status ✓ climate ✓ wakeup ✓
[site  ] INFO  2026/11/14 20:11:02     vehicle 2: range ✓ status ✓ climate ✓ wakeup ✓

Runtime failure of the other vehicle after a previous start (~16 h later, repeats on every poll):

[main  ] ERROR 2026/11/14 02:44:39 vehicle status: Get "https://prd.eu-ccapi.hyundai.com:8080/api/v1/spa/vehicles/<id>/status/latest": ccs token exchange failed: unexpected status: 401 (Unauthorized) POST https://cci-api-eu.hyundai.com/auth/v1/token-exchange?serviceType=CCS

A trace log (levels: vehicle: trace) of the next runtime failure will be added as a comment.

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

Linux (Debian package, Raspberry Pi 3B+)

External automation

No external automation accesses evcc or the vehicles (only the official Bluelink app occasionally).

Nightly build

Not yet tested on nightly. Checked by code inspection: vehicle/bluelink/cci.go on master has no change in this area since 0.319.0 (recent Bluelink commits concern login, CCS2 status, wake-up, charge start/stop).

Version

evcc version 0.319.0

domwuk avatar Nov 14 '26 19:11 domwuk

The analysis matches the code. In vehicle/bluelink/cci.go each Identity keeps its own in-memory v.bundle, while all vehicles of the same brand and user persist to the same settingsKey(). loginCCI and refreshCCI have no lock and no re-read of the persisted bundle before refreshing. Two vehicles therefore refresh the same single-use refresh token concurrently on startup (second gets 400), and after a rotation the other vehicle keeps a stale bundle (401 on CCS exchange). This looks fixable by sharing one bundle per brand and user across Identity instances, guarded by a mutex.

Related: #34805 (earlier report of two Hyundais in one evcc, closed).

cc @andig @loocars @TMA84

🤖 Generated with Claude Code

github-actions[bot] avatar Nov 14 '26 19:11 github-actions[bot]

Agree / Same here; Ioniq 5 & 6 both plugged to two go-e Gemini. Restarting evcc shows this log (level: debug; area: main, site, hyundai):

[main ] INFO 2026/11/15 04:34:45 evcc 0.319.0
[main ] INFO 2026/11/15 04:34:45 using config file: /config/evcc.yaml
[main ] INFO 2026/11/15 04:34:45 using sqlite database: /data/evcc.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=foreign_keys(1)&_pragma=auto_vacuum(INCREMENTAL)&_pragma=cache_size(-16384)&_txlock=immediate
[main ] INFO 2026/11/15 04:34:46 OCPP local url: ws://127.0.0.1:8887/<stationId>
[main ] INFO 2026/11/15 04:34:46 UI local url: http://127.0.0.1:7070
[hyundai] DEBUG 2026/11/15 04:34:49 cci: refreshing token
[hyundai] DEBUG 2026/11/15 04:34:49 cci: refreshing token
[hyundai] WARN 2026/11/15 04:34:49 cci: refreshing persisted token failed: cci token refresh failed: unexpected status: 400 (Bad Request) POST https://cci-api-eu.hyundai.com/auth/v2/token-refresh
[hyundai] DEBUG 2026/11/15 04:34:49 cci: logging in via OneApp/CCI password login
[hyundai] DEBUG 2026/11/15 04:34:50 cci: refresh successful
[main ] WARN 2026/11/15 04:34:50 vehicle 'ev4': default charge 'mode' is deprecated, please configure via UI (more > vehicles)
[hyundai] DEBUG 2026/11/15 04:34:50 cci: login successful
[main ] WARN 2026/11/15 04:34:51 vehicle 'ev7': default charge 'mode' is deprecated, please configure via UI (more > vehicles)
[site ] INFO 2026/11/15 04:34:52 site config:
[site ] INFO 2026/11/15 04:34:52 meters: grid ✓ pv ✓ battery ✓
[site ] INFO 2026/11/15 04:34:52 grid: power ✓ energy ✓ currents ✓
[site ] INFO 2026/11/15 04:34:52 pv 1: power ✓ energy ✗ currents ✗
[site ] INFO 2026/11/15 04:34:52 battery 1: power ✓ energy ✓ currents ✗ soc ✓ capacity ✓
[site ] INFO 2026/11/15 04:34:52 vehicles:
[site ] INFO 2026/11/15 04:34:52 vehicle 1: range ✓ status ✓ climate ✓ wakeup ✓
[site ] INFO 2026/11/15 04:34:52 vehicle 2: range ✓ status ✓ climate ✓ wakeup ✓
[site ] INFO 2026/11/15 04:34:52 tariffs:
[site ] INFO 2026/11/15 04:34:52 grid: priceforecast
[site ] INFO 2026/11/15 04:34:52 feed-in: pricestatic
[site ] INFO 2026/11/15 04:34:52 co2: ✗
[site ] INFO 2026/11/15 04:34:52 solar: ✗

hstammlerj avatar Nov 15 '26 03:11 hstammlerj