audiconnect / audi_connect_ha

Adds an audi connect integration to home assistant
MIT License
226 stars 98 forks source link

Start/Stop/Timed Charging Not Working #227

Open devslash0 opened 7 months ago

devslash0 commented 7 months ago

Anyone got start_charger and stop_charger to work?

I can lock and unlock, but when i try to setup smart charging with home assistant i get:

2024-02-17 18:38:05.713 ERROR (MainThread) [custom_components.audiconnect.util] Unable to stop charger of vehicle XXX: Cannot stop charger, return code 'failed'

Running:

service: audiconnect.execute_vehicle_action data: vin: XXX action: 'stop_charger'

XXX is my VIN.

cdnninja commented 6 months ago

Try latest.

devslash0 commented 6 months ago

Same, but new error message:

2024-03-05 17:32:48.897 ERROR (MainThread) [custom_components.audiconnect.util] Unable to start charger of vehicle XXX: 403, message='', url=URL('https://msg.volkswagen.de/fs-car/bs/batterycharge/v1/Audi/DE/vehicles/XXX/charger/actions') 2024-03-05 17:33:00.451 ERROR (MainThread) [custom_components.audiconnect.util] Unable to start charger of vehicle XXX: 403, message='', url=URL('https://msg.volkswagen.de/fs-car/bs/batterycharge/v1/Audi/DE/vehicles/XXX/charger/actions') 2024-03-05 17:33:20.668 ERROR (MainThread) [custom_components.audiconnect.util] Unable to stop charger of vehicle XXX: 403, message='', url=URL('https://msg.volkswagen.de/fs-car/bs/batterycharge/v1/Audi/DE/vehicles/XXX/charger/actions') 2024-03-05 17:33:29.862 ERROR (MainThread) [custom_components.audiconnect.util] Unable to start charger of vehicle XXX: 403, message='', url=URL('https://msg.volkswagen.de/fs-car/bs/batterycharge/v1/Audi/DE/vehicles/XXX/charger/actions')

VIN replaced with XXX.

DutchKillerbee commented 5 months ago

Any update on the issue? I am wondering if start stop charging is actually working for someone.

coreywillwhat commented 5 months ago

Is start_charger working, but stop_charging isn't? Can you provide logs during the service call?

devslash0 commented 5 months ago

None of them work. Testet start_charging, stop_charging and start_timed_charging during the weekend. My car is not connected at the moment (at work), so I can provide logs)

.. few hours later. The error message in my logs are the same as above. 403 error.

DutchKillerbee commented 5 months ago

I can tell that start stop charging is working for me! I am using version 1.6.2 I by coincident removed the pin code protection of my account in my car (Q3 tfsie) and after that it seems to be working! So I assume when you protected your account in your car with a pin code in some way you need to send the pin code as well Part of my debug log

2024-04-17 19:58:53.446 DEBUG (MainThread) [custom_components.audiconnect.audi_connect_account] Sending command to start charger to vehicle *************3327
2024-04-17 19:59:13.971 DEBUG (MainThread) [custom_components.audiconnect.audi_connect_account] Successfully started charger of vehicle *************3327
2024-04-17 19:59:13.972 DEBUG (MainThread) [custom_components.audiconnect.audi_connect_account] Sending command to refresh vehicle data for VIN: *************3327
2024-04-17 19:59:14.049 DEBUG (MainThread) [custom_components.audiconnect.audi_connect_account] ClientResponseError with status 403 while refreshing vehicle data for VIN: *************3327. Disabling refresh vehicle data support.
2024-04-17 19:59:14.049 DEBUG (MainThread) [custom_components.audiconnect.audi_account] Refresh vehicle data is disabled for VIN: *************3327
2024-04-17 19:59:14.049 DEBUG (MainThread) [custom_components.audiconnect.audi_account] Requesting to refresh cloud data in 5 seconds...

I could only see a 403 error message...

coreywillwhat commented 4 months ago

Thank you for this @DutchKillerbee! this is a great hint towards a solution. We'll have to look into how this service call is implemented. Wondering if you could provide more information about the PIN though:

Thanks for your help!

devslash0 commented 4 months ago

Hmm. I have two Audi Accounts. The one i use in HA is a guest account, and I see now that "remote charging" is only visable in the main user. I'll try to swap to my main user and test again.

devslash0 commented 4 months ago

