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
71.02k stars 29.66k 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

andynash commented 1 year ago

A longish post, but I thought it would be useful to clear up some of the confusion about what is needed - plus, I've also made a little progress, both on the API, and getting them to provide oAuth2 credentials so that we can actually use the API 🤞🥳

First, the API...

I've successfully got all of the 'modern' APIs (Connected/Extended/Energy, i.e. the ones that work with Android/AAOS Volvos) working using Postman, however that is as far as I can get without Volvo approving my request to publish a developer application via their developer portal.

This is because the APIs require an access token which is only valid for 60 minutes. Without a published Volvo developer app (providing oAuth credentials in the form of a key/secret), the only way to obtain a token is via the Volvo developer portal (using Volvo's own credentials), manually, every 60 minutes.

You can try the APIs for yourself on Postman here.

I have a MY23 XC90 Recharge, and the Energy API worked as expected, so hopefully this will be available for all AAOS Recharge cars. It is not documented well what data is available for which cars, but almost everything else also works for me (some that didn't might work while the car is being driven).

For example: Oil Level works, but Oil Pressure doesn't - I get the error "resource not available for VIN or accessing party" which suggests my car doesn't report that.

Some changes have been made since I first set most of these up a few months ago:

Overall (with the exception of location which strangely isn't available through any of these APIs) you can broadly match the functionality of the older VOC API currently used by this integration. Since I did this, location has become available in the Volvo app so maybe this will become available in one of the APIs at some point - it is a weird omission. I wonder if a different approach is being used by the official app, perhaps using Google's location services and APIs.

Charge scheduling was briefly made available in the app a month or two ago, then removed. That isn't available in the API either.

Both Charge Scheduling and Pre-Cleaning are in the manual for the MY22 XC90 (Sensus, not AAOS), but not the MY23, so possibly these features can be software-enabled at some point. I wonder if there are others?

Second, obtaining oAuth credentials...

I applied to publish my Volvo developer app months ago, with no response, but more recently I chased and have made contact (the email on the developer site now goes to a ticketing system, and they ended up asking me to resubmit the application to publish). The latest I heard was an ambiguous reply which suggests they have approved my request to publish my developer app, and I should expect a key/secret around the 14th (but it may just be some sort of rejection around that date) 🤞

So, it now appears as if an application to publish your Volvo developer app will now at least be looked at, which is progress (for those not familiar 'application' in this context does not mean integration, just an ID through which to query their API).

If anyone can get their oAuth credentials (by getting their developer app published), it should be possible to authenticate and GET/POST the APIs through REST, and work on developing an HA integration, or adding support for the new APIs to this one.

However, unless someone develops e.g. a SaaS app to act as an intermediary (unlikely), any Home Assistant integration working with the new APIs would need to be provided with oAuth credentials for each car owner/HA user. Hard-coding the integration owner's credentials into the integration could work I guess, but doesn't seem sensible.

That's fine (similar to Withings/Home Connect/Google Calendar), but only if Volvo are willing/set up to provide oAuth key/secrets in volume (not the case right now). My guess is they don't currently envision the HA use case, and just expect developers to build e.g. mobile apps (small numbers of Volvo developer apps, each servicing thousands of car owners [1:many], versus thousands of car owners using HA with thousands of Volvo developer apps[1:1]).

Taking Withings as an example, you can create oAuth credentials online, instantly, Currently Volvo require an application to be submitted (requesting info that is not relevant to our use case like T&Cs). This is likely to take weeks to be reviewed - and it remains to be seen whether they will even approve requests.

Hopefully their current approach will change (either because other manufacturers will do this the way we need so they will see a competitive justification, or because they get their heads around the use case and decide to be helpful).

I'll update if/when I get the oAuth credentials. If anyone else manages it, please do the same 👍 We could also really do with an HA user on the inside, ie working at Volvo, with the ability to get this in front of the right people...

distantcompany commented 1 year ago

I've never been able to get any data back on my 2022.5 XC60 Recharge with these APIs, and I always assumed my model just wasn't available yet and/or I was missing something in my Postman setup. But thanks to @andynash 's work above (awesome job, btw), I feel confident that my requests are fine. But even tho I'm logged into the developer site with the same email I use in the Volvo app, and I have no problem generating keys, when I send get-vehicles to the Extended endpoint I get an empty array:

{
    "vehicles": []
}

If I instead send to the Connected endpoint I get:

{
    "status": 200,
    "operationId": "00a026fc-a757-4b02-b395-ea3d4b34f535",
    "data": [],
    "pagination": {
        "limit": 0,
        "total": 0
    }
}

These responses seem to maybe at least confirm that my account should be using the Extended, rather than Connected API...which makes sense if I have a Recharge, correct?

But if I send to an Energy endpoint with my specific VIN, I get:

{
    "exveErrorId": "403",
    "exveErrorMsg": "vin v.s. account mismatch"
}

It's that last response that seems to prove there must be some disconnect here. How would it be possible for me to manage my XC60 through the app at all if it weren't even associated with my account?

Any ideas? Cheers.

eddyvanroy commented 1 year ago

I applied to publish my Volvo developer app months ago, with no response, but more recently I chased and have made contact (the email on the developer site now goes to a ticketing system, and they ended up asking me to resubmit the application to publish). The latest I heard was an ambiguous reply which suggests they have approved my request to publish my developer app, and I should expect a key/secret around the 14th (but it may just be some sort of rejection around that date) 🤞

In the past I had a reaction from Volvo when submitting my NodeRed application. For the extra info in the volvo application publishing form, I used a localhost redirect URI + localhost published webpage with some terms and conditions. >> Reaction from Volvo: they wanted to have a public available page & redirect URI.

@andynash Could you also share the info you used for the redirect URI + Terms and condition info ?

andynash commented 1 year ago

@rschend

These responses seem to maybe at least confirm that my account should be using the Extended, rather than Connected API...which makes sense if I have a Recharge, correct?

I don't think Extended vs Connected has anything to do with Recharge/non-Recharge - I can access both with an XC90 Recharge. Energy is of course Recharge-only (hybrid or pure).

I think I read somewhere the Connected Vehicle API is for consumers like ourselves, and Extended is aimed at fleet managers for companies and car rental firms - but I've no idea if that is so!

I've not seen any of the responses you posted above for any of the 3 APIs, so my guess (especially based on the last one for Energy) is that something is not quite right with your VCC App Key or the Access Tokens.

Re the former, double-check it, and re the tokens, make sure you are using a different (and correct, unexpired) token for each API (they all look the same as the start of the token is identical and never changes.

You mention sending "get-vehicles" to the Extended API - the correct endpoint is just "vehicles" , i.e. https://api.volvocars.com/extended-vehicle/v1/vehicles.

I'm also not sure whether you are using what I set up in Postman or your own? If you're not using mine, maybe try it as we know it works to narrow things down?

Let me know how you get on - there is a remote chance I may be able to test against a 2022/2022.5 XC60 (non-Recharge) when someone visits at the weekend.

Edit: regarding the last error, try using the access tokens from the developer site for the demo car, rather than your own, and see if that works. If it does, and yours still doesn't, there may perhaps be an issue with your account, and how the VIN for your car is registered to it?

andynash commented 1 year ago

@andynash Could you also share the info you used for the redirect URI + Terms and condition info ?

I subscribe to Nabu Casa to provide an external URL, so I was able to supply the standard external redirect URL: https://my.home-assistant.io/redirect/oauth.

This is the oAuth redirect URL used by the Withings, Google Calendar etc and would therefore be used for any future Volvo integration too.

For terms I think I used the standard Home Assistant privacy policy 😁

I mean, it is kind of silly, given the terms they are looking for are terms I will agree to (with myself as the counter-party) for the safeguarding of my own personal data by myself 😂 Another example of Volvo devs not being ware this use case exists!

distantcompany commented 1 year ago

@andynash

I don't think Extended vs Connected has anything to do with Recharge/non-Recharge - I can access both with an XC90 Recharge. Energy is of course Recharge-only (hybrid or pure).

Yeah, I misspoke there. I meant to say, "Extended is for AAOS, while Connected is for Sensus...". But that might also be incorrect. I swore someone said that a long time ago. Your distinction sounds more likely.

I've not seen any of the responses you posted above for any of the 3 APIs, so my guess (especially based on the last one for Energy) is that something is not quite right with your VCC App Key or the Access Tokens. Re the former, double-check it, and re the tokens, make sure you are using a different (and correct, unexpired) token for each API (they all look the same as the start of the token is identical and never changes.

Yep, I've re-gen'd the tokens over and over again and used them immediately. Every time I generate a new one, it prompts me for my Volvo creds, accepts them, and boom...fresh token. So that all works as expected. I just never get any data back. Notice how I get a 200 response on that one call, it just doesn't give me anything.

You mention sending "get-vehicles" to the Extended API - the correct endpoint is just "vehicles" , i.e.

Sorry, I was shorthanding there... I meant, the GET call for vehicles. I was indeed using your collection, so I wasn't futzing with the endpoints at all.

regarding the last error, try using the access tokens from the developer site for the demo car, rather than your own, and see if that works. If it does, and yours still doesn't, there may perhaps be an issue with your account, and how the VIN for your car is registered to it?

Welp...you might be on something. I'm almost certain I was able to get data back from the Demo car several months back, but now I'm getting:

{
    "status": 403,
    "operationId": "8c98c044-41d3-4ba5-b4a9-10b2ab5f1c95",
    "error": {
        "message": "FORBIDDEN",
        "description": "Access is denied"
    }
}

I don't understand why. I'm creating a fresh app, grabbing the VCC API Key and a fresh Demo token, bringing those into my Postman environment and the variables are resolving correctly in the calls. So I'm pretty confident my requests are legit. I'm not a trained developer, But I use Postman in my work every day and I'm very comfortable with it.

Strange that the demo car gives me 403 - forbidden, but if I swap out the Demo token for my personal Connected token, without touching the VCC, I get a 200, but no data. Switch it back to demo token...403. Switch it to my personal Extended token...200 again, but empty array. Back to Demo...403.

BTW, should I be seeing any references to my car anywhere in my developer account while logged in? Because I don't. Is that maybe a clue that something isn't right?

Thanks again for the help.

nikagersonlohman commented 1 year ago

Thanks for the collection @andynash . Note that your VIN is inside it; might be better to replace it in each URL with a (global) environment variable. Also note that it's possible to already add the empty VCC API Key, Energy Access Token, Connected Vehicle Access Token and Extended Vehicle Access Token variables to the main Variables of the collection (they were not there in my case)

nikagersonlohman commented 1 year ago

Volvo Cars APIs.postman_collection_edited.zip

nikagersonlohman commented 1 year ago

I have tested the Connected and Extended Vehicle APIs on an XC40 P8 (Electric) and many of the commands finally work. The big question would be how to get the 1 hour limited token for each API. Note that it might be possible to use Selenium to generate them when you need them by virtually clicking on the correct elements of Volvo's webpage...

andynash commented 1 year ago

Strange that the demo car gives me 403 - forbidden, but if I swap out the Demo token for my personal Connected token, without touching the VCC, I get a 200, but no data. Switch it back to demo token...403. Switch it to my personal Extended token...200 again, but empty array. Back to Demo...403.

I've just tried with the demo access tokens, and for Connected Vehicle I also see 403s - I think the demo may be broken for that API.

However, using List Vehicle from the Extended Vehicle API, I do get a VIN back: YV4952NA4F120DEMO

If I use that in the Collection variables (I've now added a VIN variable), the Energy and Extended APIs work, but not Connected 🤷‍♂️

BTW, should I be seeing any references to my car anywhere in my developer account while logged in? Because I don't. Is that maybe a clue that something isn't right?

Thanks again for the help.

I don't see my car referenced, so I don't think so.

You could also try the "Try it out" demo under each API, Specification on the developer site?

I seem to remember dealers have/had some ability to associate a VIN to a Volvo ID (so you could try asking one to check all looks ok with your account), however I think now it is just a case of connecting the app to the car using Bluetooth as you will have done when you first got the car. Otherwise I suggest emailing the developer people via the Contact link in the footer of the website...

andynash commented 1 year ago

Thanks for the collection @andynash . Note that your VIN is inside it

No problem, and thanks for catching that 🙏, I meant to add that as a variable before making public! I've done so now and updated all the endpoints...

Also note that it's possible to already add the empty VCC API Key, Energy Access Token, Connected Vehicle Access Token and > Extended Vehicle Access Token variables to the main Variables of the collection (they were not there in my case)

You're right, I think the Collection variables didn't carry across when I copied the collection to a public Workspace - I've added them now, so hopefully it is easier to get started now!

andynash commented 1 year ago

I have tested the Connected and Extended Vehicle APIs on an XC40 P8 (Electric) and many of the commands finally work. The big question would be how to get the 1 hour limited token for each API. Note that it might be possible to use Selenium to generate them when you need them by virtually clicking on the correct elements of Volvo's webpage...

Great! It is strange that the Energy API doesn't work for the P8, hopefully it will do in due course.

Selenium is a really good idea - I've not used it before, o I'll wait to see if Volvo come through with publishing the app before I try that. It's all so tantalisingly close to working!

nikagersonlohman commented 1 year ago

Wel... I have published a quick-and-dirty release of getting the authorization with Selenium... Be aware, this will still have many bugs...

https://github.com/nikagl/volvo

nikagersonlohman commented 1 year ago

image

IceBotYT commented 1 year ago

This selenium use may not be allowed for use inside Home Assistant, as integrations that use web scraping have been removed before.

atxbyea commented 1 year ago

I couldn't see anyone else in this thread mentioning my specific issue, so I'll chime in.

My 2018 XC90 T8 won't let me control the heater anymore, nor does it actually read the heater value it seems. Everything else polls just fine (electric charge, charging, fuel level, gps, etc).

monsivar commented 1 year ago

Tibber.com has a working integration to Volvo (only getting the battery %) and I only loget on one time using username and password (not win)and the app is getting battery status every time I use the app. So there must be a way to stay connected

TA2k commented 1 year ago

Nice ideas here but Volvo will never approve a public app. Why not copy my simple approach?

andynash commented 1 year ago

Nice ideas here but Volvo will never approve a public app. Why not copy my simple approach?

I'm certainly interested, but as I already posted here (effectively your simple is my complicated 😁), afaict this requires getting to know an entirely new piece of software (iobroker). then adding your component, then linking to Home Assistant using MQTT (again something I don't currently use, so more time/learning)? At time of writing I don't understand this potential solution well enough to risk investing time into it (example: as previously asked, how does it work where other solutions do not?). Maybe it will work for me, maybe it will end up being a rabbit hole 🤷‍♂️

Not sure what you mean by a public app, personally I am looking for Volvo to approve individual oAuth applications for each Volvo owner (as owners of other APIs do), so that we can obtain a key/secret and provide this to a Volvo integration for Home Assistant (or use in our own REST sensor config).

If Volvo will provide that (and I have been informed that in my case at least they plan to, though this is outstanding for now), there's no reason this shouldn't provide a simple way of using one integration (or just REST) in Home Assistant to access data from the Volvo API directly.

That's currently still my preferred route, unless/until I discover Volvo will never play ball, or I can better understand the iobroker (or any other alternative) approach. Even then there's a bunch of points of failure I'll have to deal with?

I believe also the iobroker approach also doesn't currently support commands such as lock/unlock, start climate etc, which is one of the key things I am looking to be able to do?

The commands are send succeful to the API and are accepted but it looks like the API is not complete to control the car.

API commands do work for me via Postman, so I know that if I get access from Volvo, I will be able to control the car.

andynash commented 1 year ago

Tibber.com has a working integration to Volvo (only getting the battery %) and I only loget on one time using username and password (not win)and the app is getting battery status every time I use the app. So there must be a way to stay connected

Do you mean log on one time with your Volvo ID to authorise the Tibber app to connect to the Volvo API? I guess they have had an oAuth application approved by Volvo, seems likely as they operate in Volvo's home market. Sadly they don't operate in the UK yet, looks interesting 😢

andynash commented 1 year ago

This selenium use may not be allowed for use inside Home Assistant, as integrations that use web scraping have been removed before.

Yes, though it should still be possible for individuals to use an evolution of @nikagersonlohman's code locally. I need to check it out, but if it can list vehicles, then I guess it can obtain access token(s), which is the only obstacle I face right now - so very promising! All I'd need to do is pass those tokens (one per API) to Home Assistant, then use REST to get whatever data I am interested in.

TA2k commented 1 year ago

There is no need to install iobroker or mqtt. You only have to read 10 line JS code. The structure much simpler than HASS/python https://github.com/TA2k/ioBroker.volvo/blob/5b181b1eb8824a6849117373207b1fce54e17f9e/main.js#L137

shillbom commented 1 year ago

There is no need to install iobroker or mqtt. You only have to read 10 line JS code.

The structure much simpler than HASS/python

https://github.com/TA2k/ioBroker.volvo/blob/5b181b1eb8824a6849117373207b1fce54e17f9e/main.js#L137

This seems quite simple indeed. I will have to try it out. Would there be an easy way to call these functions from home assistant? Local node server on the HA instance or something like that?

TA2k commented 1 year ago

No please not. Implement this as normal http request in python in the Volvo component.

nikagersonlohman commented 1 year ago

@andynash it's best to convert the js mentioned by @TA2k to python (use "requests" to run the post call). It works fine when you use the mentioned oauth2 URL with the basic authorization and access_token_manager_id. Much better than doing it with scrapers like selenium as those might break the agreement (I haven't investigated whether this is mentioned anywhere). I just hope the basic auth and access_token_manager_id will not change. Not sure where they came from, probably someone reverse engineered the app (ssl proxy?), but I do see them appear in other code as well when you search github...

nikagersonlohman commented 1 year ago

Here, this works from python:

import requests
import json

print ("Connecting...")

username = 'VOLVO ID Username'
password = 'VOLVO ID Password'
vccapikey = 'DEVELOPER VCC API KEY'

try:
    response = requests.post(
        "https://volvoid.eu.volvocars.com/as/token.oauth2",
        headers = {
            'authorization': 'Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=',
            'content-type': 'application/x-www-form-urlencoded',
            'user-agent': 'okhttp/4.10.0'
        },
        data = {  
            'username': username,
            'password': password,
            'access_token_manager_id': 'JWTh4Yf0b',
            'grant_type': 'password',
            'scope': 'openid email profile care_by_volvo:financial_information:invoice:read care_by_volvo:financial_information:payment_method care_by_volvo:subscription:read customer:attributes customer:attributes:write order:attributes vehicle:attributes tsp_customer_api:all conve:brake_status conve:climatization_start_stop conve:command_accessibility conve:commands conve:diagnostics_engine_status conve:diagnostics_workshop conve:doors_status conve:engine_status conve:environment conve:fuel_status conve:honk_flash conve:lock conve:lock_status conve:navigation conve:odometer_status conve:trip_statistics conve:tyre_status conve:unlock conve:vehicle_relation conve:warnings conve:windows_status energy:battery_charge_level energy:charging_connection_status energy:charging_system_status energy:electric_range energy:estimated_charging_time energy:recharge_status vehicle:attributes'
        }
    )
    # print(json.dumps(response.json(), indent=4))
    print("Login successful!")
except requests.exceptions.RequestException as error:
    print("Login failed:")
    print(error)

access_token = response.json()['access_token']
# print(access_token)

try:
    vehicles = requests.get(
        "https://api.volvocars.com/extended-vehicle/v1/vehicles",
        headers= {
            "accept": "application/json",
            "vcc-api-key": vccapikey,
            "Authorization": "Bearer " + access_token
        }
    )
    print("\nResult:")
    print(vehicles)

    vehiclesjson = json.dumps(vehicles.json(), indent=4)
    print("\nResult JSON:")
    print(vehiclesjson)

except requests.exceptions.RequestException as error:
    print("Get vehicles failed:")
    print(error)
Ghawken commented 1 year ago

I've never been able to get any data back on my 2022.5 XC60 Recharge with these APIs, and I always assumed my model just wasn't available yet and/or I was missing something in my Postman setup. But thanks to @andynash 's work above (awesome job, btw), I feel confident that my requests are fine. But even tho I'm logged into the developer site with the same email I use in the Volvo app, and I have no problem generating keys, when I send get-vehicles to the Extended endpoint I get an empty array:

{
    "vehicles": []
}

If I instead send to the Connected endpoint I get:

{
    "status": 200,
    "operationId": "00a026fc-a757-4b02-b395-ea3d4b34f535",
    "data": [],
    "pagination": {
        "limit": 0,
        "total": 0
    }
}

These responses seem to maybe at least confirm that my account should be using the Extended, rather than Connected API...which makes sense if I have a Recharge, correct?

But if I send to an Energy endpoint with my specific VIN, I get:

{
    "exveErrorId": "403",
    "exveErrorMsg": "vin v.s. account mismatch"
}

It's that last response that seems to prove there must be some disconnect here. How would it be possible for me to manage my XC60 through the app at all if it weren't even associated with my account?

Any ideas? Cheers.

I'm seeing the exactly same as @distantcompany -- did you ever resolve??? Connects, get Access_token 200 for /vehicles (both connected and extended) But no Data. Well empty List

wisdom_of_the_ancients

Wonder whether this is relevant... https://developer.volvocars.com/terms-and-conditions/apis-supported-locations/

Locations The API can be used with test credentials around the world. However, when published, only cars in the Europe / Middle East / Africa regions are available. We are working to bring other regions online.

I'm outside those regions....

andynash commented 1 year ago

I can't comment on the reason for empty responses etc (though the region idea sounds likely), but should mention that I almost have the API working in Home Assistant. Just need to find the time to get the timing of requests sorted out then I will share the yaml.

Weeks rather than days or months would be my estimate 🤞

Turns out there is a quota for requests but I don't know what that number is, and I have some more to do on error handling (these are linked, I need to find a way to stop polling once certain errors are encountered, and maybe extract and present the time provided for when the quota is reset).

Commands are not yet working but I think/hope that is just because I've not finished setting them up properly. No reason why they shouldn't work as they work in Postman.

The Extended API also isn't working for me yet, but that only adds a couple of things like sunroof and fuel tank cover open/closed iirc. The rest duplicates Connected Vehicle.

Unfortunately I don't have the Python skills to create a new integration or modify this one, so I am using just yaml and the UI to create a combination of rest sensors, rest commands, and an automation to manage authentication/ token refresh etc.

Maybe someone will be able to take things from there and get it properly integrated, using this or a separate integration 🤞

Ghawken commented 1 year ago

I think the region will be the case unfortunately - which does limit it usefulness really as more than 1/2 world excluded. And not the greatest for a solution for something as widespread as HA or other Home automation systems (which is my target) which have pretty broad audiences.

The calling limits are in the Developer App section - shows numbers called, and currently is limited to 10,000 /day per app.

distantcompany commented 1 year ago

Locations The API can be used with test credentials around the world. However, when published, only cars in the Europe / Middle East / Africa regions are available. We are working to bring other regions online.

I'm outside those regions....

@Ghawken I'm also outside those regions, but unless I'm missing something, the calls I'm attempting aren't "published". They're just test calls, albeit with (my) real cars. Publishing would be required in order to develop an evergreen app for 3rd party use, no?

Ghawken commented 1 year ago

@distantcompany

Hi - I'm afraid does seem to come down to supported regions, with cars outside being unavailable. The only location is with the VolvoID Car account - and this is what we use to generated the Token.

With a outside supported region I can generate token, which then used in

URL: https://api.volvocars.com/connected-vehicle/v1/vehicles

Result:
<Response [200]>

Result JSON:
{
    "status": 200,
    "operationId": "b6257daa-9573-444b-9a24-48d6903724c8",
    "data": [],
    "pagination": {
        "limit": 0,
        "total": 0
    }
}

Returns as above - successful, but no cars.

But if use Volvo Demo Car Token - and put in straight in above: I get :

URL: https://api.volvocars.com/connected-vehicle/v1/vehicles

Result:
<Response [200]>

Result JSON:
{
    "status": 200,
    "operationId": "b5f18ef0-ef68-44ed-a0d9-5e54dcd679d8",
    "data": [
        {
            "vin": "YV4952NA4F120DEMO"
        }
    ],
    "pagination": {
        "limit": 1,
        "total": 1
    }
}

Finally a car.

Would guess that no access to cars in those unsupported regions. Don't believe publishing or otherwise makes any difference because - others are not seeing it, and just changes how to get token. Although the iOS Volvo app still shows details and allows control here (outside supported region) so must be using a different API target...

distantcompany commented 1 year ago

@Ghawken yeah I think you're ultimately correct. And if that's the case, then Volvo's own language is inaccurate. It also says this when you go to publish an app:

image

But it doesn't say anything anywhere about test calls not working globally. I still contend that this language:

The API can be used with test credentials around the world.

...should mean that test calls made against any car for the purposes of testing a yet-to-be-published app will work fine. It's just that they don't have the ability to review and approve US and APAC apps yet, for whatever reason.

Probably an oversight when writing this content. Bummer.

nikagersonlohman commented 1 year ago

I am pretty sure there are quite some bugs with the API still... My recharge API doesn't work with my car, where it does for others. I have two cars in my Volvo app, will try to create a new voc account soon to see whether that fixed it. Or reset the car. Probably it's one or the other...

jelmerkk commented 1 year ago

It looks like the guys at Domoticz figured it out, could we take inspiration from them? https://github.com/akamming/Domoticz_VolvoRecharge_Plugin

nikagersonlohman commented 1 year ago

That plugin was built based on the code I provided in this thread. His recharge API works, but won't for you (I tried his code and it doesn't work for me either)

jelmerkk commented 1 year ago

I just installed Domoticz in a docker with this plugin, and it works for me... image

nikagersonlohman commented 1 year ago

Yes, what I mean to say is "for some the Recharge API works, and for some it won't". So for some people the electricRange, fullRange and estimatedChargingTime will work fine, for others it will remain empty. Not sure whether he takes the batteryChargeLevel from the Connected API or the Recharge API, but if he takes it from the Recharge API it won't work for some. So far the batteryChargeLevel in the Connected API seems to work for everyone that tested it (as long as their VINs are listed in the vehicles list).

Ghawken commented 1 year ago

Yep ditto this is based on @nikagersonlohman very helpful code.

Issue is US and APAC regions excluded. (as above)

& certain Cars excluded.. (Hardly a great solution as yet unfortunately Volvo...)

Connected:

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.

Energy:

This API is available for:
The car model XC40 fully electric between model year 2015 and 2021.
The car models XC60, S90, V90, V90CC, XC40, and C40 fully electric (all of model year 2022).

& Extended Vehicle

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.
SinBam commented 1 year ago

Hi, I tried to use the Integration, but unfortunately there are no entities. The Integration just asked me to fill in my user and my password and said successful installed. Now I read the thread and you are dealing with api and so on... Did I something wrong? Do I have to create a developer account on Volvo? Thx for an advice! (I do have a my23 XC90 Europe)

IceBotYT commented 1 year ago

Hi, I tried to use the Integration, but unfortunately there are no entities. The Integration just asked me to fill in my user and my password and said successful installed.

Now I read the thread and you are dealing with api and so on...

Did I something wrong? Do I have to create a developer account on Volvo?

Thx for an advice!

(I do have a my23 XC90 Europe)

You have done nothing wrong. The integration is broken for your car I believe

andynash commented 1 year ago

Yep ditto this is based on @nikagersonlohman very helpful code.

Issue is US and APAC regions excluded. (as above)

& certain Cars excluded.. (Hardly a great solution as yet unfortunately Volvo...)

Connected:

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.

Energy:

This API is available for:
The car model XC40 fully electric between model year 2015 and 2021.
The car models XC60, S90, V90, V90CC, XC40, and C40 fully electric (all of model year 2022).

& Extended Vehicle

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.

This info is definitely out of date. It is almost as if no one has worked on the APIs or the developer website in the last year or two (except perhaps in an internal capacity, with regard to Volvos own apps).

I have a MY23 XC90 - according to that text I should get nothing - in reality I do get Connected Vehicle and Extended Vehicle information, and with the Volvo APIs in Postman with test credentials I get Extended too.

With the alternative credentials suggested by @IceBotYT I just get Connected and Extended - it is as though those credentials are restricted in terms of Scope, rather than any problem with the API, my account etc. However, even when including the correct Scope values for Extended I get no data.

My assumption is that if they actually allowed us to publish an app using standard credentials as per the developer website, that app would be able to retrieve Extended too (for my car at least - clearly there are other more specific issues with some cars/accounts, as well as the region restrictions).

andynash commented 1 year ago

Yep ditto this is based on @nikagersonlohman very helpful code.

Issue is US and APAC regions excluded. (as above)

& certain Cars excluded.. (Hardly a great solution as yet unfortunately Volvo...)

Connected:

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.

Energy:

This API is available for:
The car model XC40 fully electric between model year 2015 and 2021.
The car models XC60, S90, V90, V90CC, XC40, and C40 fully electric (all of model year 2022).

& Extended Vehicle

This API is available for:
All car models between model year 2015 and 2021, except for model XC40 fully electric.
All car models with model year 2022, except for XC60, S90, V90, V90CC, XC40, and C40 fully electric.

This info is definitely out of date. It is almost as if no one has worked on the APIs or the developer website in the last year or two (except perhaps in an internal capacity, with regard to Volvos own apps).

I have a MY23 XC90 - according to that text I should get nothing - in reality I do get Connected Vehicle and Extended Vehicle information, and with the Volvo APIs in Postman with test credentials I get Extended too.

With the alternative credentials suggested by @IceBotYT I just get Connected and Energy - it is as though those credentials are restricted in terms of Scope, rather than any problem with the API, my account etc. However, even when including the correct Scope values for Extended I get no data.

My assumption is that if they actually allowed us to publish an app, that app would be able to retrieve Extended too, for my car at least.

raftheunis87 commented 1 year ago

Hey all, is anyone still looking into this? Cause on my side it is not working at all :-(

HWiese1980 commented 1 year ago

I've got my XC40 Recharge (MY23) yesterday, and I'm a bit surprised of how much of a hassle it seems to be to integrate it into Home Assistant. Raises quite some of my multiple eyebrows, to be honest.

I really do not understand why I seem to have to publish (i.e. make available to everyone) an app when all I want is to access my vehicle's data and send commands. I do not need to allow everyone to use my app, let alone be redirected to some ominous redirect URL and especially agree to my terms and services for a service that I do not even offer. That's a bit over the top, if you ask me. All I want is read my Volvo's data and send lock/unlock, hvac on/off, start/stop commands, nothing less and certainly nothing more.

It's overly complicated as it seems, and I start missing my Mazda MX-30 already, where it was a lot easier to access the data and send commands.

nikagersonlohman commented 1 year ago

Because... Volvo... :( They do publish an API but it's not accessible by the "common" people...

HWiese1980 commented 1 year ago

"Common" people like their customers... I wish I could kick the deciders in their lazy butts... But no, they seem to have lost all touch with their customers. My car dealer yesterday told me the company demands from him that he invites his customers for a, wait for it, wait for it, a video event to present the new EX30. A video event! He invites people who pay tens and hundreds of thousands of Euros for cars to watch a fucking video in his halls. If I'm invited to a presentation of a new car I expect to see the car, not a fucking marketing video. But if he does not do the event, which he knows his customers will be really pissed about, he's not going to get 5 demo cars for his customers once it is out, but only 1. They literally blackmail into shitting his customers. He's not going to play along. His feedback to the company was, yeah, well, screw it, then it's just going to be 1 demo car. I'm not going to do this bullshit to my customers!

Volvo... I love the cars, I love my dealer, but I hate those office sitters who never even owned a car themselves who make decisions like this.

nikagl commented 1 year ago

Yes...I'm afraid you'll have to buy another car if you dislike this as i've seen exactly this behavior over the past 12 years I've been driving a Volvo. For example, my app was having troubles in my previous car, they couldn't solve it. By scanning the traffic to and from the car i noticed they simply have a corrupted (future) date in their database. They still couldn't solve it (deleting the corrupted record would have solved it)...6 months later, the corrupted date passed and the problem was solved. Both the dealer in Holland and people in Sweden were involved.

We've been complaining about the lack of API accessibility mostly because the Volvo app they provide doesn't (or didn't the first year I've had the XC40 Recharge, 2020/2021) even support much of the functionality many other cars have.Through dealers and directly to Volvo (feedback mailaddresses and even a pioneers forum), but they will not budge....i guess there are so many more other users (not so tech savvy) that are happy and even the tech savvy ones (like me) will not trade them in just because of the lack of technical functionality other cars do have...

HWiese1980 commented 1 year ago

Outrageous. That really spoils my fun with the car. I cannot even integrate it in Tibber that way. It's absolutely embarrassing that a renowned car company like Volvo shits on their customers like that, and we, the customers, can't do much about it, other than not buying their cars - which they don't give any shits about either because enough people still buy their cars.

HWiese1980 commented 1 year ago

What's funny though is that I can actually get the data from my car by means of their demo API. It works. I just can't integrate it into my Home Assistant without "publishing" it - which probably is going to be denied because I'm just a plebs mortal ordinary customer, my needs negligible, my money worthless, my opinion even less of worthless... It'd be funny if it wasn't so sad...

bmesuere commented 1 year ago

@HWiese1980 Can't you use the token from https://github.com/akamming/Domoticz_VolvoRecharge_Plugin/blob/main/plugin.py#L129 ?