Python Plugin: Volvo EV

Python and python framework

Moderator: leecollings

User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Volvo EV

Post by FireWizard »

Hello @akamming,

You wrote:
I think Volvo is still working on the API. It seems to be very badly implemented. (it is also very recent that they gave this car API support)
I agree with partly and if you think that they are still working on the API, then it is with an extreme slow speed.
The API itself is working, as far as the functionality is implemented. If it is implemented, then it works.

But the biggest issue is that they are very slow in adding new cars and even older cars.
I own a XC40 PHEV 2023 and until mid February this year the Energy API was supported and then suddenly this car was not supported.
But the "Connected" API and the "Location" API works without any issue, although all my lights indite "Unspecified".
And believe me, the car has lights :D
I already made a workaround for the bad response of the Recharge API (according to the API, this is not an electric car ;-))
I saw it, and even think it is even more strange that that endpoint can respond with "None". Did you ever see a car, that has "None" as fuel?
The unlock gives an internal error on Volvo site. This is not something i can fix, but states something goes wrong on volvo side
That might have been temporary, as I tested it and it did what I expected. The output from the API was according to their docs
I analyze the other log above and it turns out the reply of the diagnostics call is not according to Volvo's own API documentation and also differs from other cars.
It includes
washerFluidLevelWarning
This is undocumented. I do not know which "other" car, you mean? (EX30?)
And
serviceTrigger
is missing. Undocumented as well.
For the climatization i added the unlock duration in the call. I don't think it will solve the issue, cause on my XC40 it works without, but docs now state this is mandatory, so you never no...
Not climatization, but Lock/Unlock
I think you need it, as it is also part of the API response (you get 2 minutes (maximum) to unlock the car).
We should await that volvo fixes these things...
Let's hope, but Volvo is not very quick an the biggest problem is that they do not communicate. :(
So this is probably something that has been worked on recently.
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

FireWizard wrote: Tuesday 17 September 2024 18:43 Hello @akamming,

You wrote:
I think Volvo is still working on the API. It seems to be very badly implemented. (it is also very recent that they gave this car API support)
I agree with partly and if you think that they are still working on the API, then it is with an extreme slow speed.
The API itself is working, as far as the functionality is implemented. If it is implemented, then it works.

But the biggest issue is that they are very slow in adding new cars and even older cars.
I own a XC40 PHEV 2023 and until mid February this year the Energy API was supported and then suddenly this car was not supported.
But the "Connected" API and the "Location" API works without any issue, although all my lights indite "Unspecified".
And believe me, the car has lights :D
I already made a workaround for the bad response of the Recharge API (according to the API, this is not an electric car ;-))
I saw it, and even think it is even more strange that that endpoint can respond with "None". Did you ever see a car, that has "None" as fuel?
The unlock gives an internal error on Volvo site. This is not something i can fix, but states something goes wrong on volvo side
That might have been temporary, as I tested it and it did what I expected. The output from the API was according to their docs
I analyze the other log above and it turns out the reply of the diagnostics call is not according to Volvo's own API documentation and also differs from other cars.
It includes
washerFluidLevelWarning
This is undocumented. I do not know which "other" car, you mean? (EX30?)
And
serviceTrigger
is missing. Undocumented as well.
For the climatization i added the unlock duration in the call. I don't think it will solve the issue, cause on my XC40 it works without, but docs now state this is mandatory, so you never no...
Not climatization, but Lock/Unlock
I think you need it, as it is also part of the API response (you get 2 minutes (maximum) to unlock the car).
We should await that volvo fixes these things...
Let's hope, but Volvo is not very quick an the biggest problem is that they do not communicate. :(
So this is probably something that has been worked on recently.
I meant unlock indeed.

Looking at the diagnostics call I also see i also used undocumented calls. The doc weeks to be for petrol cars. But xc40 and ex30 get different answers…

I curious though, does it work now?

UPDATE: I added 1 more fix, which hopefully also fixes the diagnostics call for the EX30...
rensbr
Posts: 62
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

