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
70k stars 29.08k 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

MikaelHoogen 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 šŸ˜…

Ah it sucks. With each update they fix some bugs and introduce a couple of new ones. Can you get the status of the odometer? Empty in the response for me

youtoofan commented 1 year ago

Just tested climate:

post: https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN/commands/climatization-start

response: { "status": 202, "operationId": "34c2559a-1f12-4dee-814d-b43f4592a664", "async": { "status": "RUNNING", "id": "65a1d1ff-1642-4980-a842-2c56ebc7f38c", "href": "https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN/requests/65a1d1ff-1642-4980-a842-2c56ebc7f38c", "expires": "2023-08-07T16:26:31Z" } }

IceBotYT commented 1 year ago

Just tested climate:

post: https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN/commands/climatization-start

response: { "status": 202, "operationId": "34c2559a-1f12-4dee-814d-b43f4592a664", "async": { "status": "RUNNING", "id": "65a1d1ff-1642-4980-a842-2c56ebc7f38c", "href": "https://api.volvocars.com/connected-vehicle/v1/vehicles/MY-VIN/requests/65a1d1ff-1642-4980-a842-2c56ebc7f38c", "expires": "2023-08-07T16:26:31Z" } }

Fantastic! Looks like we can get the C40 working with Home Assistant šŸŽ‰šŸŽ‰

rrlevy commented 1 year ago

I have an early 2022 XC40 and it's still not working. I'm still getting "resource not found" when using my VIN:

{
    "status": 404,
    "operationId": "3a9b1549-310c-4dc2-9195-2c36a83773b5",
    "error": {
        "message": "NOT_FOUND",
        "description": "resource not found"
    }
}
distantcompany commented 1 year ago

I have an early 2022 XC40 and it's still not working. I'm still getting "resource not found" when using my VIN:

{
    "status": 404,
    "operationId": "3a9b1549-310c-4dc2-9195-2c36a83773b5",
    "error": {
        "message": "NOT_FOUND",
        "description": "resource not found"
    }
}

Same here with my 22.5 XC60 Recharge. I've tried every possible combination of my app's API key, connected vs. extended API access token, both in Postman and using the sandbox, and I get nothing but errors.

I was able to make calls against the Demo vehicle, but when I try against my own account, even when querying my specific vin, which I already know, I get nada.

Maybe the C40 is the only AAOS model this works with so far?

IceBotYT commented 1 year ago

Maybe the C40 is the only AAOS model this works with so far?

If only we had someone from Volvo to tell us what the status is on this. Oh wait...

tgambee-digital commented 1 year ago

Has anyone revisited this since the latest update that added CarPlay? Not that it should, but maybe it was a big enough change to have made a difference. I don't see any, but I'm not the best at testing these things. The API documentation still says: "Note: This API works for all connected vehicles up to model year 2021, excluding the XC40 Recharge BEV."

IceBotYT commented 1 year ago

Has anyone revisited this since the latest update that added CarPlay? Not that it should, but maybe it was a big enough change to have made a difference. I don't see any, but I'm not the best at testing these things. The API documentation still says: "Note: This API works for all connected vehicles up to model year 2021, excluding the XC40 Recharge BEV."

As far as I'm aware, we tested on the CarPlay update.

karllinder commented 1 year ago

Hi! New API from Volvo just released https://developer.volvocars.com/apis/energy/specification/

IceBotYT commented 1 year ago

This is great! It's only a matter of time until they release an API for the GA cars similar to the connected vehicle API, or even better, update the connected vehicle API to allow it!

P.S. I found an email! developer.portal(at)volvocars.com

karllinder commented 1 year ago

Looks like this new API is the way forward, this from the info text:

Note: This API works for all plug-in hybrid and electric vehicles which are equipped with Google Automotive System (Google built-in). Recharge status data is updated both when the vehicle is parked (key-off) and when a charging session is initiated.

youtoofan commented 1 year ago

seems https://api.volvocars.com/connected-vehicle/v1/vehicles now returns my vehicle VIN too. Which failed previously.

karllinder commented 1 year ago

I am not a expert on this, but finnaly manage to get some data from the API

{
  "status": 200,
  "operationId": "xxx",
  "data": {
    "batteryChargeLevel": {
      "value": "50.0",
      "unit": "percentage",
      "timestamp": "2022-09-11T13:53:51.900Z"
    },
    "electricRange": {
      "value": "220",
      "unit": "kilometers",
      "timestamp": "2022-09-11T13:53:51.900Z"
    },
    "estimatedChargingTime": {
      "value": "2047",
      "unit": "minutes",
      "timestamp": "2022-09-11T13:53:51.900Z"
    },
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_CONNECTED_AC",
      "timestamp": "2022-09-11T13:53:51.900Z"
    },
    "chargingSystemStatus": {
      "value": "CHARGING_SYSTEM_IDLE",
      "timestamp": "2022-09-11T13:53:51.900Z"
    }
  }
}
karllinder commented 1 year ago

