home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.82k stars 28.95k forks source link

Volvo integration #61785

Open MikaelHoogen opened 2 years ago

MikaelHoogen commented 2 years ago

The problem

Hello

I'm trying to use the Volvo integration. It doesn't work for me. When i'm reading the api documentation there is a OAuth 2.0 authorization with tokens. The only thing you can use in the integration is user and password. I don't understand how that is supposed to work?

https://developer.volvocars.com/volvo-api/connected-vehicle/

What version of Home Assistant Core has the issue?

2021.12

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Volvo On Call

Link to integration documentation on our website

https://www.home-assistant.io/integrations/volvooncall/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @molobrakos, @decompil3d, mind taking a look at this issue as it has been labeled with an integration (volvooncall) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


volvooncall documentation volvooncall source (message by IssueLinks)

decompil3d commented 2 years ago

I believe that's a different API than what this integration uses. See https://github.com/molobrakos/volvooncall/issues/71 for details. The volvooncall package uses the same API that the Volvo mobile apps use. If your auth is not working you may need to add region: na to your yaml configuration if you're in North America.

MikaelHoogen commented 2 years ago

I believe that's a different API than what this integration uses. See molobrakos/volvooncall#71 for details. The volvooncall package uses the same API that the Volvo mobile apps use. If your auth is not working you may need to add region: na to your yaml configuration if you're in North America.

Interesting. As far as I know Volvo has shut down the Volvo on call app. My car is new and i wonder if you can access new cars in the old API.

decompil3d commented 2 years ago

Not sure what to tell you -- I have a 2018 XC60 and it works just fine. Try the region: na thing and see if that helps. If you have additional trouble, consider reaching out in https://github.com/molobrakos/volvooncall since that package is what handles the connection to Volvo's API. At least other users of the package might have some insight.

MikaelHoogen commented 2 years ago

Not sure what to tell you -- I have a 2018 XC60 and it works just fine. Try the region: na thing and see if that helps. If you have additional trouble, consider reaching out in https://github.com/molobrakos/volvooncall since that package is what handles the connection to Volvo's API. At least other users of the package might have some insight.

I'm in Sweden. But the thing is that the authorization works. But there is no data.

Thx for your help. I will dig a bit deeper in this.

jonare77 commented 2 years ago

Im in norway, using the user/password integration. Car is XC40, works as expected.

tanordheim commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

MikaelHoogen commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

Yeah I have C40 recharge. So that's a theory.

jonare77 commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

Yeah I have C40 recharge. So that's a theory.

Im sorry but i have to debunk it. I have the XC40 hybrid rechargable. I have never had any problems with the integration.

forzaKGB commented 2 years ago

I understand "it works for me" is not that helpful, however for me it works (V60 CC -21).

I did see this note on the Volvo API page you linked: This API is a Beta release, and as such can be tested against your own vehicle but not published for general release. This API works for all connected cars up to model year 2021, excluding the XC40 Recharge BEV.

Looks like there is a difference between BEV and PHEV.

tanordheim commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

Yeah I have C40 recharge. So that's a theory.

Im sorry but i have to debunk it. I have the XC40 hybrid rechargable. I have never had any problems with the integration.

That's super odd, I have the same here that is not available via the API. It's available in-app and on the Volvo ID webpage, just not via the API used by the volvooncall-library that HomeAssistant uses - regardless of region (which was mentioned earlier in the discussion). What year model is it?

jonare77 commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

Yeah I have C40 recharge. So that's a theory.

Im sorry but i have to debunk it. I have the XC40 hybrid rechargable. I have never had any problems with the integration.

That's super odd, I have the same here that is not available via the API. It's available in-app and on the Volvo ID webpage, just not via the API used by the volvooncall-library that HomeAssistant uses - regardless of region (which was mentioned earlier in the discussion). What year model is it?

18 months since I got the car. They may be linking newer cars up againt a new api.

MikaelHoogen commented 2 years ago

@jonare77 which version of XC40 do you have? This seems to be a problem that affects only newer versions (like the Recharge) as far as I've been able to tell.

Yeah I have C40 recharge. So that's a theory.

Im sorry but i have to debunk it. I have the XC40 hybrid rechargable. I have never had any problems with the integration.

That's super odd, I have the same here that is not available via the API. It's available in-app and on the Volvo ID webpage, just not via the API used by the volvooncall-library that HomeAssistant uses - regardless of region (which was mentioned earlier in the discussion). What year model is it?

