Volvo on call support for new API released for Google Automotive

Hi

Looks like Volvo released support for a new API, possibel to add this to current integration?

from the site:

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.

/karl

Looks interesting, someone with coding skills should really take a look at this, as the new cars done support / does not show up in the current volvo-on-call integration

1 Like

I’ve played around with the new API and added a sensor to HA in configuration.yaml. I got a Volvo XC60 2022 with Google and I’ve been waiting for this “update” for over a year :-).

First some REST stuff:

  - platform: rest
    scan_interval: 600
    name: Volvo Recharge Status
    resource: https://api.volvocars.com/energy/v1/vehicles/YOUR_WIN/recharge-status/battery-charge-level?vcc-api-key=SECRET_API_KEY
    json_attributes_path: $.data.batteryChargeLevel
    json_attributes:
      - value
      - timestamp
    headers:
      Authorization: Bearer YOUR_ENERGY_API_ACCESS_TOKEN
      accept: application/vnd.volvocars.api.energy.vehicledata.v1+json
  - platform: template
    sensors:
      volvo_recharge_status_value:
        value_template: >
          {{ state_attr('sensor.volvo_recharge_status', 'value') | round(1) | replace('.', ',') }}

However the Energy API access token expires after an hour… so we need to implement the OAuth2 flow.

I’m sure it’ll be easier if the creator of Volvo On Call integration just fixes this. Should be a breeze :slight_smile:

2 Likes

what an API…battery level. And that’s it.

I have a B4 model, and I’m seeking for an integration that will allow me to heat my car, lock it, open it, geolocalize it… this seems to be a no go…

All of these features were possible before Volvo switched to Google automotive. what a regression.

Their integrated OS is SO BAD I had to buy an iphone and use carplay instead of it. Shame on you Volvo.

1 Like

Locking/opening/heating is possible in the Volvo app (which sucks). But there’s no HA integration.

Yes I know that. But you can’t trigger heating on an event, not even plan it to start each day at a specific hour before you leave.

You can’t geolocalise your car anymore since Google automotive models are there.

You actually can’t do anything nice. I agree, these new Volvo’s are a mess.

Engine wise, they are great, but the running automotive OS ruins my personal experience.

I’m hoping they’re just prioritizing dev work after an upgrade. I’ve subscribed to their developer mailing list to see if they add features.

Since Volvo ownership moved to the far-east?

I mean… Volvo was bought by Geely before On-call was actually released, so seems a little hard to blame the change for it getting worse

I worked on this one today since I just received my new 2023 XC40 recharge. With the help of some other implementations (iotbroker), I was able to set up the password grant_type which is somehow not documented, maybe the guys over there did some reverse engineering of the Volvo Cars app or something.

That means I am now able to properly list the information of my car (Connected Vehicle API and Energy API) and expose this stuff to HA without the need to set up the authorization_code flow and therefore a published Volvo app with proper redirect URLs.

Since this a pretty hacky solution I believe the guys at HA won’t allow this as a “proper” integration, so I will invest some time and provide some sort of custom integration for the ones that are interested in it here. But it will surely take me some time to prepare everything, my current test code is written in node_red which is not ideal for simple usage :wink:

Since the APIs are currently only available in Europe / Middle East / Africa this will most likely not work for our American / Asian friends, I am not sure though since the docs only mention “published” applications, which is not a requirement in this case.

5 Likes

I just realized that a proper implementation using the flow suggested by Volvo should be possible with the My Home Assistant mechanic.

Unfortunately, I am not able to test it until Volvo accepted and published my application. Using the code flow is only possible once your app is reviewed and published, but it is not possible to test it the intended way until Volvo reviewed and published it, which seems really stupid…

Anyways, I will keep you posted once I got an update from the Volvo dev team.

1 Like

Do you want to share your node red flow? I just want to get the SOC.

This won’t work since a lot of custom nodes stuff is going on and it is somewhat broken anyways, but I can provide you my TS example that I used to verify if my setup is working.

Maybe this will help you as well :slight_smile:

I know it is ugly, but it might point you in a working direction as long as I have no feedback from Volvo.

import axios from 'axios';
import qs from 'qs';

export class VolvoApi {
  constructor(private _apiKey: string, private _user: string, private _password: string) {}
  public async getToken(): Promise<string> {
    const response = await axios.post(
      'https://volvoid.eu.volvocars.com/as/token.oauth2',
      qs.stringify({
        username: this._user,
        password: this._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',
      }),
      {
        headers: {
          authorization: 'Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=',
          'content-type': 'application/x-www-form-urlencoded',
          'user-agent': 'okhttp/4.10.0',
        },
      },
    );
    return response.data.access_token;
  }

  public async getVINs(): Promise<string[]> {
    const token = await this.getToken();
    const result = await axios.get('https://api.volvocars.com/connected-vehicle/v1/vehicles', {
      headers: {
        accept: 'application/vnd.volvocars.api.connected-vehicle.vehiclelist.v1+json',
        Authorization: `Bearer ${token}`,
        'vcc-api-key': this._apiKey,
      },
    });
    return result.data.data.map((o: { vin: string }) => o.vin);
  }

  public async getBatteryChargeLevel(vin: string): Promise<{ value: string; unit: string; timestamp: string }> {
    const token = await this.getToken();
    const result = await axios.get(`https://api.volvocars.com/energy/v1/vehicles/${vin}/recharge-status/battery-charge-level`, {
      headers: {
        accept: 'application/vnd.volvocars.api.energy.vehicledata.v1+json',
        Authorization: `Bearer ${token}`,
        'vcc-api-key': this._apiKey,
      },
    });
    return result.data.data.batteryChargeLevel;
  }
}

This works perfectly in Insomnia/Postman … thank you!

Question is who’s credentials/app is it using? JWTh4Yf0b - where does it come from or was it sniffed from some other app?

i have instald https://www.iobroker.net/ in a docker,
after that run: GitHub - TA2k/ioBroker.volvo: Volvo On Call Adapter for ioBroker
in Iobroker are now a lot of sensors, iobroker send them to MQTT.
in Homeassistant a read the mqtt tho show below information.
i can now only read the information not yet start the preheat as example.

2023-02-27 16_23_41-Dashboard – Home Assistant

@selstam I have absolutely no idea, that is why I described it as “hacky”… I got this part from the iobroker implementation. Since the current Vovlo Cars App is still using the password-flow, I guess to maintain compatibility with “older” cars, someone might have just sniffed this one from the Volvo App or something. Did not verify that though…

1 Like

Sounds plausible.

Anyway, I’ll be coding a .net bridge for the API calls and assemble it in a REST-based sensor in HASS. Hacky as you say, yes! :slight_smile: The bridge will refresh the access token periodically so as long as the application is available it should work - at least until someone gets a complete flow working.

Yeah, the climatization stuff seems quite unpredictable at the moment somehow. I am sometimes able to start it via curl (with some weird errors popping up in the app afterward), but never with my axios implementation - maybe there are some differences in handling empty POST bodies.

But it is not reliable in general, since the API will be changed in an upcoming release, whenever this may be, Volvo may have realized that the implementation is kinda buggy…

Steven, which country are you from please? When I fire up ioBroker and successfully log on to the Volvo service, it states that I have 0 vehicles. I’m in Australia so my assumption is that this is an API call and we are still region blocked.

hey i am from the netherlands and is working fine here