Dielee / volvo2mqtt

Home Assistant addon for connecting AAOS Volvos
MIT License
125 stars 25 forks source link

Volvo api unstable #167

Closed mfrimannm closed 4 months ago

mfrimannm commented 5 months ago

Hi

Is it just me or is the api unstable to a point where it is unusable? I have created an app getting a api key primary and secondary. I have linked my volvo ID and added my vin number to the comfiguration.

I have even tried the online playground on volvo website and seen that the application and volvo Id gives informations from my car.

But plugging it into the env and starting the container just gives me the same old error VCCAPIKEY not working and even if a get to next step is then says. "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application."

And what's worse is that now trying on volvo website now also doesn't work... Am I doing something wrong or is it just not that reliable?

BR Mads

Dielee commented 5 months ago

For me, the API is pretty stable. Yes there are some frequent changes, but overall it works very well. Why doesn't it work that well for a few people, I don't know.

Three things came to my mind:

  1. Are you using only the primary API key ?
  2. Is it working against the V1 API ? Have you tried this at the Volvo page ?
  3. Where do you come from ? I have seen a few different behaviors for specific countries.
droidgren commented 5 months ago

I believe I have the same problem, I created a volvo developer account yesterday and keep getting: Access denied due to invalid VCC-API-KEY

I can see that volvo2mqtt is making API calls since I get "Request today". I don't need to publish the application right? Country: sv-SE

Jan 25 10:29:27 volvo2mqtt [106] - ERROR: API Call failed. Status Code: 401. Error: {  
                        "status": 401,
                        "error": {  
                            "message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application."
                        }

I have tried creating new API applications, with the same result. image How do I change the API version?

Dielee commented 5 months ago

You don't need to publish the app, right! What are the log entries above the pasted log lines ?

droidgren commented 5 months ago

I get this log on Start 982ee2c4_volvo2mqtt_2024-01-25T12-44-57.024Z.log (keys are scrambled)

On restart I get is log 982ee2c4_volvo2mqtt_2024-01-25T12-47-06.272Z.log

image

FireWizard52 commented 5 months ago

Hi,

@mfrimannm wrote:

I have created an app getting a api key primary and secondary. I have linked my volvo ID and added my vin number to the comfiguration.

Is it correct, that I conclude that you use an own application and not the volvo2mqtt plugin? And that you have designed your own "authorization"?

I use the Connected Vehicle API, version 2, the Energy API and the Location API without any problem for about 2-3 months. I created my own Node-RED application.

A few things:

  1. Everywhere in the documentation, it has been written that the access token will expire in 1 hour and that you have to refresh it before it expires. Do not login all the time. However I discovered that the token expires in 0.5 hours (1799 seconds) So refresh it in time.

  2. The data that some API endpoints return depend on the model and version of your vehicle. Data that do not exist or that is not available return "UNSPECIFIED".

  3. I noticed that the "Primary VCC-API key" of the Connected Vehicle API also works for the Energy and Location API. The others gave a failure. However, I did not test very intensively the keys that gives a failure, as I had a working one. Try it only with the "Primary VCC-API key" of the Connected Vehicle API.

Regards

droidgren commented 5 months ago

In the Volvo developer portal I can see that volvo2mqtt is making API calls since I get "Request today". I am using a Primary key from three different API applications. Whats weird is that I only see the last key being used in the Volvo developer portal If volvo2mqtt is trying to use each key shouldn't all keys be tested?

Dielee commented 5 months ago

In the Volvo developer portal I can see that volvo2mqtt is making API calls since I get "Request today". I am using a Primary key from three different API applications. Whats weird is that I only see the last key being used in the Volvo developer portal If volvo2mqtt is trying to use each key shouldn't all keys be tested?

I have an idea whats going on there, but I need a full startup log please. So restart and send me the full log after volvo2mqtt restarted.

droidgren commented 5 months ago

I have an idea whats going on there, but I need a full startup log please. So restart and send me the full log after volvo2mqtt restarted. Sure, here it is 982ee2c4_volvo2mqtt_2024-01-26T06-46-29.953Z.log

droidgren commented 5 months ago

Also, should I need to "Authorise my car" in the developer portal?

Dielee commented 5 months ago

Also, should I need to "Authorise my car" in the developer portal?

No, you don't.

Dielee commented 5 months ago

Would you please enter your car vin manually to the configuration and send me the log ?

droidgren commented 5 months ago

Would you please enter your car vin manually to the configuration and send me the log ? Sure. 982ee2c4_volvo2mqtt_2024-01-26T07-08-11.238Z.log

Dielee commented 5 months ago

It works now. Please check your entities in HA ;)