Sorry for spam, but looks like connected API now also work: https://api.volvocars.com/connected-vehicle/v1/vehicles/XXX/battery-charge-level

Response bodyDownload{   "status": 200,   "operationId": "xxxy",   "data": {     "batteryChargeLevel": {       "value": "50.0",       "unit": "percentage",       "timestamp": "2022-09-11T13:53:51.876Z"     }   } }
IceBotYT commented 1 year ago

Would getting the location of the car work? I know it's a long shot, since it's not even available in the app.

karllinder commented 1 year ago

@IceBotYT - no, looks like the API do not has that yet.

distantcompany commented 1 year ago

Can anyone confirm which models are you suddenly getting data back for? I'm trying again with our 2022.5 XC60 Recharge and still getting nothing.

Get vehicle list:

{
  "status": 200,
  "operationId": "b4cb362f-8275-4a64-89ff-81febcb29ec8",
  "data": [],
  "pagination": {
    "limit": 0,
    "total": 0
  }
}

Get details on my VIN:

{
  "status": 404,
  "operationId": "3b193bbe-7f71-4342-87a8-0918dec734a2",
  "error": {
    "message": "NOT_FOUND",
    "description": "resource not found"
  }
}
IceBotYT commented 1 year ago

We're testing with the 2022 C40 Recharge. Is yours a Google Automotive car?

distantcompany commented 1 year ago

Yep. AAOS. Feels like maybe the APIs are still only working against full EVs (40 models).

karllinder commented 1 year ago

Yep. AAOS. Feels like maybe the APIs are still only working against full EVs (40 models).

Hi

Yes, I have a full EV XC40 2022 model.

wixoff commented 1 year ago

@rschend I'm not getting anything either, and I have both an XC60 Hybrid (2018) and a C40 EV (2022) on my account. I get the same responses you do: the API request to list vehicles "works," in a sense, in that it authenticates and returns a 200 status code. But the data section of the response is empty. And using my VIN (for either car) returns a 404.

I wonder if it's a regional thing? I'm in North America.

In any case, I appreciate that it's apparently being worked on.

distantcompany commented 1 year ago

@rschend I'm not getting anything either, and I have both an XC60 Hybrid (2018) and a C40 EV (2022) on my account. I get the same responses you do: the API request to list vehicles "works," in a sense, in that it authenticates and returns a 200 status code. But the data section of the response is empty. And using my VIN (for either car) returns a 404.

I wonder if it's a regional thing? I'm in North America.

In any case, I appreciate that it's apparently being worked on.

Oh that's interesting that not even your 2018 XC60 works, since that's Sensus and afaik, those all still work fine with the API. I was about to say, it feels like Sensus cars still work...and XX40 models on AAOS now work, but all other models on AAOS are left out of the party.

FWIW, I was always able to get responses on the Connected API for our 2019 XC40 (gas only) before we traded it in for this new XC60 Recharge. I wonder if the Sensus-based hybrids ever worked?

Also in NA, by the way.

wixoff commented 1 year ago

The older Volvo On Call (VOC) API still works for the 2018 XC60, so it's possible the new Connected API is currently in a semi-broken state I guess, and I'll wait for it to settle down.

I too was able to get info on the XC60 from the Connected API a week or two ago.

rrlevy commented 1 year ago

I also CAN'T access my 2022 XC40 (Pure Electric) using the new api. I also get error 404.

Also, the old https://api.volvocars.com/connected-vehicle/v1/vehicles is also not showing my VIN....

PeteH010 commented 1 year ago

This new Energy API isn't pulling any data for me. July 2022 XC60 PHEV (AAOS) - UK

curl -X 'GET' \
  'https://api.volvocars.com/energy/v1/vehicles/MY-VIN/recharge-status/battery-charge-level?vcc-api-key=<API KEY>' \
  -H 'accept: application/vnd.volvocars.api.energy.vehicledata.v1+json' \
  -H 'vcc-api-key: <API KEY>' \
  -H 'Authorization: Bearer <ACCESS TOKEN>'

{
  "status" : 404,
  "operationId" : "1f7bfe0e-a840-4145-a925-659218448197",
  "error" : {
    "message" : "NOT_FOUND",
    "description" : "resource not found"
  }
}%
aerikers commented 1 year ago

This works in Sweden on a XC40 pure:

api.volvocars.com/energy/v1/vehicles/[MY VIN]/recharge-status/battery-charge-level

