volvo-connect: unauthorized_client
Describe the bug
Hi.. Is the (hard-coded) client suddenly become invalid?
[volvo-cc] TRACE 2024/10/18 21:28:49 POST https://volvoid.eu.volvocars.com/as/token.oauth2
[volvo-cc] TRACE 2024/10/18 21:28:49 access_token_manager_id=JWTh4Yf0b&grant_type=password&password=***&scope=openid+vehicle%3Aattributes+energy%3Arecharge_status+energy%3Abattery_charge_level+energy%3Aelectric_range+energy%3Aestimated_charging_time+energy%3Acharging_connection_status+energy%3Acharging_system_status+conve%3Afuel_status+conve%3Aodometer_status+conve%3Aenvironment&username=***
--
{"error":"unauthorized_client"}
[main ] ERROR 2024/10/18 21:28:49 creating vehicle db:1 failed: cannot create vehicle type 'template': cannot create vehicle type 'volvo-connected': unexpected status: 400 (Bad Request)
This is in the code
const (
managerId = "JWTh4Yf0b"
basicAuth = "Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc="
)
Steps to reproduce
curl -X POST https://volvoid.eu.volvocars.com/as/token.oauth2
-H "Authorization: Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc="
-H "Content-Type: application/x-www-form-urlencoded"
-d "access_token_manager_id=JWTh4Yf0b"
-d "grant_type=password"
-d "username=invalid_user_does_not_matter"
-d "password=invalid_pass_does_not_matter"
-d "scope=openid vehicle:attributes energy:recharge_status energy:battery_charge_level energy:electric_range energy:estimated_charging_time energy:charging_connection_status energy:charging_system_status conve:fuel_status conve:odometer_status conve:environment"
{"error":"unauthorized_client"}
Configuration details
Not appliccable
Log details
{"error":"unauthorized_client"}
What type of operating system are you running?
Docker container
Nightly build
- [X] I have verified that the issue is reproducible with the latest nightly build
Version
0.130.13 (not yet relevant to issue, current master version has same credentials)
Seems Volvo has made changes. Do we know which?
See https://github.com/TA2k/ioBroker.volvo/issues/37#issuecomment-2423673823
I don't know what they have changed, but I can confirm that Volvo2mqtt is working again.
https://github.com/Dielee/volvo2mqtt
They have updated to V2 API. What ever that means.
There is a volvo.py in that repository src/volvo.py
Seems this requires 2FA now which we don't support. Long time ago, we've asked Volvo to unboard us on their official APIs. This hasn't happened. We're not going to add more ugly workaround.
So back to the generic car.
But is this As of version v1.9.0, this addon uses the same OTP authentication as the Volvo app. The following steps are required for authentication in exactly this order:
Setup volvo2Mqtt, either via Docker, or via HA addon (take a look at the "Setup" section below)
Fill in your settings and start volvo2Mqtt
Your log will show the following lines
Waiting for otp code... Please check your mailbox and post your otp code to the following mqtt topic "volvoAAOS2mqtt/otp_code". Retry 0/15
Waiting for otp code... Please check your mailbox and post your otp code to the following mqtt topic "volvoAAOS2mqtt/otp_code". Retry 1/15
etc ...
Now, open your mailbox and copy your OTP Code
Open HomeAssistant and search for the entity ID text.volvo_otp
Paste your OTP into the text entity and press Enter
6a. (optional) If your OTP cannot be safed, try to paste your OTP code via MQTT to the following topic: volvoAAOS2mqtt/otp_code
OTP Post Script
If everything has worked, your addon is now authenticated. In the future, OTP authentication only needs to be done when updating, not when restarting the container.
really an ugly workaround?
I've got a bad request 400 error on my Volvo template running Evcc as an addon in HS. Does this mean that we cannot use the templates in evcc due to the 2FA on Volvo's side?
I've got a bad request 400 error on my Volvo template running Evcc as an addon in HS. Does this mean that we cannot use the templates in evcc due to the 2FA on Volvo's side?
yes, that's exactly what it means. +1 on this issue.
What is the reason behind 2FA not being supported?
I understand, that in the yaml approach it is complicated to integrate 2FA, but with the new configuration screen it should be possible to redirect to Volvo and deal with 2FA.
There is even a kind of exmaple flow.
https://github.com/volvo-cars/developer-portal-api-samples/tree/main/oauth2-code-flow-sample
That's exactly the API that Volvo has not onboarded us on... Once they do that's the way to go.
That's exactly the API that Volvo has not onboarded us on... Once they do that's the way to go.
Ah, so you didn't receive a client_id? And the app is not yet published by Volvo? Who should we have to e-mail at Volvo to ask for more information? Do you have any contacts for us?
I think you can get a client id without even having a Volvo. But somehow the evcc user needs to login with his or her client id to get connected to their cars.
@andig Where are you stuck in the process of onboarding?
https://developer.volvocars.com/apis/docs/authorisation/
But you should be able to onboard even with your github account
Idea: Creating a volvoAAOS2mqtt vehicle type? (Using: https://github.com/Dielee/volvo2mqtt)
Playing with the idea, i unfortunately see that the DemoCar VIN is not very supportive.. so some real data is needed.
app-1 | Oct 21 13:14:22 volvo2mqtt [1] - INFO: Vin: ['LPSEFAVS2NPOLDEMO'] found!
app-1 | Oct 21 13:14:22 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 403. Error: {
app-1 | "status" : 403,
app-1 | "operationId" : "ff862ec3-f787-4a09-89db-f21d6a3d1472",
app-1 | "error" : {
app-1 | "message" : "FORBIDDEN",
app-1 | "description" : "No relationship to UUID"
app-1 | }
app-1 | }
app-1 | Oct 21 13:14:22 volvo2mqtt [1] - INFO: Failed, Battery Charge Level is unfortunately not supported by your vehicle.
But a real VIN is very responsive with the following data every 300 seconds on mqtt...
volvoAAOS2mqtt/availability online
homeassistant/sensor/ANONYMIZED_VIN_battery_charge_level/state 75.0
homeassistant/sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_battery_charge_level/config {"name": "Battery Charge Level", "object_id": "volvo_ANONYMIZED_VIN_battery_charge_level", "schema": "state", "icon": "mdi:battery-70", "state_topic": "homeassistant/sensor/ANONYMIZED_VIN_battery_charge_level/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_battery_charge_level", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "battery", "unit_of_measurement": "%", "state_class": "measurement"}
homeassistant/sensor/ANONYMIZED_VIN_battery_capacity/state 66.0
homeassistant/sensor/ANONYMIZED_VIN_electric_range/state 356
homeassistant/sensor/ANONYMIZED_VIN_estimated_charging_time/state 0
homeassistant/sensor/ANONYMIZED_VIN_charging_system_status/state Done
homeassistant/sensor/ANONYMIZED_VIN_charging_connection_status/state Connected AC
homeassistant/sensor/ANONYMIZED_VIN_odometer/state 1436
homeassistant/sensor/ANONYMIZED_VIN_last_data_update/state 21.10.2024, 12:55:40
homeassistant/sensor/ANONYMIZED_VIN_active_schedules/attributes {"timers": []}
homeassistant/binary_sensor/ANONYMIZED_VIN_window_front_left/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_window_front_right/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_window_rear_left/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_window_rear_right/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_door_front_left/state OFF
homeassistant/binary_sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_door_front_left/config {"name": "Door Front Left", "object_id": "volvo_ANONYMIZED_VIN_door_front_left", "schema": "state", "icon": "mdi:car-door-lock", "state_topic": "homeassistant/binary_sensor/ANONYMIZED_VIN_door_front_left/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_door_front_left", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "door"}
homeassistant/binary_sensor/ANONYMIZED_VIN_door_front_right/state OFF
homeassistant/binary_sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_door_front_right/config {"name": "Door Front Right", "object_id": "volvo_ANONYMIZED_VIN_door_front_right", "schema": "state", "icon": "mdi:car-door-lock", "state_topic": "homeassistant/binary_sensor/ANONYMIZED_VIN_door_front_right/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_door_front_right", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "door"}
homeassistant/binary_sensor/ANONYMIZED_VIN_door_rear_left/state OFF
homeassistant/binary_sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_door_rear_left/config {"name": "Door Rear Left", "object_id": "volvo_ANONYMIZED_VIN_door_rear_left", "schema": "state", "icon": "mdi:car-door-lock", "state_topic": "homeassistant/binary_sensor/ANONYMIZED_VIN_door_rear_left/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_door_rear_left", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "door"}
homeassistant/binary_sensor/ANONYMIZED_VIN_door_rear_right/state OFF
homeassistant/binary_sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_door_rear_right/config {"name": "Door Rear Right", "object_id": "volvo_ANONYMIZED_VIN_door_rear_right", "schema": "state", "icon": "mdi:car-door-lock", "state_topic": "homeassistant/binary_sensor/ANONYMIZED_VIN_door_rear_right/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_door_rear_right", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "door"}
homeassistant/binary_sensor/ANONYMIZED_VIN_tailgate/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_engine_hood/state OFF
homeassistant/binary_sensor/ANONYMIZED_VIN_tank_lid/state ON
homeassistant/binary_sensor/ANONYMIZED_VIN_sunroof/state OFF
homeassistant/switch/ANONYMIZED_VIN_climate_status/state OFF
homeassistant/lock/ANONYMIZED_VIN_lock_status/state LOCKED
homeassistant/lock/volvoAAOS2mqtt/ANONYMIZED_VIN_lock_status/config {"name": "Lock state", "object_id": "volvo_ANONYMIZED_VIN_lock_status", "schema": "state", "icon": "mdi:lock", "state_topic": "homeassistant/lock/ANONYMIZED_VIN_lock_status/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_lock_status", "availability_topic": "volvoAAOS2mqtt/availability", "command_topic": "homeassistant/lock/ANONYMIZED_VIN_lock_status/command"}
homeassistant/device_tracker/ANONYMIZED_VIN_location/attributes {"longitude": "<REDACTED>", "latitude": "<REDACTED>", "gps_accuracy": 1}
homeassistant/sensor/ANONYMIZED_VIN_tyre_front_left/state NO_WARNING
homeassistant/sensor/ANONYMIZED_VIN_tyre_front_right/state NO_WARNING
homeassistant/sensor/ANONYMIZED_VIN_tyre_rear_left/state NO_WARNING
homeassistant/sensor/ANONYMIZED_VIN_tyre_rear_right/state NO_WARNING
homeassistant/binary_sensor/ANONYMIZED_VIN_engine_state/state OFF
homeassistant/binary_sensor/volvoAAOS2mqtt/ANONYMIZED_VIN_engine_state/config {"name": "Engine State", "object_id": "volvo_ANONYMIZED_VIN_engine_state", "schema": "state", "icon": "mdi:engine-off-outline", "state_topic": "homeassistant/binary_sensor/ANONYMIZED_VIN_engine_state/state", "device": {"identifiers": ["volvoAAOS2mqtt_ANONYMIZED_VIN"], "manufacturer": "Volvo", "model": "EX30", "name": "EX30 (2025) - ANONYMIZED_VIN"}, "unique_id": "volvoAAOS2mqtt_ANONYMIZED_VIN_engine_state", "availability_topic": "volvoAAOS2mqtt/availability", "device_class": "running"}
homeassistant/sensor/ANONYMIZED_VIN_distance_to_empty_battery/state 356
homeassistant/sensor/ANONYMIZED_VIN_km_to_service/state 28564
homeassistant/sensor/ANONYMIZED_VIN_time_to_service/state 19 months
homeassistant/sensor/ANONYMIZED_VIN_service_warning_status/state NO_WARNING
homeassistant/sensor/ANONYMIZED_VIN_washer_fluid_warning/state NO_WARNING
homeassistant/sensor/ANONYMIZED_VIN_api_backend_status/state NO_WARNING
homeassistant/number/ANONYMIZED_VIN_update_interval/state 300
So this requires only to have a volvo2mqtt-app (https://github.com/Dielee/volvo2mqtt) installed, and a volvo-mqtt vehicle type to be created.
I would rather have a nice and clean programmed evcc go implementation of the volvo API in place of course.
But in the meantime, while we wait for volvo, it doesn't feel too kludgy for me to:
- Create a mqtt vehicle type (Could be re-used for future mqtt vehicles ...)
- Pull in a well supported homeassistant vehicle data via MQTT: volvoAAOS2mqtt
Any ideas/thoughts for the volvoAAOS2mqtt vehicle type support?
We have the same for Mazda, happy tonsuppoert a PR.
evcc yaml:
vehicles:
- name: myCar
title: Volvo XC60 Recharge
type: custom
icon: car
capacity: 19
phases: 2
onIdentify:
mode: pv # enable PV-charging when vehicle is identified (minpv|now|off|pv)
soc: # battery soc (%)
source: http
uri: http://xxx.xxx.xxx.xxx:8123/api/states/sensor.volvo_
battery_charge_level method: GET # default HTTP method headers: - authorization: Bearer - content-type: application/json jq: .state | tonumber # parse response json range: # optional electric range (km) source: http uri: http://xxx.xxx.xxx.xxx:8123/api/states/sensor.volvo electric_range method: GET # default HTTP method headers: - authorization: Bearer - content-type: application/json jq: .state | tonumber # parse response json odometer: source: http uri: http://xxx.xxx.xxx.xxx:8123/api/states/sensor.volvo _odometer method: GET # default HTTP method headers: - authorization: Bearer - content-type: application/json jq: .state | tonumber # parse response json status: source: http uri: http://xxx.xxx.xxx.xxx:8123/api/states/sensor.xc60_charging_status_a_f method: GET # default HTTP method headers: - authorization: Bearer - content-type: application/json jq: .state # parse response json
helper sensor (sensor.xc60_charging_status_a_f):
{% if is_state("sensor.volvo_
{%- else -%}
F
{%- endif %}