droidgren commented 5 months ago

It works now. Please check your entities in HA ;)

Sure it does, still API Called failed in the logs though. Thanks,

Dielee commented 5 months ago

Yes, there are some endpoints which are not working. But the core of the component will work. I don't why are some api calls are failing... This seems to be a volvo issue.

Michel-NL commented 5 months ago

I'm having the same problem. Sometimes it works and sometimes (80% of the case) it will give an error with the status code 401. This problem has also been raised on the Volvo Developer github https://github.com/volvo-cars/developer-portal-api-samples/issues/8

And the same behavior with the error is on the Volvo site https://developer.volvocars.com/apis/connected-vehicle/v2/specification/#openapi Doesn't matter if you choose API v1 or v2.

image

Could it be something with the 150 seconds blocking time? https://developer.volvocars.com/apis/connected-vehicle/v2/release-notes/#breaking-changes Commands - The version 2 of the command API is synchronous and the status returned will determine the outcome of the command. The request will block for up to 150 seconds so the caller may choose to wrap the call in an asynchronous structure in their preferred language. The response structure for commands has changed. It now includes more detailed information about the executed command, such as invocation status.

Dielee commented 5 months ago

Ah, good to know. My addon works without any issues, so this error may be account specific.... The blocking time is only for the "commands", such as "Start climate", not for the api key check at all. This can't be our problem here.

But... How do you login at the volvo dev portal ? Google ? Github ?

Michel-NL commented 5 months ago

Ah, good to know. My addon works without any issues, so this error may be account specific.... The blocking time is only for the "commands", such as "Start climate", not for the api key check at all. This can't be our problem here.

But... How do you login at the volvo dev portal ? Google ? Github ?

The Volvo developer account is linked to my Github account. Once you are going to try the API I'm logging in with my Volvo ID image

Just tried it with the demo account and it is the same. I can get the "demo" Vin vehicles but every other API call throws the 401 error.

Dielee commented 5 months ago

So this may be another api issue, great...

Michel-NL commented 5 months ago

Think so and the results are always different. In the log you can see that some sensors are not supported for my vehicle, if I try it tomorrow or in an hour, then the sensor is available and an other sensor which was available is now unavailable. _volvo2mqtt_logs (1).txt

Michel-NL commented 5 months ago

Looks like we are going to have an solution :)

image

mfrimannm commented 5 months ago

Hi, I am using volvo2mqtt and have been working sometimes for me with Homeassistant too. But for now it just giving me an error

FireWizard52 commented 5 months ago

Hi,

I looked to the various supplied log files, by @droidgren, and one thing is very similar.

You use multiple VCC-API-keys. I do not know, which API key. I have never seen this in my application.

The VCC-API key is only used, when querying an endpoint. It is not used during the OAuth2.0 authorization process. I recommend to use the primary VCC-API-key of the Connected Vehicle API. With that VCC-API-key, I also receive responses from the Energy and the Location API, so there is no reason to use multiple APi keys. With other keys I have seen errors as well.

1. It is not important, whether you use version 1 or version 2 of the Connected Vehicle API, but version 1 is deprecated and will be removed on April 30, 2024. See: https://developer.volvocars.com/apis/connected-vehicle/v1/endpoints/climate/
So any development against version 1 is useless. This volvo2mqtt plug-in uses version 2 and so do I.