Testet with main account, still 403 error :/ I have my PIN entered in HA.

DutchKillerbee commented 4 months ago

@coreywillwhat Sorry for my late response but let me try to describe what happened.

At a certain day (I forgot what day) I had to login with my audi account in my car profile! The message was something like "your account has not been used for a while. Please login" Funny I used my car the day before. I didn't have my credentials by hand so I used the profile of my son. Both profile didn't have a pincode. The day after I logged in my car with my credentials and all seems to be fine. But Audi forced me to set a pin code to protect my profile. I added a pin code and later I removed it again. In my car everything is back to normal now. My profile is working and also all the other users profiles/accounts in my car.

Since that moment start/stop charging is working for me! Still I have a pin code configured in the HA integration, but I think this is another pincode than the pincode in your car (to protect anybody else using your profile)

To be honest I don't know if there is any relation what I did but I can tell that start/stop charging is working for me now

If I can help you providing some logs/other stuff please let me know.

DutchKillerbee commented 4 months ago

Some additional (maybe helpful) information:

coreywillwhat commented 4 months ago

Thank you so much @DutchKillerbee this is great information. I took a look and it doesn't look like we're passing a PIN for setting the vehicle charger, which would explain why removing your PIN from the Audi Vehicle Account might allow it to work. I can see if implementing the same method as used in "lock"/"unlock", will fix it.

The problem is, I can't test this, and there is a chance any changes will break your ability to use it without a PIN @DutchKillerbee . At least until we get the chance to revert it back. I would rather test this prior to pushing to the master branch. If I draft up a PR, would either @DutchKillerbee or @devslash0 be willing to test the code before we push to the master branch?

coreywillwhat commented 4 months ago

An additional question: What region are each of you? NA, EU, etc..

devslash0 commented 4 months ago

I can test yes :) available this weekend. EU (Norway)

DutchKillerbee commented 4 months ago

@coreywillwhat EU Netherlands. Ready to do some tests. Probably I will have to alter the files manually or could you prep a command to apply this patch to the current code. Currently running 1.7.0

harmendp commented 4 months ago

If need be, I can test as well. Audi Q4 etron, EU BE

coreywillwhat commented 4 months ago

@coreywillwhat EU Netherlands. Ready to do some tests. Probably I will have to alter the files manually or could you prep a command to apply this patch to the current code. Currently running 1.7.0

We've debated a beta release, but it would complicate the auto-release schedule, so we haven't made any decisions on that yet. For testing, I would suggest using Studio Code Server add-on in HA to modify files/lines for testing based on the PR. It will be more clear what needs to be done when I actually put the PR together and you can take a look.

I've run into an issue with this update though, as I'm in the US, and my car doesn't support start/stop/timed charging, I won't be able to figure out the action required for the S-PIN security token.

@t0bias-r I'm not sure if you can help out here.... @DutchKillerbee is reporting that removing the SPIN from their audi account allows them to use the execute vehicle action to start/stop the charger. Looking at set_battery_charger it doens't look like we're using a security_token for this. If it is required for starting/stopping the charger, then we need to add it similar to the set_vehicle_lock. The only piece i think we're missing would be the action for the _get_security_token(). Is the action something you could help figure out?

t0bias-r commented 4 months ago

@t0bias-r I'm not sure if you can help out here.... @DutchKillerbee is reporting that removing the SPIN from their audi account allows them to use the execute vehicle action to start/stop the charger. Looking at set_battery_charger it doens't look like we're using a security_token for this. If it is required for starting/stopping the charger, then we need to add it similar to the set_vehicle_lock. The only piece i think we're missing would be the action for the _get_security_token(). Is the action something you could help figure out?

@coreywillwhat I try to help :-) Just so I'm doing the right thing. I need to capture the API request for an action that requires the SPIN, right?

coreywillwhat commented 4 months ago

thank you @t0bias-r! Yes, specifically the start/stop/timed charging action, if you can.

t0bias-r commented 4 months ago

No matter which charging setting I change or charing action is execute (timer, immediately) in the app, I never have to enter the SPIN (for my Q8 etron). I just need the SPIN for locking and unlocking the car.

Here are the API calls: audi-car-locking.txt

What I don't currently know is which internal (security) calls are used for the challenge-response and for the hashing....

TFhdKi95ae8L commented 4 months ago

Same for me, start charging does not work anymore for a while. Willing to test / share logs if needed. A3 Etron