itchannel / fordpass-ha

Fordpass integration for Home Assistant
317 stars 58 forks source link

Feature Request: Forcibly Limit API Calls #217

Closed austinbeam closed 1 year ago

austinbeam commented 2 years ago

I love this integration, but seems like Ford doesn't. Several of us have gotten our accounts blocked and are now unable to use FordPass at all. They claim to be unblocking mine and I will report back assuming they do, but in the meantime wanted to make a feature request that might help with folks getting blocked.

Would it be possible for the integration to keep track of API calls and forcibly stop them once the limit is crossed within some configurable time period? The suggestion in #214 is that there is a 20k/week API limit. I'd like to go way lower than this to be safe since they tell me they'll only unblock me once, but others might want to fly closer to the sun. It would be nice to be able to choose the limit and time period (per hour, day, week, month, etc) but I'll take whatever form makes sense and is easiest.

Can't tell you how much I appreciate the work on this @itchannel. If there are other ideas on how to achieve the same, let me know. Just want my integration back! :)

AlteVerwischteZiege commented 2 years ago

@austinbeam In my case it was a 3d party app sponsored by my electrical utility that triggered the lockout with a refresh call every 5 min 24X7. As best I can tell you are in control of how often your HA instance demands the refresh.

austinbeam commented 2 years ago

Thanks @AlteVerwischteZiege -- as far as I know, nothing else is connected to Fordpass other than the app itself. All I could figure was I hit it really quickly in repetition during config change / restart cycles or something and caused the lockout, but hard to say for sure. I will make sure I'm not doing anything else to cause issues and hope for the best. Have a good one.

itchannel commented 1 year ago

As mentioned in #214 I will add in the ability to change the refresh rate in the options. By default it is every 5mins I would not recommend any lower than this or it will certainly lock your account out. But maybe I should increase the default to 10 or 15mins, thoughts?

ivlis commented 1 year ago

Thanks @itchannel for looking into that. I was locked out of my account today. I'm not using any other apps except this integration. I have two cars in my account, maybe this contributed to a ban. 15 minutes is actually totally fine with me.

Being locked out is not fun because phone as a key stops working as well as Ford Credit payments (yikes)

austinbeam commented 1 year ago

I think the higher default is wise, seems like they’re cracking down. It’s a shame they aren’t willing to work with developers at all and in general are so hard to get in touch with.

I assume you’re talking setting the default at 15 and still having it be configurable, right?

itchannel commented 1 year ago

Testing version 1.38 as we speak which sets a 15min update interval by default but can be changed in options

image

@austinbeam I agree it would be nice if the Ford devs got involved, I did try contacting via the official API but got no where. Happy to abide by Ford rules if I knew what they were :)

ivlis commented 1 year ago

@itchannel Does having two cars in HA increase API poll 2x?

itchannel commented 1 year ago

@ivlis It does unfortunately but only by an extra 2 requests as the token is already stored if using the same account with both cars on it. It will double the requests though if you use separate accounts as they have different creds etc.

I have 2 cars on my HA and haven't been blocked or limited and I counted the API requests and they were way below the presumed 20k cut off. However I have changed the default interval just to be safer and reduce the load on Fords servers. It can be overidden in options if people don't like it.

austinbeam commented 1 year ago

@itchannel Appreciate you and all your efforts!

itchannel commented 1 year ago

Latest release (1.39) changes the default poll interval from 5 minutes to 15 to reduce the amount of API calls.

You can also change it in the options if you want it quicker or slower. Just be aware it's set in seconds and anything less than 5mins (300 seconds) could result in a ban.

TechnicalLee commented 1 year ago

Ford has locked out apps that are only polling 3-5 times per day, I don't think shifting from 5 minutes to 15 minutes is really going to be an improvement. Polling every 15 minutes is still often enough to cause 12V drain issues. If you choose to continue using this, I'd reduce the poll rate as much as humanly possible. Or better yet, be more intelligent about when the vehicle is polled (such as only after arriving home, after your charging period ends, etc).

Also, I'm not sure how long the auth token is valid for, but it may be wise to only request a new token when the current one is expired rather than every time.

itchannel commented 1 year ago

@TechnicalLee When I'm talking about polling I'm referring to the polling interval to the Fordpass API to get the latest cached status not the vehicle. This integration only polls the car on user request running the "update" service, it doesn't do it automatically to prevent battery drain as you mentioned. Most people including myself just have it set to poll the car on demand such as an automation detecting I've arrived home.

It also only requests a new token when the old token has expired using the cached oauth "refresh_token".

austinbeam commented 1 year ago

Thanks for implementing this @itchannel