-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Car API not available - can't stop charging #564
Comments
@danielsan1 thanks, this is all very frustrating. I have hopes that @ngardiner or someone else is adding support for the old system again via a fix. Getting an own domain to allow this again is kind of no option. |
I have noticed a bug which might be helpful in this case: original code (line 1050 in Vehicle/TeslaAPI.py)
This assumes that after the "state" variable, nothing is there. But that was not the case for me. It had additinal parameters in it that got added as "state" later on and so the requests always failed. This regular expression has to optimized to skip additinal parameters. I also would suggest to change it in case the reply changes (state before code in URL). |
I see the exact same errors and behavior on
I'll update to 16299ca and will test again in the next days. |
If the token is expired, then the refresh token should be used to fetch a new one. An individual token is good for eight hours. Maybe check your logs to see if/why that's failing? It looks something like:
|
I am still not lucky: First i have a legacy Model S, so legacy API should still work for me / my car. (I use twcmanager for years now, never hat problems until the versions since the last few months) I also imported the tokens (Access and Refresh token) via google chrome plugin (Tesla Access Token Generator) and settings page and it correctly writes both tokens to settings.json. So now my wrong behaviour. I don‘t get the message as users above (can‘t connect car…) i get the following:
Unfortunately i have no clue what i can do. I think my tokens are correct, but twcmanager is not able to „use“ them. Please give me a hint what i can check/try? |
I refreshed the tokens today, will keep an eye on the logs for any access_token errors.
|
I increased the log level, hope that helps:
|
@whisdol, it looks like the legacy API is now disabled for you, at least as far as commands go. I haven't looked into the Command Protocol much beyond the Fleet API tokens, unfortunately. @r3pTiLe1860, it looks like the response doesn't have a
|
@MikeBishop thanks for reply. command executes correctly and gets valid data (but as far as i can see - no drive_state:
i don't know if there is any critical data, so i replaced some at the beginning. glad to get some help :-) |
Hello, got some new observations...
This reply is not showing in my log. After 8 hours nothing seems to be refreshed. At least all I see in the log is a sudden 401 reply after a 200 one was given shortly before. As log level I have set 13 in config.json.
|
@GMerg I am still facing the same issues. Exactly the same log as yours. Car is M3 2019. Also no request to re-enter the tokens. But when restarting, the request appears. |
@Flitzer42, it's not that we don't have code to refresh the token. If it's failing for some reason, we'll need to understand why. @GMerg, going out on a limb, but what if you instead do:
Previously |
@MikeBishop i think you meant me regarding drive_state :-). I think we get further - looks better at least for me:
|
I get the following: |
@GMerg you have to wake up the car before. Just connect with app and repeat the command |
Great! I made #568 to add that scope, since I don't think there's any harm in doing it generally. |
@MikeBishop thank you so much, looking forward to the merge and i will report then immediately :-) |
@r3pTiLe1860 I have now the log after waking it up and performing the command @MikeBishop wanted... |
@MikeBishop thanks again for the fix. I checked after merge on main and it worked :-) logging looks good, plugged in car at night and the 6amp charging stopped after few moments. Now i hope the handling of access/refresh token works correctly. Will check again tomorrow. |
The access/refresh still seems to be a problem, at least for me. |
I can confirm that. Behavior is the same for me: Yesterday i updated and restarted - had to put in new tokens via URL method and all worked well. But as @GMerg stated there seems to be no update. After the token expires no more connection over API is possible and the refresh token is removed from settings.json. Doesn‘t seem to belong to fleet api because for my case it‘s the owner API. |
Same for me |
Thanks for confirming! I got same issues as @Flitzer42 and @r3pTiLe1860 reported. |
Same problem here M3 2020 and MY 2022. If I manually fill in the tokens it works for ~ a day. Then the api control gets lost. Im on v1.3.2. |
@MikeBishop or @ngardiner please help 🙏 |
Same for me since I upgraded to 1.3.2. Before the upgrade I can see the token refresh in the logs every 7 hours. It returns with After the upgrade to 1.3.2, the next refresh only lists In the After that, no refresh is tried anymore (probably we should change the code to retry the refresh with the old token) and when I try to access the API now it says Trying to reproduce that manually to see what is going on. If you have any ideas it would be much appreciated. Did not spend a lot of time with the API so far. |
Okay, fortunately refresh tokens are valid for quite some time. When I'm calling
I'm indeed getting a response without a refresh token:
Is this expected behavior currently? twcmanager at least seems to expect a new refresh token in the response. Did they disable token refresh to force people to the fleet API? Coincidentally my upgrade to 1.3.2 happened on March 26, the same day Tesla announced |
Ah, think we need to specify the right scope to get the according response. If I'm not mistaken, that is
|
Thanks @dtiefnig for investigating. Would be absolutely great if that fixes the token refresh. Fingers also crossed that owner api will stay for legacy cars ;-) |
Works for me currently with my 2019 M3P. Hope it stays that way for the time being. |
@Flitzer42 can you run the curl command with a valid refresh token? Does it return a new refresh token?
Did not have to change anything else to get this working again. But I did manually add the refresh token to |
@dtiefnig thanks for for response and support. I am running the TWCManager on a raspberry with buster (I failed to get TWCManager running on a bullseye. ). The curl command gives me a "curl: option --json: is unknown" as response. My curl version does not support --json (version7.64). I am no Linux or programming expert... |
Ah, the
The response should contain a new refresh token. If it does, it should work in twcmanager as well with the small patch. |
Thanks for clarification, The above request gives me a refresh token. That's fine. I did not test the function of the application again (takes some time until it refreshes the token). Let's see tomorrow.... |
Logged the refresh attempt with journalctl: |
Hmm, according to the log, the refresh token is not returned. Are you sure the code was patched correctly? Did you restart twcmanager to reload the source code? This does not happen automatically. If you restarted, is the patch still applied after the restart? Might be something is reverting the code back to the old version. |
Sure, rasperry restartet and verified with WinSCP and nano that the patch is in. (Was my first thought too :-) )
The comma at the end of the last line makes me curious... |
You can try the following patch:
Apply with Maybe a good opportunity to fix the typo in mainline as well, as the log line currently states |
Thanks for the support. I will do some further investigations on the weekend. Seems that the section starting with "try: ..." is not executed. Need to add further log outputs to trace. Will come back to you later. |
Oh, would make sense to put the new logger log line for the request before the |
Yea, that's the plan |
Sure, it's just software. :) The code is a little further down in the file. It checks whether the expiration timestamp of the token is less than x seconds in the future. As the tokens are valid for 8 hours, the 60 * 465 will cause the token to refresh 15 minutes after they have been issued. I'm using that myself to test the renewal.
|
Ohh shit, was working all the time on: "/home/pi/TWCManager/lib/TWCManager/Vehicle/TeslaAPI.py". This had no effect. |
Hah, a classic. So I think this issue could be closed. The original problem was fixed anyway by @MikeBishop already, so if there are issues with the token handling still, it may be better to open a new issue. Works for you also @GMerg? |
I can also confirm the fix. Many thanks to all of you. I updated to main after the refresh token and the let the car sleep fix were merged. Now, two days later the car was started to charge, the token is refeshed, all works perfectly :-) |
@Flitzer42 seems as I made the same mistake and run a different/old version after update. Now Im running the real deal and will have to test for 8 hours till the refresh token is about to get renewed. I will report back if that worked. |
I can confirm that the latest update fixes things with three notes that you need to follow to get it working:
|
Note 3: Interesting observation. For me it works without customization (legacy car P85D) I was able to paste the link from Tesla and it (refresh) works. Maybe a difference for legacy cars? |
I had this as the final URL: |
Two days now and all working perfectly with my additions above. So Maybe a fix on #566 and maybe removing the manual access/refresh data (or add a note that state is needed as well) will fix it for everyone. |
Hello,
Im having some issues for weeks now with trying to stop charging.
In log I see the following:
When I open the web browser, I see no request to update the "Access/Refresh Token" either.
In the latest config.json I read about a change on API since 2024 for cars produced after 2021, but my car is a lot older and this all worked before....shouldn't it then work as well now?
Would be nice if someone can help me getting this start/stop command back working.
The text was updated successfully, but these errors were encountered: