Dielee / volvo2mqtt

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

Important Notice: Deprecation of Connected Vehicle API Version 1 and Migration to Version 2 #172

Closed FireWizard52 closed 3 months ago

FireWizard52 commented 4 months ago

Hi, for your information

I received the following email from Open Innovation Portal developer.portal@volvocars.com

Upgrade now for improved functionality and performance with Version 2 of our Connected Vehicle API.

*Important Notice: Deprecation of Connected Vehicle API Version 1 and Migration notice to* Connected Vehicle API Version 2

Dear Developers,

We want to inform you that the Connected Vehicle API Version 1 will be deprecated and removed from our portal on April 30, 2024.

As you may know, we're continuously striving to improve our services and enhance your experience with our developer portal. In line with this commitment, we are excited to announce the availability of the latest version, Version 2, of our Connected Vehicle API.

Please transition to Version 2 for improved functionality and performance. Explore the latest features here ( https://developer.volvocars.com/apis/connected-vehicle/v2/overview/ ).

Connected Vehicle API V2.0 ( https://developer.volvocars.com/apis/connected-vehicle/v2/overview/ )

If you need assistance, our support team is here to help - please feel free to get in touch with us at [developer.portal@volvocars.com](mailto:developer.portal@volvocars.com).

Thank you for your cooperation.

Best regards,

Volvo Cars Developer Portal
Dielee commented 4 months ago

Yeah, thanks for this information. We are completely on V2 right now!

iz3man commented 4 months ago

Any idea why i don't see most of the sensors then for the last few days? Do we need to alter the configuration? Get a new key? Anything like that? Thanks

That's all I get at the moment:

}
Feb 19 15:27:41 volvo2mqtt [107] - DEBUG: Response status code: 200
Feb 19 15:27:41 volvo2mqtt [107] - DEBUG: {
  "data" : {
    "serviceWarning" : {
      "value" : "REGULAR_MAINTENANCE_TIME_FOR_SERVICE",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "serviceTrigger" : {
      "value" : "CALENDAR_TIME",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "engineHoursToService" : {
      "value" : 527,
      "unit" : "h",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "distanceToService" : {
      "value" : 25391,
      "unit" : "km",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "washerFluidLevelWarning" : {
      "value" : "NO_WARNING",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "timeToService" : {
      "value" : 0,
      "unit" : "days",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    }
  }
}
Feb 19 15:27:41 volvo2mqtt [107] - DEBUG: Response status code: 200
Feb 19 15:27:41 volvo2mqtt [107] - DEBUG: {
  "data" : {
    "serviceWarning" : {
      "value" : "REGULAR_MAINTENANCE_TIME_FOR_SERVICE",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "serviceTrigger" : {
      "value" : "CALENDAR_TIME",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "engineHoursToService" : {
      "value" : 527,
      "unit" : "h",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "distanceToService" : {
      "value" : 25391,
      "unit" : "km",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "washerFluidLevelWarning" : {
      "value" : "NO_WARNING",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    },
    "timeToService" : {
      "value" : 0,
      "unit" : "days",
      "timestamp" : "2024-02-19T14:25:08.542Z"
    }
  }
} 
Dielee commented 4 months ago

What do you mean with "you don't see most of the sensors" ?

iz3man commented 4 months ago

Same issue like that one https://github.com/Dielee/volvo2mqtt/issues/171 Only the entities I posted in the log excerpt are seen. All others like mileage, fuel, etc .... are GONE. Just vanished. EDIT: Nah. Not completety gone, but a lot are not updated. Average fuel consumption/speed is there, but charging and such is missing.

iz3man commented 4 months ago

I checked which entities are missing / not getting any update from Volvo. These are the ones:

battery_charge_level charging_connection_status charging_system_status electric_range estimated_charging_finish_time estimated_charging_time

So basically all petrol based sensors, and door/window, service, odometer etc work fine. All ELECTRIC sensors are missing.

FireWizard52 commented 4 months ago

Hello @iz3man,

The entities, you are missing or that do not receive an update, are exactly the endpoints from the Energy API. See: https://developer.volvocars.com/apis/energy/v1/overview/

After a period that I only received an empty object, when querying any of the Energy endpoints, it started to work.

From February 14, about 15:11 it failed again, but now with a 404 error and a message "NOT_FOUND", with a description "Car model is not supported".

I have a XC40 PHEV model year 2023. What is the model of your car?

Regards

iz3man commented 4 months ago

Yep. About a week ago troubles started. My wife's car is a 2021 XC40 T4 Recharge PHEV.

FireWizard52 commented 4 months ago

Hi @iz3man,

Then that is the problem, as I have the same car (but 2 years younger). I don't think that Linus can help you, as it is not related to his application, but it is a Volvo issue.

I hope that we will get a stable API sooner or later and that all available sensors are supported.

Regards

iz3man commented 4 months ago

That's bad. It's the only sensors I'm interested in :) Knowing the state of charge, and when/if to charge and when to stop. :(

schrej-zz commented 4 months ago

Hi, I also don't get any data besides the config data. Volvo XC40 Recharge 2024

iz3man commented 3 months ago

@Dielee Linus, is this something that the user has to solve? Is only the XC40 Recharge affected by that issue? Anything we can do? Is it up to Volvo to change anything (unlikely) or do you (or someone else) alter the Add-On? Thanks in advance.

Dielee commented 3 months ago

We are completely on V2. So if your car does not work with volvo2mqtt, this can't be fixed by myself. It's a volvo api issue, sorry!

iz3man commented 3 months ago

Thanks for the fast reply. But I don't get it ;) The iphone App work, the car works, all other Volvo cars work, and just the XC40 is not sending some data? Is that what you're saying? That would mean that Volvo got seperate APIs for different makes? If this is the case is there some kind of debugging that can be done from my side? Where would I start. I don't see ANY chance at all that Volvo would change ANYTHING, as their cars are working, and the apps as well.

Dielee commented 3 months ago

The apps are using another API, they are connected via MQTTS, not via REST. My add-on uses the official API. If your car does not work with their REST API, there is nothing I can do for you. You can try to intercept the app traffic.. If this works, I don't know.

iz3man commented 3 months ago

Ok. Maybe you can help my on working with the API then please.

image

Where do I get the access token from? And what for do I need it. I got the API token entered, logged in the Volvo online account, but everytime I want to do a query I get this response:

image

Thank you!

FireWizard52 commented 3 months ago

Hello @iz3man,

You asked:

is this something that the user has to solve?

No, it is the responsibility of the developers to switch to version 2, before API version 1 expires (April 30th 2024). The intention of my post was to issue a warning to Linus, although I had already seen that he was on version 2.

Is only the XC40 Recharge affected by that issue?

No, every Volvo is affected by a change in the API, if they use it. So it is car independent. However the effect may be different from car to car.

Anything we can do?

No, as an end user you can do nothing. Even we, as developers, have no influence on what Volvo makes available i9n their API's and for which car.

But I don't get it ;) The iphone App work, the car works, all other Volvo cars work.

As Linus says the app uses a different API/endpoint and I believe that your Iphone works. My Android phone works too. All other cars work? Yes my car works, but I do not receive data from the Energy API, while a month ago I did. So obviously Volvo changed something. I sent an email, but they have not responded yet. And I do not expect an answer, because these API's are not intended for end users in order to retrieve their own car data.

just the XC40 is not sending some data?

The XC40 is sending data . If you use the old "molobrakos" plugin (for HA). See: https://github.com/molobrakos/volvooncall, you will see, that for your own XC40 PHEV you get:

"hvBattery": { "hvBatteryChargeStatusDerived": "CableNotPluggedInCar", "hvBatteryChargeStatusDerivedTimestamp": "2024-03-15T12:59:11+00:00", "hvBatteryChargeModeStatus": null, "hvBatteryChargeModeStatusTimestamp": null, "hvBatteryChargeStatus": "PlugRemoved", "hvBatteryChargeStatusTimestamp": "2024-03-12T16:33:22+00:00", "hvBatteryLevel": 94, "hvBatteryLevelTimestamp": "2024-03-15T12:59:11+00:00", "distanceToHVBatteryEmpty": 37, "distanceToHVBatteryEmptyTimestamp": "2024-03-15T12:59:11+00:00", "hvBatteryChargeWarning": "UnexpectedPowerloss", "hvBatteryChargeWarningTimestamp": "2024-03-07T12:30:31+00:00", "timeToHVBatteryFullyCharged": 0, "timeToHVBatteryFullyChargedTimestamp": "2024-03-12T15:37:53+00:00" }, Did you try this application? This is the one, I still use in my production system.

That would mean that Volvo got seperate APIs for different makes?

No, this is not the case.

I don't see ANY chance at all that Volvo would change ANYTHING, as their cars are working, and the apps as well.

Yes, they are working on their API's. Soon your phone app will require 2FA. And I expect more changes.

The apps are using another API, they are connected via MQTTS, not via REST.

@Dielee . I did not do any research so far, but if the app uses MQTTS, then there is a broker. Would that be something to look at. (Try to find the IP address?)

You can try to intercept the app traffic.. If this works, I don't know.

I was successful with that with the old Volvo on Call app (See: https://github.com/molobrakos/volvooncall/issues/52) With the latest Volvo Cars app it returned an error and I was not able to capture the data packets.

Where do I get the access token from? And what for do I need it. I got the API token entered, logged in the Volvo online account, but every time I want to do a query I get this response:

As said earlier the Volvo API's are not intended to be used by hobbyists, like you and me. Probably that's why, we do not get an answer on mails and requests for publication. I wish I could a valid key, etc in a legal way/ Volvo want as partner a "legal entity" and unfortunately private persons are not considered as such. So all "open source developers" has to find another route. You can do as well, but remember the Volvo servers are located in Sweden and in Sweden they have already since July 1st. 1973, a law against data trespassing. So breaking into their servers is illegal and may cause trouble.

study their documentation carefully,

Regards

schrej-zz commented 3 months ago

Hi, I think, there's a deviation in the definition of the V2 specification. i the specification, the charge level is sopposed to be sent via https://api.volvocars.com/connected-vehicle/v2/vehicles/{vin}/fuel But if you go to the V2 sandbox, the topic is https://api.volvocars.com/connected-vehicle/v2/vehicles/{vin}/battery-charge-level

FireWizard52 commented 3 months ago

Hello @schrej-zz,

First regarding API versions

For normal users (Non Volvo employees) 4 different API's are available.

  1. Extended API > Still on version v1
  2. Connected API > Version 1 will be deprecated April 30, 2024 and is replaced by version 2
  3. Energy API > Still version 1
  4. Location API > Still version 1

I think we might expect an update of the Location API, if they want to bring the API header in line with the header of the other API's. This was also one of the differences between v1 and v2 of the Connected API.

You said:

I think, there's a deviation in the definition of the V2 specification. i the specification, the charge level is supposed to be sent via https://api.volvocars.com/connected-vehicle/v2/vehicles/{vin}/fuel

This is one of the things that recently changed.

The fuel amount, you could retrieve in the Connected API V1 with the scope: openid and conve:fuel_status and an endpoint fuel, while the Battery Charge Level had the same scope, but as endpoint: battery-charge-level.

But it moved to version v2. In the beginning they did not change the scope, so that you could retrieve both values from the same endpoint: "fuel".

Then suddenly Volvo introduced a new scope for the fuel: openid, conve:fuel_status and conve:battery_charge_level. I mentioned that in an earlier post. So instead of 1 scope and 2 endpoints, they moved to 2 scopes and 1 endpoint in v2.

For more info see: https://developer.volvocars.com/apis/connected-vehicle/v2/release-notes/

So the sandbox is using the old v1 endpoint.

And now our problem: The latest added scope (conve:battery_charge_level) is not in the list of authorized scopes.

Until Volvo is more "open" and "communicative", there is not much developers can do.

Regards

iz3man commented 3 months ago

Thanks @FireWizard52 . I guess I understand it a little better now, and see there's nothing I can do. Unfortunately integrating a PHEV in HomeAssistant w/o knowing the SOC is not possible. So I hope time will bring the solution :) Thanks everyone for contributing - very much appreciated. And offtopic: 2FA for the Volvo app? I hope not - or at least not mandatory. 2FA is a plague of it's own.

FireWizard52 commented 3 months ago

@iz3man

And offtopic: 2FA for the Volvo app? I hope not - or at least not mandatory. 2FA is a plague of it's own.

Yes, I got a message in the app, February 22, announcing that. I expect it is mandatory, but hope you can stay logged in, like now.

FireWizard52 commented 3 months ago

This morning, Monday, March 18, 2024, since 11:00h the "Old"VoC server is not accessible anymore. It returns:

$ voc status Could not connect to the server.

I'm sure that 2FA is the reason. I logged out of my Volvo Cars app and when I tried to log-in again, I had to submit a Volvo ID-verificationcode, consisting of 6 digits. Currently it is impossible to make a connection with the Volvo ID-service.

So this is probably the end of the "old" Volvo integration, unless someone is able to solve this issue. Thanks to all contributors.

Regards

iz3man commented 3 months ago

How can Volvo be so stupid. Why not ask the customer what the want/need. What are API keys for then? How should ANY automation work with mandatory 2FA?? Using 2FA for starting the heating? No way. My wife will hate me that I bought her that car...

FireWizard52 commented 3 months ago

Hello @iz3man,

Do not react so angry. It is quite common today that for security reasons 2FA is used. What would be the security for your bank account or your credit-card account without 2 FA?

Up to now (today) I never logged in with my app. I did it once (or maybe a few times after) and when the app connected, I stayed logged-in. I tested it now, by logging-out and the logging-in again. And now I have to add the Volvo-ID-verification code, which has been sent by email. This means that the "old" (molobrakos) version stopped working. I expect that as soon the Volvo ID-service is up and running you simply log-in again and that it stays logged-in.

It will have consequences for applications that use the same API or an API with the same functionality. But here @Dielee is working on a solution (See #180) for that and other applications will soon follow.

So in the Volvo app it will not have serious consequences, except that you have to submit a code during log-in, but that will last until you log-out again. Other applications will come with a solution.

Regards

iz3man commented 3 months ago

May your words be true :) You know I'm 50+ now, and would call myself a digital native, but for my parents many things are unuseable in the meantime. I get calls from my parents all the time ... ;)

FireWizard52 commented 3 months ago

I hope so, You are 50+, well let me tell you I'am 70+, but working since the seventies of the last century with computers, etc :)

I can image that those older people has problems. It's the same with me. I do not understand my grandson and his games either :)