Dielee / volvo2mqtt

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

Climate / Engine remote start #118

Closed ChristianNiklasson closed 6 months ago

ChristianNiklasson commented 8 months ago

Would it be possible to have two climate activate options? As it works now as far as I can see is that the climate activation does so with the ”leave in 30 min” option ending up with no engine start.

if it is possible i would also like to have a “leave in 15 min” option that would also start the engine.

Dielee commented 8 months ago

I don't know what you want, sorry. If you activate the climate, it will start immediately, until the engine starts, or for 30 minutes.

ChristianNiklasson commented 8 months ago

If you in the Volvo app start the climate with a 15 minute delay or less the engine will start.

If you start the climate with a 20 minute or more delay only the heater will start.

So, the effect will also be that if only the heater is started the heated steering wheel will not activate as well as other electric heated functions such as mirrors and so on.

Therefore if it would be possible to also send the "minutes to leave" information that i assume is sent by the native app with the command to start the climate it would automatically force an engine start (if set to 15min or less)

Dielee commented 8 months ago

Ah okay, this is a feature I wasn't aware of. I can't find any API endpoint to support the feature in the HA Add-on, sorry. Feel free to search on your own!

ChristianNiklasson commented 8 months ago

There is apparently a direct command to start the engine

image

Documentation found here:

https://developer.volvocars.com/apis/connected-vehicle/v1/specification/

Dielee commented 8 months ago

Yes, I know, but without any timer function. This is On/Off.

ChristianNiklasson commented 8 months ago

Understand, but i took a look in the Volvo app and there aren't some many time options.

So a engine start option would probably be a 15 minute timer and heater start would then be a 30 min timer.

So just to have the engine start option in the integration would solve the issue the way i was looking for from the start.

Dielee commented 8 months ago

As I can't test the engine start endpoint, are you able to test some dev releases ?

ChristianNiklasson commented 8 months ago

Sure, might need some guidance for the installation though 🙃

Dielee commented 8 months ago

Are you using the HA Add-on?

ChristianNiklasson commented 8 months ago

Yep 👍🏻

Dielee commented 7 months ago

Are you able to start your engine via the volvo devloper portal ?

Mine isn't starting:

{
    "error": {
        "message": "FORBIDDEN",
        "description": "Access is denied"
    }
}
Rustymage commented 7 months ago

The developer portal apparently has runtime minutes if that's of use here?

curl -X 'POST' \
  'https://api.volvocars.com/connected-vehicle/v1/vehicles/TESTVIN/commands/engine-start' \
  -H 'accept: application/vnd.volvocars.api.connected-vehicle.commandinvokeresponse.v1+json' \
  -H 'Content-Type: application/vnd.volvocars.api.connected-vehicle.enginestart.v1+json' \
  -d '{
  "runtimeMinutes": 10
}'
Dielee commented 7 months ago

The engine start uses runtime in minutes, the climate not.

ChristianNiklasson commented 7 months ago

Ah, yes and the max would be 15 minutes then

ChristianNiklasson commented 7 months ago

Are you able to start your engine via the volvo devloper portal ?

Mine isn't starting:


{

    "error": {

        "message": "FORBIDDEN",

        "description": "Access is denied"

    }

}

I received Error 500 internal Server error

Dielee commented 7 months ago

Great... This API is real garbage at this time!

Dielee commented 7 months ago

If this won't work, I can't implement the engine start, sorry.

ChristianNiklasson commented 7 months ago

So i was able to start the engine via the Volvo Dev site.

It needed both the VIN and authentication with a token from my Volvo ID and the API Key.

So at least it works there both the engine start and the engine stop command worked fine

Rustymage commented 7 months ago

I just checked and using the engine start stop end points, it works for me too.

image
Dielee commented 7 months ago

Nice, I will implement it if I have some spare time.

Dielee commented 7 months ago

Are your Cars phevs or mild hybrids ? Or even bevs are working?

ChristianNiklasson commented 7 months ago

Mine is Mild-hybrid

Rustymage commented 7 months ago

Are your Cars phevs or mild hybrids ? Or even bevs are working?

Mild hybrid. B5.

Dielee commented 7 months ago

So please send me your response from this endpoint:

https://api.volvocars.com/connected-vehicle/v2/vehicles/<YOUR VIN>/commands