2. It is not necessary to log-in to the Volvo Developer account or to stay logged-in, if you run this application. Volvo will even disconnect you after a couple of days.

I know this Connected Vehicle API is not extreme stable as I see also that sometimes "UNSPECIFIED" is shown.

See picture below for a window/ (All windows show the same) So this was a temporary issue with the Volvo endpoint, but not a VCC-API issue/

Screenshot_Window_Log_volvo_API

The "warnings" endpoint gives for all light bulbs "UNSPECIFIED", and I noticed also this for the tank lid.

The cause cannot be the connection between the car and the Volvo server, as I also run the "molobrakos" python application for more than 5 years without any issue. So it is the connection between the Volvo server and our applications.

Regards

droidgren commented 5 months ago

Yes, there are some endpoints which are not working. But the core of the component will work. I don't why are some api calls are failing... This seems to be a volvo issue.

Seems like it was a one time event , I have not got any more successful updates since that one.

Hi,

I looked to the various supplied log files, by @droidgren, and one thing is very similar.

You use multiple VCC-API-keys. I do not know, which API key. I have never seen this in my application.

The VCC-API key is only used, when querying an endpoint. It is not used during the OAuth2.0 authorization process. I recommend to use the primary VCC-API-key of the Connected Vehicle API. With that VCC-API-key, I also receive responses from the Energy and the Location API, so there is no reason to use multiple APi keys. With other keys I have seen errors as well.

I have only been using Primary keys. Using one or more makes no difference at all.

timknowlden commented 5 months ago

I'm also having a hard time getting any stability from my connection to the API. different start ups of the container give different errors. Entities come and go I get invalid vccapikey in the logs followed bt successful messages. I guess I set this up at a bad time as volvo are clearly having issues with the API which makes getting the config correctly set up even more difficult

droidgren commented 5 months ago

For some reason, connection to the API has started now work now, have been sucessfully been updating all weekend. Don't know if was just a matter of API being more stable again, or if it was because I actually did something. But this is what I did

I still get a lot of "ERROR: API Call failed. Status Code: 401" in the logs though.

Michel-NL commented 5 months ago

It looks like it is doing a lot more now. Also on the dev portal it is much better now. Occasionally on the portal I get the 401 error, but after pressing again on execute it will work.

Jan 31 19:20:29 volvo2mqtt [1] - INFO: Starting volvo2mqtt version v1.8.27 Jan 31 19:20:30 volvo2mqtt [1] - INFO: Using VCCAPIKEY: 58acca904xxxxx Jan 31 19:20:30 volvo2mqtt [1] - INFO: Vin: ['xxxxxxxxxx'] found! Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Battery Charge Level is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Electric Range is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Estimated Charging Time is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Charging System Status is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Charging Connection Status is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Estimated Charging Finish Time is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:20:30 volvo2mqtt [1] - INFO: Failed, Odometer is unfortunately not supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Last Data Update is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Active schedules is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Window Front Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Window Front Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Window Rear Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Window Rear Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Door Front Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Door Front Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Door Rear Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Door Rear Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tailgate is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Engine Hood is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tank Lid is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Sunroof is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Air Conditioning is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Lock state is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Force Update Data is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:20:30 volvo2mqtt [1] - INFO: Failed, Location is unfortunately not supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tire Front Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tire Front Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tire Rear Left is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Tire Rear Right is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Engine State is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:20:30 volvo2mqtt [1] - INFO: Failed, Fuel Level is unfortunately not supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Average Fuel Consumption is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Average Energy Consumption is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Distance to Empty Tank is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Distance to Empty Battery is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Average Speed is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Hours to Service is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Distance to Service is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Time to Service is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Service warning status is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Washer Fluid Level warning is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! API Backend status is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - INFO: Success! Update Interval is supported by your vehicle. Jan 31 19:20:30 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:20:30 volvo2mqtt [1] - INFO: Failed, Warnings is unfortunately not supported by your vehicle. Jan 31 19:20:32 volvo2mqtt [1] - INFO: Sending mqtt update... Jan 31 19:20:32 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:20:32 volvo2mqtt [1] - INFO: Mqtt update done. Next run in 300 seconds.