{
    "status": 200,
    "operationId": "46d50433-4e88-4378-a163-9177bb02e22b",
    "data": {
        "batteryChargeLevel": {
            "value": "70.0",
            "unit": "percentage",
            "timestamp": "2022-09-15T07:31:57.855Z"
        }
    }
}
lyndonfoo commented 1 year ago

I have an XC40 pure in Australia and I am getting the ā€œresource not foundā€ response for a battery charge level request.

I also get a successful (status: 200) but empty response when querying for the list of vehicles for my Volvo ID

shillbom commented 1 year ago

This new Energy API isn't pulling any data for me. July 2022 XC60 PHEV (AAOS) - UK

curl -X 'GET' \
  'https://api.volvocars.com/energy/v1/vehicles/MY-VIN/recharge-status/battery-charge-level?vcc-api-key=<API KEY>' \
  -H 'accept: application/vnd.volvocars.api.energy.vehicledata.v1+json' \
  -H 'vcc-api-key: <API KEY>' \
  -H 'Authorization: Bearer <ACCESS TOKEN>'

{
  "status" : 404,
  "operationId" : "1f7bfe0e-a840-4145-a925-659218448197",
  "error" : {
    "message" : "NOT_FOUND",
    "description" : "resource not found"
  }
}%

Weird. It works for my XC60 Recharge 2022. I also get the data using the connected-vehicle-api. There I can read battery level but not fuel. All endpoints in the energy api works as expected.

I can also use the connected-vehicle-api api to read locked / unlocked of all windows and doors and lock / unlock the car.

eddyvanroy commented 1 year ago

This new Energy API isn't pulling any data for me. July 2022 XC60 PHEV (AAOS) - UK

curl -X 'GET' \
  'https://api.volvocars.com/energy/v1/vehicles/MY-VIN/recharge-status/battery-charge-level?vcc-api-key=<API KEY>' \
  -H 'accept: application/vnd.volvocars.api.energy.vehicledata.v1+json' \
  -H 'vcc-api-key: <API KEY>' \
  -H 'Authorization: Bearer <ACCESS TOKEN>'

{
  "status" : 404,
  "operationId" : "1f7bfe0e-a840-4145-a925-659218448197",
  "error" : {
    "message" : "NOT_FOUND",
    "description" : "resource not found"
  }
}%

Weird. It works for my XC60 Recharge 2022. I also get the data using the connected-vehicle-api. There I can read battery level but not fuel. All endpoints in the energy api works as expected.

I can also use the connected-vehicle-api api to read locked / unlocked of all windows and doors and lock / unlock the car.

For an full electric XC40 it is working, should you not leave the "vcc-api-key=" as url parameter? See postman sample image

eddyvanroy commented 1 year ago

BTW: did someone already solve the volvo OAuth 2 procedure in their home automation?

https://developer.volvocars.com/apis/docs/authorisation/ _"To start the authorisation process you need to have client credentials for the Volvo ID identity system. This is done by publishing your application on your account page. Once the publishing process is done, we will send you the client credentials needed to continue. The client credentials consist of; a client_id and a client_secret."__

cybermaniapt commented 1 year ago

After checking that there was an integration with home assistant (a few months ago) and receiving my new car (xc60 2023) this week, it was with great disappointment that I now realized that the integration is broken for most of us / new cars :| :|

Installed and there are no new entities or errors on the logs.

It would be great if this can get reworked, unfortunately I don't have enough knowledge to help much other then be available to test anything needed!

@molobrakos , is this something that you could help with?

eddyvanroy commented 1 year ago

BTW: did someone already solve the volvo OAuth 2 procedure in their home automation?

https://developer.volvocars.com/apis/docs/authorisation/ "To start the authorisation process you need to have client credentials for the Volvo ID identity system. This is done by publishing your application on your account page.

At the "application" submission, you also need a legal disclaimer of your application. I've a draft available for my node Red configuration, but has someone already created this in the past already?

In commercial solutions you would have 1 application (and secret/id) handling multiple users (Volvo IDs). In my "application" (the node red flow) I would like to have 1 application (and secret/id) handling only 1 (your own) Volvo ID.

BTW: my node-red configuration is inspired from https://github.com/FireWizard52/Volvo-Extended-Vehicle-API-to-Domoticz

shillbom commented 1 year ago

I have created a request to get appsecret and id. Let's see what they say.

I would assume that secret / id could be included in the integration, as the user has to authenticate and redirect against volvo (much like the apps).

monsivar commented 1 year ago

I have created a request to get appsecret and id. Let's see what they say.

I would assume that secret / id could be included in the integration, as the user has to authenticate and redirect against volvo (much like the apps).

Any update on this topic or the request for an appsecret? got my new C40 Recharge on friday and was hoping for an integration so i can plan my charging.

I tested https://github.com/FireWizard52/Volvo-Extended-Vehicle-API-to-Domoticz in Node Red for som statuses, but this dos not contain any energy information

odin- commented 1 year ago

I was also thinking about requesting an app secret. shillbom did you create any github project which you've referenced in your request?

shillbom commented 1 year ago

@odin- I tried to explain the situation in the free text fields. I still havenā€™t heard anything from them.

letā€™s see what they say. If anyone gets a hold of appid / secret I can help add the new logic to the integration :)

odin- commented 1 year ago

@shillbom excellent. Waiting eagerly for an answer. Or perhaps it should be a totally new integration? Dunno if they can coexist in a good way, then the API needs to be selected somewhere?

IceBotYT commented 1 year ago

Update: The Volvo Cars app has now been updated to include the car's location and range now. This might mean the API changes mentioned before are probably complete now.

IceBotYT commented 1 year ago

Exciting news! I just checked the Connected Vehicle API, and C40 and other AAOS cars are now supported!!!! Edit: I am wrong. Read it again. image

shillbom commented 1 year ago

@IceBotYT Exciting! Location is very important if you want to automate. Like locking doors when at home and at night.

@odin- Still havenā€™t heard anything. I was thinking about if we could extract the keys from the android app or something? Havenā€™t had time to investigate more :(

wixoff commented 1 year ago

@IceBotYT I hate to pour cold water on things - but that announcement reads to me as all models EXCEPT AAOS models are supported.

And North America is still excluded, so I'll continue to sit this one out for now. It definitely is progress that the app and the API documentation site have been updated, though, so that's good.

IceBotYT commented 1 year ago

@IceBotYT I hate to pour cold water on things - but that announcement reads to me as all models EXCEPT AAOS models are supported.

I just reread it. I feel like an idiot šŸ˜…

Sorry to cause the confusion!

odin- commented 1 year ago

@shillbom :-(. I am thinking to use some kind of hack to update the key every hour. Web scraping using Selenium and Python.

Did some experiments, however got stuck at two factor authentication if logging in either using Google or GitHub. Perhaps I should have a GitHub account without two factor I can use...

Also I had problems finding the "Log in" button @ Volvo Developer by using Selenium. However that got solved when I used the Chrome Selenium IDE add-on and tried to "record" the sequence.

cybermaniapt commented 1 year ago

Hi everyone,

Just for me to understand, are the more recent cars from Volvo with AAOS not supported at all by the Volvo integration on HA? If so this is because Volvo hasn't created a way to get that information or because the integration on HA needs to be upgraded? Kind regards!

IceBotYT commented 1 year ago

AAOS Volvos are not supported by the Volvo integration. This is because Volvo has not released support for an official API yet.

rrlevy commented 1 year ago

Actually, Volvo HAS released the new Energy API integration for AAOS cars, but it is still not available in some countries (only Europe and Asia)

Em qui., 17 de nov. de 2022 Ć s 18:22, IceBotYT @.***> escreveu:

AAOS Volvos are not supported by the Volvo integration. This is because Volvo has not released support for an official API yet.

ā€” Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/61785#issuecomment-1319221826, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLJAEMRUVTVSRSTDKOTKHDWI2O2BANCNFSM5KAO57KA . You are receiving this because you were mentioned.Message ID: @.***>

--

Rafael Rocha Levy Cel: +55 11 9 9631-3901

shillbom commented 1 year ago

@odin- Did you get anywhere with the scraper? If you have something that might run on a RPi I can try to help.

The main issue I want to fix is to schedule charging. As of now my charge box turns on at 22:00 but the car is sleeping so it does not start charging... I have to wake it up using the app or by locking the doors. So silly. I bought a SwitchBot to press the car key but it's to weak so I'm going to build something with Lego to make it work.

odin- commented 1 year ago

@shillbom I think I need to create an additional Gmail account without two factory authentication as scraping cannot get passed Gmail login on Volvo Dev site.

But haven't had time yet :-(

AndiMert commented 1 year ago

ioBroker Community built a working Integration for AAOS. It works without Oauth - you just need a vcc api key https://github.com/TA2k/ioBroker.volvo

andynash commented 1 year ago

ioBroker Community built a working Integration for AAOS. It works without Oauth - you just need a vcc api key https://github.com/TA2k/ioBroker.volvo

I'm not familiar with ioBroker, but that looks interesting. How is it working behind the scenes though - scraping?

Edit: it looks as though it might be possible to connect HA to ioBroker (using MQTT, or an integration which appears to only work HA-->ioBroker but I may be wrong). However that seems overcomplicated to me, unless ioBroker is providing a lot of value.