Volvo Cars integration

Hi,

1)Yes error happens immediately when trying to add the integration.

  1. HA version 2024.12.1

  2. Error below:

Logger: aiohttp.server
Source: /usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py:451
First occurred: 12:48:40 (1 occurrences)
Last logged: 12:48:40

Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py”, line 480, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.13/site-packages/aiohttp/web_app.py”, line 569, in _handle
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.13/site-packages/aiohttp/web_middlewares.py”, line 117, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/security_filter.py”, line 92, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/forwarded.py”, line 83, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/request_context.py”, line 26, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 86, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 242, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/headers.py”, line 32, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/http.py”, line 73, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/decorators.py”, line 81, in with_admin
return await func(self, request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/data_validator.py”, line 74, in wrapper
return await method(view, request, data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/config/config_entries.py”, line 172, in post
return await self._post_impl(request, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/config/config_entries.py”, line 179, in _post_impl
return await super()._post_impl(request, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py”, line 84, in _post_impl
result = await self._flow_mgr.async_init(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
…<2 lines>…
)
^
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 1315, in async_init
flow, result = await self._async_init(flow_id, handler, context, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 1340, in _async_init
flow = await self.async_create_flow(handler, context=context, data=data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 1536, in async_create_flow
handler = await _async_get_flow_handler(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.hass, handler_key, self._hass_config
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 3333, in _async_get_flow_handler
await _load_integration(hass, domain, hass_config)
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 3310, in _load_integration
await async_process_deps_reqs(hass, hass_config, integration)
File “/usr/src/homeassistant/homeassistant/setup.py”, line 575, in async_process_deps_reqs
await requirements.async_get_integration_with_requirements(
hass, integration.domain
)
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 54, in async_get_integration_with_requirements
return await manager.async_get_integration_with_requirements(domain)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 170, in async_get_integration_with_requirements
await future
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 159, in async_get_integration_with_requirements
await self._async_process_integration(integration, done)
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 182, in _async_process_integration
await self.async_process_requirements(
integration.domain, integration.requirements
)
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 269, in async_process_requirements
await self._async_process_requirements(name, missing)
File “/usr/src/homeassistant/homeassistant/requirements.py”, line 307, in _async_process_requirements
raise RequirementsNotFound(name, list(failures))
homeassistant.requirements.RequirementsNotFound: Requirements for volvo_cars not found: [‘pydantic==1.10.18’].

This one is the reason. Hold on, I’ll fix it right away!

@xti9 I just released v0.2.1 which should fix the issue. Can you try it please?

You might need to explicitly check for an update in HACS. Go to the Volvo Cars repo and click “Update information” in the context menu of the three dots. After that you should see a pending update in Settings.

ok that worked.

But now i get an error - same error i was getting when using vovlo2mqtt alone - for some reaosn i cannot get access to my vehicle. Any ideas?

This error originated from a custom integration.

Logger: custom_components.volvo_cars.coordinator
Source: helpers/update_coordinator.py:318
integration: Volvo Cars (documentation, issues)
First occurred: 13:31:48 (6 occurrences)
Last logged: 13:32:37

Unexpected error fetching VolvoXC40 data
Traceback (most recent call last):
File “/config/custom_components/volvo_cars/volvo/api.py”, line 206, in _async_request
response.raise_for_status()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File “/usr/local/lib/python3.13/site-packages/aiohttp/client_reqrep.py”, line 1157, in raise_for_status
raise ClientResponseError(
…<5 lines>…
)
aiohttp.client_exceptions.ClientResponseError: 403, message=‘Forbidden’, url=‘https://api.volvocars.com/connected-vehicle/v2/vehicles/REDACTED

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py”, line 318, in __wrap_async_setup
await self._async_setup()
File “/config/custom_components/volvo_cars/coordinator.py”, line 82, in _async_setup
self.vehicle = await self.api.async_get_vehicle_details()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/volvo_cars/volvo/api.py”, line 130, in async_get_vehicle_details
data = await self._async_get_data_dict(_API_CONNECTED_ENDPOINT, “”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/volvo_cars/volvo/api.py”, line 160, in _async_get_data_dict
body = await self._async_get(endpoint, operation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/volvo_cars/volvo/api.py”, line 168, in _async_get
return await self._async_request(hdrs.METH_GET, endpoint, operation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/volvo_cars/volvo/api.py”, line 211, in _async_request
raise VolvoAuthException from ex
custom_components.volvo_cars.volvo.models.VolvoAuthException

Just a few sanity checks:

  1. Is your car connected to your Volvo account?
  2. Do you use the same account for the Developer portal?
  3. Did it work before?
  4. Is your location mentioned on https://developer.volvocars.com/terms-and-conditions/apis-supported-locations/?
  5. From what year is your Volvo?

Can you enable debug logging while adding your car or reloading the current entry? I’m interested in the log lines with Request []:, Request [] status: and Request [] body:.

Disable debug logging and send these log lines.

Works for me, thanks for the update!

1 Like

Hi.

  1. Yes car connected to volvo account (and app works well)
  2. Yes same account for developer portal. Also tried with guthub account
  3. Yes worked for a year (volvo2mqtt)
  4. Yes
  5. 2024 xc40 recharge

See log:

2024-12-09 08:43:06.849 DEBUG (MainThread) [custom_components.volvo_cars.volvo.api] Request status: 403
2024-12-09 08:43:06.849 DEBUG (MainThread) [custom_components.volvo_cars.volvo.api] Request body: {‘error’: {‘message’: ‘FORBIDDEN’, ‘description’: ‘No relationship to UUID’}}
2024-12-09 08:43:06.849 DEBUG (MainThread) [custom_components.volvo_cars.volvo.api] Request error: Forbidden
2024-12-09 08:43:06.849 ERROR (MainThread) [custom_components.volvo_cars.coordinator] Unexpected error fetching VolvoXC40 data
Traceback (most recent call last):

I receive the same error (No relationship to UUID) when I use a random VIN. Can you triple check your VIN number and make sure there is no whitespace before and after the number?

If that is OK, then the link between your car and developer account might be broken somehow. Did you change anything in your account or car around the time volvo2mqtt stopped working?

You could also try to create a new API key.

Yes somehow link is broken. I have checked VIN number and its correct. Also created new API and get same error. My only change is that a few months ago i re-configures the car to my Volvo ID. Not sure if this may have disturbed something, and the error now popped up only when the system reattempted the OTP.

Other than that i am totally lost.

You could try to completely delete your developer account and create a new one.

That could be hard because I can’t seem to be able to login to the Volvo Developer Portal for weeks…

Yeah, using email & password does not seem to work. But I can login using my GitHub account, which is using the same email address as my Volvo ID (not sure if this is required).

Thank you very much for your continued support. Have also deleted developer account and logged in via github. Exactly same response. Is there any way to see which cars are linked to an account on the developer hub?

You can go to Specification – Energy API | Volvo Cars Developer Portal and locate “try it out”. There you can choose “My Volvo ID”. Click on authorize.

When returning to that page, scroll down and try out the first API call. You’ll need to enter your VIN.

Yep failure there too. Maybe i need to contact Volvo.

{
  "status": 401,
  "operationId": "577097e2-74fb-415f-94a4-60025f28409c",
  "error": {
    "message": "Unauthorized",
    "description": "Full authentication is required to access this resource"
  }
}

Do you see the same e-mail address as your developer account on this page: https://www.volvocars.com/uk/account/?

You should also see your car and the VIN on this page: https://www.volvocars.com/uk/account/my-cars/.

(I’ve taken UK links, but you can use your own country.)

EDIT: If nothing else helps, maybe it is indeed better to contact Volvo.

OK finally got it to work! Indeed the car was not showing in the page you mentioned. So i logged out of the app, re logged in and then re paired the car to the app.

Thanks for your help. Integration is great!

1 Like

Hi @thomas_be

Thank you for this project.
I have a XC90 (regular gas - not hybrid) and I encountered an issue after configuring that in HA.

It appears that the code fails when trying to get a filed that my car does not have (batteryCapacityKWH)

Is the code for E-vehicles only?

Thank you.

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py”, line 318, in __wrap_async_setup
await self._async_setup()
File “/config/custom_components/volvo_cars/coordinator.py”, line 82, in _async_setup
self.vehicle = await self.api.async_get_vehicle_details()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/volvo_cars/volvo/api.py”, line 131, in async_get_vehicle_details
return VolvoCarsVehicle.parse_obj(data)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/usr/local/lib/python3.13/site-packages/pydantic/main.py”, line 526, in parse_obj
return cls(**obj)
File “/usr/local/lib/python3.13/site-packages/pydantic/main.py”, line 341, in init
raise validation_error
> pydantic.error_wrappers.ValidationError: 1 validation error for VolvoCarsVehicle
> batteryCapacityKWH
> field required (type=value_error.missing)

Hi! The exact same issue (for the same model :thinking:) has been created on my repo about an hour ago. I’m working on a fix and will push a release shortly!

@thiagobruch Please try v0.2.2. You’ll need to click on “update information” on the Volvo Cars entry in HACS. You can find it in the context menu of the three dots. After that, you should receive an update notification in Settings. You might need to restart HA.