Rustymage commented 7 months ago
{
  "data": [
    {
      "command": "LOCK_REDUCED_GUARD",
      "href": "/v2/vehicles/VIN/commands/lock-reduced-guard"
    },
    {
      "command": "LOCK",
      "href": "/v2/vehicles/VIN/commands/lock"
    },
    {
      "command": "UNLOCK",
      "href": "/v2/vehicles/VIN/commands/unlock"
    },
    {
      "command": "ENGINE_START",
      "href": "/v2/vehicles/VIN/commands/engine-start"
    },
    {
      "command": "ENGINE_STOP",
      "href": "/v2/vehicles/VIN/commands/engine-stop"
    }
  ]
}
Dielee commented 7 months ago
{
  "data": [
    {
      "command": "LOCK_REDUCED_GUARD",
      "href": "/v2/vehicles/VIN/commands/lock-reduced-guard"
    },
    {
      "command": "LOCK",
      "href": "/v2/vehicles/VIN/commands/lock"
    },
    {
      "command": "UNLOCK",
      "href": "/v2/vehicles/VIN/commands/unlock"
    },
    {
      "command": "ENGINE_START",
      "href": "/v2/vehicles/VIN/commands/engine-start"
    },
    {
      "command": "ENGINE_STOP",
      "href": "/v2/vehicles/VIN/commands/engine-stop"
    }
  ]
}

Climate isn't supported by your car, interesting. Can you confirm this ?

There is a new feature container available. Please test the engine start feature: ghcr.io/dielee/volvo2mqtt:engine_start_feature

There will be two new entities:

  1. Engine Runtime number
  2. Engine State switch
Rustymage commented 7 months ago

I have climate, see photo.

image

I don't have a start/stop option in the app, however the developer portal climate API doesn't work, yet start/stop does...

Will try the feature when I'm home.

Thank you!

Dielee commented 7 months ago

The climate api doesn't work, this is what I wanted to know. If you delete the mqtt device in HA and run the new 1.9.0, the climate entity will not even appear anymore, as it isn't supported by your car.

Dielee commented 7 months ago

If you start the climate with "Leave in" minutes, the motor starts immediately?

Rustymage commented 7 months ago

If you start the climate with "Leave in" minutes, the motor starts immediately?

In the Volvo app, yes. The hazards flash and car starts. It stays locked and needs the key and a twist of the internal 'start/stop dial' to fully unlock and allow driving.

Dielee commented 7 months ago

Alright, than the changes should do what you want! But I can't test it, as my BEV doesn't support engine start. So if something is not working, please provide debug logs.

ChristianNiklasson commented 7 months ago

Could you guide me on how to install the package?

Dielee commented 7 months ago

If you are using the HA Addon, there is no way. You have to install dev containers via docker.

ChristianNiklasson commented 7 months ago

Noted, so i will just wait for the next uppdate then?

Dielee commented 7 months ago

I need some testers... If nobody can test this, I will not merge this into main...

Rustymage commented 7 months ago

I need some testers... If nobody can test this, I will not merge this into main...

I'll take a look when I'm home and get back to you.

ChristianNiklasson commented 7 months ago

I have climate, see photo.

image

I don't have a start/stop option in the app, however the developer portal climate API doesn't work, yet start/stop does...

Will try the feature when I'm home.

Thank you!

I would say that you dont have the extra fuel warmer on your car, thats why you cant choose more than 15 minutes, in my example i have the diesel warmer that i can use instead of turning the car on. So the effect will be that the "start climate" will start the dieselwarmer for a 30 min runtime.

So: 1-15 minutes leave time will start the engine. (/vehicles/{vin}/commands/engine-start) 30 minutes will start the climate (fuel/diesel warmer)

Rustymage commented 7 months ago

I'd hope mine didn't have a diesel warmer as it's a petrol ;)

Rustymage commented 7 months ago

Here's the log:

Nov 22 19:13:40 volvo2mqtt [1] - INFO: Starting volvo2mqtt version v1.9.0
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Using VCCAPIKEY: KEY
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Vin: ['VIN'] found!
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Battery Charge Level (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Battery Charge Level (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Electric Range (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Estimated Charging Time (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Charging System Status (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Charging Connection Status (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Estimated Charging Finish Time (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Odometer (sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Last Data Update (sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Active schedules (sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Window Front Left (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Window Front Right (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Window Rear Left (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Window Rear Right (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Door Front Left (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Door Front Right (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Door Rear Left (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Door Rear Right (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Tailgate (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Engine Hood (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Tank Lid (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Sunroof (binary_sensor) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Failed, Air Conditioning (switch) is unfortunately not supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Engine State (switch) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Leave in (number) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Lock state (lock) is supported by your vehicle.
Nov 22 19:13:40 volvo2mqtt [1] - INFO: Success! Force Update Data (button) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Location (device_tracker) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Tire Front Left (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Tire Front Right (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Tire Rear Left (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Tire Rear Right (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Fuel Level (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Average Fuel Consumption (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Failed, Average Energy Consumption (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Distance to Empty Tank (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Failed, Distance to Empty Battery (sensor) is unfortunately not supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Average Speed (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Hours to Service (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Distance to Service (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Time to Service (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Service warning status (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! Washer Fluid Level warning (sensor) is supported by your vehicle.
Nov 22 19:13:41 volvo2mqtt [1] - INFO: Success! API Backend status (sensor) is supported by your vehicle.
Nov 22 19:13:43 volvo2mqtt [1] - INFO: Sending mqtt update...
Nov 22 19:13:44 volvo2mqtt [1] - INFO: Mqtt update done. Next run in 300 seconds.
Nov 22 19:13:51 volvo2mqtt [1] - ERROR: API Call failed. Status Code: 403. Error: {
  "error" : {
    "message" : "FORBIDDEN",
    "description" : "Access is denied"
  }
}
image image
Dielee commented 7 months ago

Okay, we have some API issues. The 403 is the start engine switch ?

Rustymage commented 7 months ago

Enabling CONF_debug doesn't get me further detail..?

The below just repeats and toggling state doesn't change the output - happy to do something different if asked.

Nov 22 19:22:46 volvo2mqtt [1] - DEBUG: Starting GET call against https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics
Nov 22 19:22:46 volvo2mqtt [1] - DEBUG: Response status code: 200
Nov 22 19:22:46 volvo2mqtt [1] - DEBUG: {

  "data" : {
    "serviceWarning" : {
      "value" : "NO_WARNING",
      "timestamp" : "2023-11-22T16:29:59.366Z"
    },
    "engineHoursToService" : {
      "value" : 598,
      "unit" : "h",
      "timestamp" : "2023-11-22T16:29:59.366Z"
    },
    "distanceToService" : {
      "value" : 42476,
      "unit" : "km",
      "timestamp" : "2023-11-22T16:29:59.366Z"
    },
    "washerFluidLevelWarning" : {
      "value" : "NO_WARNING",
      "timestamp" : "2023-11-22T16:29:59.366Z"
    },
    "timeToService" : {
      "value" : 10,
      "unit" : "months",
      "timestamp" : "2023-11-22T16:29:59.366Z"
    }
  }
}
Rustymage commented 7 months ago

Okay, we have some API issues. The 403 is the start engine switch ?

The 403 is a direct response to switching on the state switch.

Dielee commented 7 months ago

Aaah, I have a idea, please wait a few minutes.

Dielee commented 7 months ago

The conve:engine_start_stop scope is missing from the authentication. Unfortunately the authorization against the used endpoint, is returning an error, if this scope is posted. For now, there is no soloution. I will take a look tomorrow.

Rustymage commented 7 months ago

conve:engine_start_stop

I'm not following on whether I can assist in posting the scope or how?

What's conve:engine_start_stop?

Dielee commented 7 months ago

API authentication stuff.. There is nothing you can do at this time, thanks!

ChristianNiklasson commented 7 months ago

You have noted that the API needs an access token from your Volvo ID aswell as the VIN and ofcourse the API key? Seen as the second authorisation below

image

The auth. key for the Volvo ID should be found here: https://volvoid.eu.volvocars.com/VolvoLogin/login?resumePath=j6dPwGVjUq&client_id=developervcarsdotcom

image

I might just be stupid but still wanted to point it out, this was the authorization i missed when i first tried the command on the Volvo Dev. site.

Dielee commented 7 months ago

Yes Sure, I know the API very good at this time. The authorization is missing the conve:engine_start_stop scope. I will try my best.

Dielee commented 7 months ago

It looks like the needed scope conve:engine_start_stop to start and stop the engine isn't working with the used authentication method. I started an app publication at Volvo. Hopefully, they will review my app. If my app is reviewed and published, I have to implement an oauth2 auth flow. If there is something new, I will keep you updated.

Dielee commented 7 months ago

UPDATE: I deep dived into the app authentication. There is something new, which I would be able to implement, but this wouldn't fix the access to the "Engine Start" Resource.