akamming wrote: Tuesday 17 September 2024 19:57 I curious though, does it work now?

UPDATE: I added 1 more fix, which hopefully also fixes the diagnostics call for the EX30...
Thank you for the support and all the effort you have put into making the plugin compatible with my EX30, I really appreciate it! At first sight the red errors are gone, so thank you for that!!

Unfortunally I'm still getting a error 500 when try to unlock the car or turn on climatization, but probably that has something to do with the Volvo API then in combination with the EX30. But still, I can read out the KM stats and other stuff, which is also great.

So thank you again for the patience and effort!
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

rensbr wrote: Wednesday 18 September 2024 12:12
akamming wrote: Tuesday 17 September 2024 19:57 I curious though, does it work now?

UPDATE: I added 1 more fix, which hopefully also fixes the diagnostics call for the EX30...
Thank you for the support and all the effort you have put into making the plugin compatible with my EX30, I really appreciate it! At first sight the red errors are gone, so thank you for that!!

Unfortunally I'm still getting a error 500 when try to unlock the car or turn on climatization, but probably that has something to do with the Volvo API then in combination with the EX30. But still, I can read out the KM stats and other stuff, which is also great.

So thank you again for the patience and effort!
your're welcome. It's a nice hobby, it's just very frustrating that Volvo isn't more consequent in the API. That makes maintaining the plugin too much work.

anyway nice that it works now.

i have faith this 500 error will be fixed. At first when the XC40 was just added to the supported cars list, it also gave internal 500 errors. In a later phase it started working. It is probably on some backlog of some development team over there to make the functionality work..
rensbr
Posts: 62
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