Michel-NL commented 5 months ago

Okay it worked one time (the initial start of the container) and after that it only generates 401 errors. The same API key still works on the website. test.txt

Michel-NL commented 5 months ago

Sorry for spamming the thread.

Some things I noticed. Whenever it gets an 401 on the first try when the container starts, it will not be retried in the next requests. In this case I got the 401 error on the Odometer. I know it works by checking the API on the portal. Same error I got on location, and I know that also works with the API.

Jan 31 19:43:38 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/odometer Jan 31 19:43:38 volvo2mqtt [1] - DEBUG: Response status code: 401 Jan 31 19:43:38 volvo2mqtt [1] - DEBUG: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:43:38 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 401. Error: {
"status": 401, "error": {
"message": "Access denied due to invalid VCC-API-KEY. Make sure to provide a valid key for an active application." } } Jan 31 19:43:38 volvo2mqtt [1] - INFO: Failed, Odometer is unfortunately not supported by your vehicle.

With ever request it gets random 401 errors. This is just the API from Volvo, same behavior is on the Volvo portal. Is it maybe an option to add an value in the config for how many retries it may do when there is an 401? For users who have no problem could leave it empty or ignore it. But for other users it could be helpful to start with 2 or maybe bump it up to 3. Maybe a disclaimer would be handy, because i'm not sure if an 401 will count for your delay 10000 limit requests.

Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors
Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Response status code: 200
Jan 31 19:48:42 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors
Jan 31 19:48:43 volvo2mqtt [1] - DEBUG: Response status code: 401
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Response status code: 200

Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/statistics
Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Response status code: 200
Jan 31 19:48:43 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/statistics
Jan 31 19:48:43 volvo2mqtt [1] - DEBUG: Response status code: 401
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/statistics
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Response status code: 200

Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics
Jan 31 19:43:39 volvo2mqtt [1] - DEBUG: Response status code: 200
Jan 31 19:48:43 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics
Jan 31 19:48:43 volvo2mqtt [1] - DEBUG: Response status code: 200
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics
Jan 31 19:53:43 volvo2mqtt [1] - DEBUG: Response status code: 401
droidgren commented 4 months ago

I had it running for a week or so but now it decided to stop , but there seems to be a new error this time.

"API: Service not enabled"

Any clues? I cannot see any changes at the developers portal.

Successfully started
[08:09:35] ERROR: Got unexpected response from the API: Service not enabled
Feb 06 08:09:37 volvo2mqtt [107] - INFO: Starting volvo2mqtt version v1.8.27
Traceback (most recent call last):
  File "/volvoAAOS2mqtt/main.py", line 13, in <module>
    set_mqtt_settings()
  File "/volvoAAOS2mqtt/util.py", line 134, in set_mqtt_settings
    raise Exception("MQTT connection could not be established. Please check if your 
droidgren commented 4 months ago

I had it running for a week or so but now it decided to stop , but there seems to be a new error this time.

"API: Service not enabled"

Any clues? I cannot see any changes at the developers portal.

Successfully started
[08:09:35] ERROR: Got unexpected response from the API: Service not enabled
Feb 06 08:09:37 volvo2mqtt [107] - INFO: Starting volvo2mqtt version v1.8.27
Traceback (most recent call last):
  File "/volvoAAOS2mqtt/main.py", line 13, in <module>
    set_mqtt_settings()
  File "/volvoAAOS2mqtt/util.py", line 134, in set_mqtt_settings
    raise Exception("MQTT connection could not be established. Please check if your 

I fixed this by restarted the MQTT addon. Don't know why a got the API error....

pvfpinto commented 4 months ago

Hi, having issues regarding the API but I think that is related with my model. V60 T6 will be support?

thanks.

mfrimannm commented 4 months ago

It seems to be running now, lets hope Would love to use this nice integration 👍