18 months since I got the car. They may be linking newer cars up againt a new api.

Yeah I have that feeling to. I picked up my C40 Recharge 2022 this monday

JRFabbi commented 2 years ago

I was having some issues with this integration but now everything is working fine, just replaced my Volvo ID to my e-mail (was my phone number)

Mine is XC40 Recharge (PHEV) MY2022

tgambee commented 2 years ago

Mine is XC40 Recharge (PHEV) MY2022

Can you confirm it is working with the XC40 Recharge (all electric) with no issue? Did you have to tweak any settings besides your id?

rrlevy commented 2 years ago

I have a XC40 Recharge (all electric) in Brazil, I can use the Volvo Cars app and I can see the car in the EU volvo account website (https://volvoid.eu.volvocars.com/Account/landing-page)

image

However, this integration does not work for me. I get an error 500 when trying to use it on Home Assistant:

2022-01-01 02:48:10 WARNING (MainThread) [volvooncall.volvooncall] Failure when communcating with the server: 500, message='Internal Server Error', url=URL('https://vocapi.wirelesscar.net/customerapi/rest/v3.0/customeraccounts')
2022-01-01 02:48:10 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/volvooncall/__init__.py", line 172, in update
    if not await connection.update(journal=True):
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 105, in update
    user = await self.get("customeraccounts")
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 91, in get
    return await self._request(METH_GET, self._make_url(url, rel))
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 76, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://vocapi.wirelesscar.net/customerapi/rest/v3.0/customeraccounts')

Doing further investigations, when I do an HTTP GET request with my username and password to the address used by the integration (https://vocapi.wirelesscar.net/customerapi/rest/v3.0/customeraccounts), I can get my account info but no cars are shown in the response. I get an empty array on accountVehicleRelation:

{
    "username": "<<REDACTED>>",
    "firstName": "Rafael",
    "lastName": "<<REDACTED>>",
    "accountId": "<<REDACTED>>",
    "account": "https://vocapi.wirelesscar.net/customerapi/rest/v3.0/customeraccounts/<<REDACTED>>",
    "accountVehicleRelations": []
}

I'm not sure if this is related to the XC40 Recharge all electric, or if it really doesn't work in Brazil.

decompil3d commented 2 years ago

@rrlevy did you set the region config? I know for North America we have to set to na so maybe you need to set to sa or latam or something for South America?

rrlevy commented 2 years ago

@rrlevy did you set the region config? I know for North America we have to set to na so maybe you need to set to sa or latam or something for South America?

@decompil3d I don't think there is a different region for South America. I've tried multiple variations (sa, br, latam, la, etc) but they don't exist. The requests to the API work only at vocapi.wirelesscar.net and vocapi-na.wirelesscar.net, but both shows no cars in the list. However, since I use the web address volvoid.eu.volvocars.com for my authentication from the Brazilian Volvo website, I believe they should use the european API.

JRFabbi commented 2 years ago

Hello @rrlevy, I think the problem is the pure electric because I'm from Brazil and have an R-D MY2022 working using the standard region.

rrlevy commented 2 years ago

Hello @rrlevy, I think the problem is the pure electric because I'm from Brazil and have an R-D MY2022 working using the standard region.

That's sad... I believe it's because the pure electric uses Android Automotive and is therefore has a completely different OS.

I wrote to Volvo anyway to learn more about it. I noticed that the car also won't work with the new API ( https://developer.volvocars.com/volvo-api/connected-vehicle )

decompil3d commented 2 years ago

@rrlevy does your car appear on Volvo's mobile app? Perhaps that can be investigated to see if there is some new API to use.

rrlevy commented 2 years ago

@rrlevy does your car appear on Volvo's mobile app? Perhaps that can be investigated to see if there is some new API to use.

Yes, it does. It allows me to open/close the car, turn on or schedule the air conditioning, and to check charging status:

image

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Avd888 commented 2 years ago

Unfortunately the bug is still there in version 2022.3:

Logger: homeassistant
Source: components/volvooncall/__init__.py:174
First occurred: 14:42:50 (2 occurrences)
Last logged: 14:50:55

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/volvooncall/__init__.py", line 174, in update
    if not await connection.update(journal=True):
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 117, in update
    await vehicle.update(journal=journal)
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 158, in update
    await self._connection.update_vehicle(self, journal)
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 125, in update_vehicle
    self._state[url].update(await self.get("status", rel=url))
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 91, in get
    return await self._request(METH_GET, self._make_url(url, rel))
  File "/usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py", line 76, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/YV***********7/status'

&

Logger: volvooncall.volvooncall
Source: /usr/local/lib/python3.9/site-packages/volvooncall/volvooncall.py:305
First occurred: 15:52:03 (2 occurrences)
Last logged: 15:52:04

Failure to execute: 500, message='Internal Server Error', url=URL('https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/Y********************7/unlock')

Apparently the unlock endpoint in changed in the api:

https://api.volvocars.com/connected-vehicle/v1/vehicles/{vin}/commands/unlock

https://developer.volvocars.com/apis/connected-vehicle/endpoints/doors-windows-locks/#lock-doors

decompil3d commented 2 years ago

Apparently the unlock endpoint in changed in the api:

The underlying volvooncall library does not use the new API. Newer vehicles seem to have issues with the older API though. Someone who has a newer Volvo should investigate building a new base library and integrating here. I have a 2018 and am getting a new Lincoln soon, so I will not be able to continue maintaining this integration nor underlying library soon.

chinmayjade commented 2 years ago

Hello @rrlevy, I think the problem is the pure electric because I'm from Brazil and have an R-D MY2022 working using the standard region.

I have the same issue with my 19 S60. I stumbled across this integration last weekend and it works partially for me. The integration is able to pull odometer data, lock/unlock status and door closed/open status etc. However it fails with the same Failure to execute: 500, message='Internal Server Error' when I try to lock/unlock from HA.

I am in the US and using region na in the config.

Screen Shot 2022-04-08 at 10 23 21 PM
timknowlden commented 2 years ago

I have a my22 xc60 which works in the Volvo cars app. I’m from the UK and the car uses the new android automotive platform. I have set up the Volvo on call integration with username and password but nothing shows in the integrations page on home assistant and nothing in the log except that Volvooncall is taking longer than 10seconds to start.

decompil3d commented 2 years ago

The integration doesn't work with the new Android-based cars. Only Sensus ones. You're welcome to reverse-engineer the new API and contribute to the integration though.

timknowlden commented 2 years ago

The integration doesn't work with the new Android-based cars. Only Sensus ones. You're welcome to reverse-engineer the new API and contribute to the integration though.

Okay thanks for clarifying, I’d love to help if I can. But completely clueless on the matter or reverse engineering API’s.

Avd888 commented 2 years ago

The api is actually well documenten so no need for reverse engineering

https://developer.volvocars.com/volvo-api/connected-vehicle

rrlevy commented 2 years ago

The api is actually well documenten so no need for reverse engineering

https://developer.volvocars.com/volvo-api/connected-vehicle

No, this API is only for Non-Android Automotive Volvo vehicles. The new vehicles are not compatible with this API listed.

rrlevy commented 2 years ago

As confirmed now by Volvo on the API Overview page, the Connected Vehicle API will not work with newer vehicles with Android Automotive OS:

https://developer.volvocars.com/apis/connected-vehicle/overview/

image

Avd888 commented 2 years ago

Oke, my mistake, so there are appearently three api? The old one used by HA which works read for a part for sensus cars (only read information from the car, not locking and start heater). The connected api, the new api from Volvo for cars up to model year 2021 and the 'hidden' api for newer cars?

decompil3d commented 2 years ago

Oke, my mistake, so there are appearently three api? The old one used by HA which works read for a part for sensus cars (only read information from the car, not locking and start heater). The connected api, the new api from Volvo for cars up to model year 2021 and the 'hidden' api for newer cars?

The old API does read+write on older Volvos. My 2018 xc60 can be started, locked, and have heater turned on/off via the API. But it is somewhat flaky these days.

I'm waiting on a new Lincoln Aviator, so my efforts are likely going to shift to the fordpass integration soon 😉. But I'm sure someone will eventually figure out the new Volvo API and expose it in a Python module. My advice is to make a new library module and then integrate that here into HA. The existing volvooncall module is written in a relatively old way and is too intertwined with how HA works.

Avd888 commented 2 years ago

So you don't receive the error message as described in the post above: https://github.com/home-assistant/core/issues/61785#issuecomment-1090302530

Mine is MY2015 with sensus connect but it doesn't work, only read, the start / lock / heater on/off don't work, only in the volvo app.

decompil3d commented 2 years ago

So you don't receive the error message as described in the post above: https://github.com/home-assistant/core/issues/61785#issuecomment-1090302530

Mine is MY2015 with sensus connect but it doesn't work, only read, the start / lock / heater on/off don't work, only in the volvo app.

Nope, I don't see errors for that.

IceBotYT commented 2 years ago

I went ahead and contacted Volvo Support, and this is their response. What a shame. image

tj1816 commented 2 years ago

I went ahead and contacted Volvo Support, and this is their response. What a shame. image

That sucks! Hopefully that changes

youtoofan commented 1 year ago

I also drive a C40, and when i try the new volvo cars api I do get a response now:

request: https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN-NUMBER/battery-charge-level reply : { "status": 200, "operationId": "82ba6883-6241-4f03-b145-2083fa73a70a", "data": { "batteryChargeLevel": { "value": "89.0", "unit": "percentage", "timestamp": "2022-08-07T11:32:46.378Z" } } }

youtoofan commented 1 year ago

doors work too: request: https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN-NUMBER/doors

{ "status": 200, "operationId": "5432eff4-3ef4-4be1-8d56-ae64d8c503c8", "data": { "carLocked": { "value": "LOCKED", "timestamp": "2022-08-07T03:23:16.985Z" }, "frontLeft": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" }, "frontRight": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" }, "rearLeft": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" }, "rearRight": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" }, "hood": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" }, "tailGate": { "value": "CLOSED", "timestamp": "2022-08-07T03:23:16.985Z" } } }

youtoofan commented 1 year ago

But getting a list of vehicles fails: https://api.volvocars.com/connected-vehicle/v1/vehicles

{ "status": 406, "operationId": "a38b0bc8-d916-438b-89f7-486532b1a2be", "error": { "message": "NOT_ACCEPTABLE", "description": "Not Acceptable" } }

So in order for the door status and battery level calls to work, we have to include the VIN number ourselves in the api call.

IceBotYT commented 1 year ago

So in order for the door status and battery level calls to work, we have to include the VIN number ourselves in the api call.

Ahhhh!! This makes so much sense now. I remember having to manually enter the VIN number when setting up the app, so it isn't a bug in the connected vehicles list.

My proposal is to have a new option added to the YAML configuration option called 2022_plus or new_api or modern_api. When that is set to true, username and password become optional and then a new vin option becomes required, and then once that's set up we can then go from there. Sound good?

MikaelHoogen commented 1 year ago

But getting a list of vehicles fails: https://api.volvocars.com/connected-vehicle/v1/vehicles

{ "status": 406, "operationId": "a38b0bc8-d916-438b-89f7-486532b1a2be", "error": { "message": "NOT_ACCEPTABLE", "description": "Not Acceptable" } }

So in order for the door status and battery level calls to work, we have to include the VIN number ourselves in the api call.

Wow, the API works with my C40 as well. I have tried this many times in the past and then it did not work. They must have updated something :)

IceBotYT commented 1 year ago

Does climate start work?

MikaelHoogen commented 1 year ago

Does climate start work?

I can try it out. The internet connection on my C40 are kinda shaky. @youtoofan Are your internet connection stable? My connection does almost never work when the car is turned off. I must drive the car for a while before it works

IceBotYT commented 1 year ago

Does climate start work?

I can try it out. The internet connection on my C40 are kinda shaky. @youtoofan Are your internet connection stable? My connection does almost never work when the car is turned off. I must drive the car for a while before it works

My connection with the car is stable. I can try it out.

MikaelHoogen commented 1 year ago

Does climate start work?

I can try it out. The internet connection on my C40 are kinda shaky. @youtoofan Are your internet connection stable? My connection does almost never work when the car is turned off. I must drive the car for a while before it works

My connection with the car is stable. I can try it out.

No problems with connection dropping when the car is turned off?

IceBotYT commented 1 year ago

No problems with connection dropping when the car is turned off?

Yeah, it works 90% of the time :)

MikaelHoogen commented 1 year ago

No problems with connection dropping when the car is turned off?

Yeah, it works 90% of the time :)

Okey, it's been so much trouble with mine. Starting to think that my car is faulty. Feels like i'm beta testing and pay premium

IceBotYT commented 1 year ago

Okey, it's been so much trouble with mine. Starting to think that my car is faulty. Feels like i'm beta testing and pay premium

It's not just you. To be honest, I forgot that I dropped the car off at the dealer a few days ago because there were so many issues and I needed them fixed. I can't test 😅