akamming wrote: Wednesday 18 September 2024 14:53 your're welcome. It's a nice hobby, it's just very frustrating that Volvo isn't more consequent in the API. That makes maintaining the plugin too much work.
anyway nice that it works now.
I can completly understand that it is a frustration business when API and documentation is not up-to-date. (I'm a PLC software developer myself, but with no knowledge of python. :().
i have faith this 500 error will be fixed. At first when the XC40 was just added to the supported cars list, it also gave internal 500 errors. In a later phase it started working. It is probably on some backlog of some development team over there to make the functionality work..
Let's hope so and wait for Volvo to fix this issue. At least the statusses work.
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

rensbr wrote: Wednesday 18 September 2024 15:03
Let's hope so and wait for Volvo to fix this issue. At least the statusses work.
In the meantime: Could you do me a favor and run this python script (ofcourse: pls fill in your VOC username and password in this script) and post the output?:

I'm curious if the API returns the Climatization and (un)lock commands...

Code: Select all

import requests
import json
import datetime

print ("Connecting...")

username = '<VOC UserNAme>'
password = '<VOC Password>'
vccapikey = '<VCC API Key>'

access_token = None
vin = None

def GetAccessToken():
    global access_token

    try:
        response = requests.post(
            "https://volvoid.eu.volvocars.com/as/token.oauth2",
            headers = {
                'authorization': 'Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=',
                'content-type': 'application/x-www-form-urlencoded',
                'user-agent': 'okhttp/4.10.0'
            },
            data = {
                'username': username,
                'password': 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'
            }
        )
        # print(json.dumps(response.json(), indent=4))
        print("Login successful!")
        print(response.json())
    except requests.exceptions.RequestException as error:
        print("Login failed:")
        print(error)

    access_token = response.json()['access_token']
    # print(access_token)

def GetVin():
    global access_token
    global vin

    if access_token:
        try:
            vehicles = requests.get(
                "https://api.volvocars.com/extended-vehicle/v1/vehicles",
                headers= {
                    "accept": "application/json",
                    "vcc-api-key": vccapikey,
                    "Authorization": "Bearer " + access_token
                }
            )
            print("\nResult:")
            print(vehicles)
            vjson=vehicles.json()
            print("Vin = "+str(vjson["vehicles"][0]["id"]))

            vehiclesjson = json.dumps(vehicles.json(), indent=4)
            print("\nResult JSON:")
            print(vehiclesjson)

        except requests.exceptions.RequestException as error:
            print("Get vehicles failed:")
            print(error)

        vin = vjson["vehicles"][0]["id"]
    else:
        print ("NO access token")

def APIcommand(text,url,accept):
    global access_token
    global vin

    if vin:
        try:
            a=datetime.datetime.now()
            print (text)
            print (url)
            status = requests.get(
                url,
                headers= {
                    "accept": accept,
                    "vcc-api-key": vccapikey,
                    "Authorization": "Bearer " + access_token
                }
            )
            b=datetime.datetime.now()


            print("\nResult:")
            print("Execution time: "+str(b-a))
            print(status)
            sjson=status.json()

            sjson = json.dumps(status.json(), indent=4)
            print("\nResult JSON:")
            print(sjson)

        except requests.exceptions.RequestException as error:
            print(text+" failed:")
            print(error)
    else:
        print ("No vin")

GetAccessToken()
GetVin()

APIcommand("commands", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands", "application/json")
#APIcommand("listresources", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources", "application/json")
#APIcommand("sleepCycleStartTime", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources/sleepCycleStartTime", "application/json")
#APIcommand("externalTemp", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources/externalTemp", "application/json")
#APIcommand("RechargeStatus","https://api.volvocars.com/energy/v1/vehicles/"+vin+"/recharge-status", "application/vnd.volvocars.api.energy.vehicledata.v1+json")
#APIcommand("chargingcurrentlimit","https://api.volvocars.com/energy/v1/vehicles/"+vin+"/recharge-status/charging-current-limit", "application/vnd.volvocars.api.energy.chargingcurrentlimitresponse.v1+json")
#APIcommand("Commands", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands", "application/json")
#APIcommand("diagnostics","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/diagnostics","application/json")
#APIcommand("engine", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/engine","application/json")
#APIcommand("engine-status", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/engine" ,"application/json")
#APIcommand("Brakes", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/brakes","application/json")
#APIcommand("Statistics","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/statistics","application/json")
#APIcommand("odometer","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/odometer","application/json")
#APIcommand("tyres","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/tyres","application/json")
#APIcommand("command-accessibilit","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/command-accessibility","application/json")
#APIcommand("vehicle", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin, "application/json")
#APIcommand("warnings", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/warnings", "application/json")
#APIcommand("command accessibility", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/command-accessibility", "application/json")
#APIcommand("climatization start", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands/climatization-start", "application/json")
rensbr
Posts: 62
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

akamming wrote: Wednesday 18 September 2024 21:38
rensbr wrote: Wednesday 18 September 2024 15:03
Let's hope so and wait for Volvo to fix this issue. At least the statusses work.
In the meantime: Could you do me a favor and run this python script (ofcourse: pls fill in your VOC username and password in this script) and post the output?:

I'm curious if the API returns the Climatization and (un)lock commands...

Code: Select all

import requests
import json
import datetime

print ("Connecting...")

username = '<VOC UserNAme>'
password = '<VOC Password>'
vccapikey = '<VCC API Key>'

access_token = None
vin = None

def GetAccessToken():
    global access_token

    try:
        response = requests.post(
            "https://volvoid.eu.volvocars.com/as/token.oauth2",
            headers = {
                'authorization': 'Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=',
                'content-type': 'application/x-www-form-urlencoded',
                'user-agent': 'okhttp/4.10.0'
            },
            data = {
                'username': username,
                'password': 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'
            }
        )
        # print(json.dumps(response.json(), indent=4))
        print("Login successful!")
        print(response.json())
    except requests.exceptions.RequestException as error:
        print("Login failed:")
        print(error)

    access_token = response.json()['access_token']
    # print(access_token)

def GetVin():
    global access_token
    global vin

    if access_token:
        try:
            vehicles = requests.get(
                "https://api.volvocars.com/extended-vehicle/v1/vehicles",
                headers= {
                    "accept": "application/json",
                    "vcc-api-key": vccapikey,
                    "Authorization": "Bearer " + access_token
                }
            )
            print("\nResult:")
            print(vehicles)
            vjson=vehicles.json()
            print("Vin = "+str(vjson["vehicles"][0]["id"]))

            vehiclesjson = json.dumps(vehicles.json(), indent=4)
            print("\nResult JSON:")
            print(vehiclesjson)

        except requests.exceptions.RequestException as error:
            print("Get vehicles failed:")
            print(error)

        vin = vjson["vehicles"][0]["id"]
    else:
        print ("NO access token")

def APIcommand(text,url,accept):
    global access_token
    global vin

    if vin:
        try:
            a=datetime.datetime.now()
            print (text)
            print (url)
            status = requests.get(
                url,
                headers= {
                    "accept": accept,
                    "vcc-api-key": vccapikey,
                    "Authorization": "Bearer " + access_token
                }
            )
            b=datetime.datetime.now()


            print("\nResult:")
            print("Execution time: "+str(b-a))
            print(status)
            sjson=status.json()

            sjson = json.dumps(status.json(), indent=4)
            print("\nResult JSON:")
            print(sjson)

        except requests.exceptions.RequestException as error:
            print(text+" failed:")
            print(error)
    else:
        print ("No vin")

GetAccessToken()
GetVin()

APIcommand("commands", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands", "application/json")
#APIcommand("listresources", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources", "application/json")
#APIcommand("sleepCycleStartTime", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources/sleepCycleStartTime", "application/json")
#APIcommand("externalTemp", "https://api.volvocars.com/extended-vehicle/v1/vehicles/"+vin+"/resources/externalTemp", "application/json")
#APIcommand("RechargeStatus","https://api.volvocars.com/energy/v1/vehicles/"+vin+"/recharge-status", "application/vnd.volvocars.api.energy.vehicledata.v1+json")
#APIcommand("chargingcurrentlimit","https://api.volvocars.com/energy/v1/vehicles/"+vin+"/recharge-status/charging-current-limit", "application/vnd.volvocars.api.energy.chargingcurrentlimitresponse.v1+json")
#APIcommand("Commands", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands", "application/json")
#APIcommand("diagnostics","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/diagnostics","application/json")
#APIcommand("engine", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/engine","application/json")
#APIcommand("engine-status", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/engine" ,"application/json")
#APIcommand("Brakes", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/brakes","application/json")
#APIcommand("Statistics","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/statistics","application/json")
#APIcommand("odometer","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/odometer","application/json")
#APIcommand("tyres","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/tyres","application/json")
#APIcommand("command-accessibilit","https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/command-accessibility","application/json")
#APIcommand("vehicle", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin, "application/json")
#APIcommand("warnings", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/warnings", "application/json")
#APIcommand("command accessibility", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/command-accessibility", "application/json")
#APIcommand("climatization start", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands/climatization-start", "application/json")
Thanks!!

Is this the respons you are looking for?

Code: Select all

C:\Users\user\Downloads>python PythonScipt.py
Connecting...
Login successful!
{'access_token': 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjFaNkpvZUo1ZEZYTzltTHJwX1FmNWk1UWtZUV9SUzI1NiIsInBpLmF0bSI6InMifQ.eyJzY29wZSI6Im9wZW5pZCBlbWFpbCBwcm9maWxlIGNhcmVfYnlfdm9sdm86ZmluYW5jaWFsX2luZm9ybWF0aW9uOmludm9pY2U6cmVhZCBjYXJlX2J5X3ZvbHZvOmZpbmFuY2lhbF9pbmZvcm1hdGlvbjpwYXltZW50X21ldGhvZCBjYXJlX2J5X3ZvbHZvOnN1YnNjcmlwdGlvbjpyZWFkIGN1c3RvbWVyOmF0dHJpYnV0ZXMgY3VzdG9tZXI6YXR0cmlidXRlczp3cml0ZSBvcmRlcjphdHRyaWJ1dGVzIHZlaGljbGU6YXR0cmlidXRlcyB0c3BfY3VzdG9tZXJfYXBpOmFsbCBjb252ZTpicmFrZV9zdGF0dXMgY29udmU6Y2xpbWF0aXphdGlvbl9zdGFydF9zdG9wIGNvbnZlOmNvbW1hbmRfYWNjZXNzaWJpbGl0eSBjb252ZTpjb21tYW5kcyBjb252ZTpkaWFnbm9zdGljc19lbmdpbmVfc3RhdHVzIGNvbnZlOmRpYWdub3N0aWNzX3dvcmtzaG9wIGNvbnZlOmRvb3JzX3N0YXR1cyBjb252ZTplbmdpbmVfc3RhdHVzIGNvbnZlOmVudmlyb25tZW50IGNvbnZlOmZ1ZWxfc3RhdHVzIGNvbnZlOmhvbmtfZmxhc2ggY29udmU6bG9jayBjb252ZTpsb2NrX3N0YXR1cyBjb252ZTpuYXZpZ2F0aW9uIGNvbnZlOm9kb21ldGVyX3N0YXR1cyBjb252ZTp0cmlwX3N0YXRpc3RpY3MgY29udmU6dHlyZV9zdGF0dXMgY29udmU6dW5sb2NrIGNvbnZlOnZlaGljbGVfcmVsYXRpb24gY29udmU6d2FybmluZ3MgY29udmU6d2luZG93c19zdGF0dXMgZW5lcmd5OmJhdHRlcnlfY2hhcmdlX2xldmVsIGVuZXJneTpjaGFyZ2luZ19jb25uZWN0aW9uX3N0YXR1cyBlbmVyZ3k6Y2hhcmdpbmdfc3lzdGVtX3N0YXR1cyBlbmVyZ3k6ZWxlY3RyaWNfcmFuZ2UgZW5lcmd5OmVzdGltYXRlZF9jaGFyZ2luZ190aW1lIGVuZXJneTpyZWNoYXJnZV9zdGF0dXMiLCJjbGllbnRfaWQiOiJoNFlmMGIiLCJncm50aWQiOiIzSG95bEowZnp1MVRkdEswbUNHemZjRDNybkt3bUJPbiIsImlzcyI6Imh0dHBzOi8vdm9sdm9pZC5ldS52b2x2b2NhcnMuY29tIiwiYXVkIjoiaDRZZjBiIiwibWFya2V0IjoiTkwiLCJhY3IiOiJ1cm46dm9sdm9pZDphYWw6YnJvbnplOmFueSIsImZpcnN0TmFtZSI6IlJlbnMiLCJsYXN0TmFtZSI6IkJydWdtYW5zIiwic3ViIjoiMzVjMTA4NjktNzNhMS00Y2ZjLWFhOTUtYjRhNDRhMmRjNjc3IiwiZW1haWwiOiJyLmJydWdtYW5zQG1hLWl0Lm5sIiwiZXhwIjoxNzI2NzI5NTAyfQ.O8UrwMki6shFuYijVjiVWZE9I6aPnFgSvb-evpk_9NbYsj9sCxqL8e4GXmnvHqOc4kSiuZI1Avldn_3xqZi_R9_BzgAbNnIRiIS4fsq8Zvh2rQiYGOgbqOsVwBxDlBPxAYF3WrOSDMwU4mh59IUgxYum4hzf82Jg9uza39kGof4Oasp1qYmQb-7KkZ2RFU5ZJgbWeStIu8_J3ms1ru2m2Yh9GkvhKGkyT4tt9bA67GVJgIYHyq355Rze-6rkVeJL28DxVwZG9wWYgUITkpffqGrLN3rfdXdWenw2OcaTZTziFA4tmCT9jcS5X8KTf0Zf-Delh3gt0Eb6WP06A5LCOA', 'refresh_token': 'UYkHW3agSP0xeNcbXZzKhhf7cqmwlZBdjT0.JodVYH', 'token_type': 'Bearer', 'expires_in': 1799}

Result:
<Response [200]>
Vin = VIN

Result JSON:
{
    "vehicles": [
        {
            "id": "VIN"
        }
    ]
}
commands
https://api.volvocars.com/connected-vehicle/v2/vehicles/VIN/commands

Result:
Execution time: 0:00:00.390398
<Response [200]>

Result JSON:
{
    "data": [
        {
            "command": "LOCK",
            "href": "/v2/vehicles/VIN/commands/lock"
        },
        {
            "command": "UNLOCK",
            "href": "/v2/vehicles/VIN/commands/unlock"
        },
        {
            "command": "CLIMATIZATION_START",
            "href": "/v2/vehicles/VIN/commands/climatization-start"
        },
        {
            "command": "CLIMATIZATION_STOP",
            "href": "/v2/vehicles/VIN/commands/climatization-stop"
        }
    ]
}
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

tx for running the script.

Unfortunately it didn't give the answer i hoped. It reports the the climatization and (un)lock commands are there...

I hoped it wasn't, so i could make generic code to only create the climatization and (un)lock buttons when the cars support it. This way only supported functions would be shown to the end user.

So only thing left for EX30 users is to wait for volvo to fix these commands...

you could try contacting Volvo via their developer portal (although they never send me back an email when i tried to contact them...)
rensbr
Posts: 62
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

akamming wrote: Thursday 19 September 2024 20:36 tx for running the script.

Unfortunately it didn't give the answer i hoped. It reports the the climatization and (un)lock commands are there...
I now have tested the command's on the Volvo API website and I'm getting also there the error 500 back.

I also have added a function to your script, so I can also test the Post requests easly:

Code: Select all

def APIcommandPost(text,url,accept,type):
    global access_token
    global vin

    if vin:
        try:
            a=datetime.datetime.now()
            print (text)
            print (url)
            status = requests.post(
                url,
                headers= {
                    "accept": accept,
                    "vcc-api-key": vccapikey,
                    "Authorization": "Bearer " + access_token,
                    "Content-Type": type
                }
            )
            b=datetime.datetime.now()


            print("\nResult:")
            print("Execution time: "+str(b-a))
            print(status)
            sjson=status.json()

            sjson = json.dumps(status.json(), indent=4)
            print("\nResult JSON:")
            print(sjson)

        except requests.exceptions.RequestException as error:
            print(text+" failed:")
            print(error)
    else:
        print ("No vin")

APIcommandPost("climatization start", "https://api.volvocars.com/connected-vehicle/v2/vehicles/"+vin+"/commands/climatization-start", "application/json", "application/json")
And when I'm try that, I also getting an Error 500, see below. So clearly something is wrong on the Volvo side.

Code: Select all

climatization start
https://api.volvocars.com/connected-vehicle/v2/vehicles/VIN/commands/climatization-start

Result:
Execution time: 0:00:00.501118
<Response [500]>

Result JSON:
{
    "error": {
        "message": "INTERNAL_SERVER_ERROR",
        "description": "Internal Server Error"
    }
}
you could try contacting Volvo via their developer portal (although they never send me back an email when i tried to contact them...)
Since every (post) function we try returns an error 500, it looks liket that someting is clearly wrong on the Volvo side, so I can report that to them.
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Volvo EV

Post by FireWizard »

Hello @akamming,

I follow your post (and also other posts, regarding Volvo), although I do not use your plugin, but Node-RED (as I use this for a long time)

I noticed this at the HA plug-in github page.
See: https://github.com/Dielee/volvo2mqtt/issues/237
They released a fix today.

So obviously there are changes in the naming for the EX30
I do not notice this for my XC40. This is as it was, but perhaps this caused an issue in your plug-in as well.


Regards
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: Volvo EV

Post by waltervl »

Hmm, it seems that this volvo2mqtt application also uses Mqtt AutoDiscover so could be used in Domoticz without python plugin or node-red.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1771
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Volvo EV

Post by FireWizard »

Hi @waltervl,

I think, you are right, but this is also a python application.
One thing, I do not like, is that Linus Dietz (dielee) has introduced 2FA, similar to the log-in procedure for the Volvo app. Unnessary i.m.o.

And using Node-RED gives you control over your own application.

There is a thread, where @kiddigital made a native Domoticz application, but due to legal authorization issues, it was never published.

Regards
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

waltervl wrote: Friday 20 September 2024 18:41 Hmm, it seems that this volvo2mqtt application also uses Mqtt AutoDiscover so could be used in Domoticz without python plugin or node-red.
Both have their pro’s and cons: I think python plug-in is the way. Cause for volvo2mqtt you need to setup Mqtt with autodiscovery and a docker container.
But ofcourse of you already that for other integrations that might be the easiest way.

I stay away as long as possible from 2fa, cause it Will cause several kind of issues… but i am afraid Volvo Will enforce it in the near future…
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

FireWizard wrote: Friday 20 September 2024 16:49 Hello @akamming,

I follow your post (and also other posts, regarding Volvo), although I do not use your plugin, but Node-RED (as I use this for a long time)

I noticed this at the HA plug-in github page.
See: https://github.com/Dielee/volvo2mqtt/issues/237
They released a fix today.

So obviously there are changes in the naming for the EX30
I do not notice this for my XC40. This is as it was, but perhaps this caused an issue in your plug-in as well.


Regards
I am not using that api call where the Change are. But again it is weird that for different cars there are charges in the naming, just like in the diagnostics call. Makes maintaininng an api integration a lot of work
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

FireWizard wrote: Friday 20 September 2024 19:04 Hi @waltervl,

I think, you are right, but this is also a python application.
One thing, I do not like, is that Linus Dietz (dielee) has introduced 2FA, similar to the log-in procedure for the Volvo app. Unnessary i.m.o.

And using Node-RED gives you control over your own application.

There is a thread, where @kiddigital made a native Domoticz application, but due to legal authorization issues, it was never published.

Regards
i just added 2FA to the domoticz plugin as well. it's experimental. Just run "python authorize.py" in the volvo plugin directory and it will confirm your identity using 2FA and then retrieve the token and store in it an ini file in that dir. After that the plugin will use that token.

I agree it's less user friendly than without 2FA, so i left the normal functionality without intact. But i think in the near future Volvo will enforce 2FA.. so then i'm prepared :D
HvdW
Posts: 539
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

Question.
I deleted a few sensors and now I get this.

Code: Select all

2024-09-30 18:09:10.141 Volvo: KWH Meter (Volvo-chargedTotal)
2024-09-30 18:09:10.149 Volvo: KWH Meter (Volvo-usedKWH)
2024-09-30 18:09:10.149 Error: Volvo: (Volvo) Unit creation failed, Hardware/DeviceID/Unit combination (16/YV1XZEHR4R2282899/64) already exists in Domoticz.
2024-09-30 18:09:10.149 Volvo: ERROR: Unable to update KWH device (chargedAtHome), is the "accept new devices" toggle switched on in your config?
2024-09-30 18:09:10.157 Volvo: KWH Meter (Volvo-chargedPublic)
2024-09-30 18:09:10.165 Volvo: KWH Meter (Volvo-chargedPublicAC)
2024-09-30 18:09:10.173 Volvo: KWH Meter (Volvo-chargedPublicDC)
What should I do?
Bugs bug me.
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: Volvo EV

Post by waltervl »

Normally when removing a device controlled by a plugin you should restart the plugin (or Domoticz) to get a new similar device back.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
akamming
Posts: 344
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

waltervl wrote: Monday 30 September 2024 19:11 Normally when removing a device controlled by a plugin you should restart the plugin (or Domoticz) to get a new similar device back.
Indeed a restart might help. If the issue persists, you can switch on debugging and look for clues in the logging...

If i delete any device it is recreated again right away. does domoticz allow for creation f new devices?
HvdW
Posts: 539
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

Thanks for the replies.
The same day it persisted despite some reboots and the next day it was gone.
Bugs bug me.
rensbr
Posts: 62
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

rensbr wrote: Friday 20 September 2024 13:22 Since every (post) function we try returns an error 500, it looks liket that someting is clearly wrong on the Volvo side, so I can report that to them.
To quote myself, It looks like Volvo has changed something at their side, because locking/unlocking the car seems to work now.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests