-
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
Implement Fleet API vehicle_data rate limiting #575
Comments
Ultimately, I'd love to take the suggestion in #562 that we use the Pi's BT interface to directly command the car without going through the API. My initial experiments with that using the Tesla command line tools haven't been successful, though. But that would let us completely bypass these limits. |
Yes, I also think that this would be the way to go. Do you currently have the Fleet API working with TWCManager and are not running into the rate limits due to too many charge start/stop commands? Is there something I can do with the existing configuration options to limit the number of commands that are sent to the Fleet API? |
@blach Start charging attempts should be very limited because of the All I see is TeslaAPI calls to |
This morning I was running a mix of an old version of TWCManager with the latest TeslaAPI.py. I did this because I made modifications to the source code in the past to work with my Fronius inverter setup. The log file below is from that Frankenstein-version of TWCManager, so it might not reflect the behavior of the main branch. I have since then updated all files to the main branch. Currently there is not enough solar power, so I'll check again tomorrow and let you know. Anyway, this morning, it tried to start charging both cars about every minute, even though the server already returned "complete" or "is_charging". I'm not sure if this will be fixed by updating the rest of the source files of TWCManager to the versions from the main branch. Anyway, here is part of the log file from this morning:
|
So TeslaAPI is saying:
but it does not stop asking to start charging:
There are 5 situations where
Assuming non of these applied every minute in the above log the question is: why does TWCManager not respect |
I'll check how it behaves tomorrow when there is enough solar power. Maybe the issue was due to a mix of the old and new source code. |
TWCManager/lib/TWCManager/TWCSlave.py Line 559 in b4d1536
It looks like stopAskingToStartCharging is reset for all cars if at least one TWCSlave has I do have two TWCs ("slaves") and two cars and one of them was charging. So I think that line was executed in my case. |
Ok, I just tested this:
I added log statements to TWCSlave.py to see if that code is executed. And indeed, this code in send_slave_heartbeat is called about every second: TWCManager/lib/TWCManager/TWCSlave.py Lines 546 to 559 in b4d1536
The "slave" that is charging causes This results in "Car API cmd charge_start" being sent every minute, running into the rate limits. I'm going to comment out those lines in TWCSlave.py now. I'm wondering why you aren't running into this same issue? |
With those lines in TWCSlave.py commented out, I now get this in the log file:
I'll keep watching it, but this seems to solve my issue! So in conclusion, I think these lines should be removed or commented out to prevent sending TWCManager/lib/TWCManager/TWCSlave.py Lines 546 to 559 in b4d1536
|
I'm glad we found where the current logic fails for you. I looked at the code again and I can't figure out why we don't have the same issue. The @MikeBishop Can you see how this is supposed to work? |
I see what the problem is now. During a charge the quoted code indeed resets I think there are not too many TWCManager users with two or more TWC slaves. It seems this logic has been broken for a long time if not forever. Removing the code completely like @blach did seems right. Or we could add a conditional |
Or we could add conditions like the case above, so that it triggers when any TWC starts charging, not continuously while charging. But I suspect this isn't needed and can just be removed. |
Yeah, I also think this has been broken for a long time, but it never really mattered because the legacy Tesla owner API didn't put any limits on the number of charge commands. I'm glad you were able to trace the problem. |
Today I ran into another rate limit: One of the cars was not at home, so I think I see this in the log:
According to Tesla's website, "Device data" limit is 200 requests / vehicle / day. So I now set the default value of the TWCManager/lib/TWCManager/Vehicle/TeslaAPI.py Line 1477 in b4d1536
and here: TWCManager/lib/TWCManager/Vehicle/TeslaAPI.py Line 1488 in b4d1536
This should only call the API endpoint up to 12 times per hour, which should make it stay below the 200 requests / day. |
I just saw that there is a backoff mechanism that should be triggered when the API returns 429. Unfortunately, |
|
I looked at the code: In
So I think that's why the backoff mechanism isn't triggered. Correct me if I'm wrong. |
By the way: I still think that update_vehicle_data should cache its result for 5 minutes instead of only 1 minute to not exceed the 200 / vehicle / day device data limit. |
You are right, I've added that to #589 now. It is TWCManager/lib/TWCManager/Vehicle/TeslaAPI.py Lines 770 to 782 in b4d1536
|
I'm talking about these lines in TWCManager/lib/TWCManager/Vehicle/TeslaAPI.py Lines 1435 to 1438 in b4d1536
There should be a call to But yeah, |
I indeed missed the 429 in |
I just read the Tesla Fleet API membership tiers which mention:
So we should limit the vehicle_data request calls to 1 per 5 minutes. The start/stop commands and wake limits should be OK as is.
The text was updated successfully, but these errors were encountered: