widewing/ha-toyota-na

[FR] Add Service for Forcing Refresh of Data

Closed this issue · 10 comments

It'd be nice to be able to trigger a manual sensor update of the status of the vehicle, initially really just thinking of location data, however I can see some tangential value of grabbing most aspects of the data.

The use case for location data is:

  • your garage door state just changed, get the latest vehicle location (testing for coming or going)
  • ssid or bssid changed on HA Companion app sensors, trigger update of statuses (location, locks, etc) to be able to ascertain if the vehicle is in different location or moving, etc.

Yeah it's a known issue. I haven't work out how to properly refresh the status yet. You can follow up discussion here: toyotha/toyota-na#1 (comment)

Ah, I was mainly talking about a Home Assistant service to trigger that, but good to know that it's blocked by that.

Is it worth figuring out how to rate limit this before exposing the service? I'd hate for someone to accidentally start spamming Toyota services and get unwanted attention on this project.

I was also a little concerned about the update rate too, the auto-update is currently set to every minute. I would hate for it to get shut down if that is too frequent.

I'm still digging through the APK dump but I'm hoping there's some sort of event endpoint we can use so we don't need to poll. I'm not hopeful, I think most of the eventing the app seems to have is driven by firebase notifications, but 🤞🏻 something comes up yet.

some sort of event endpoint we can use so we don't need to poll

I was thinking about that yesterday. But suspected it's mostly firebase-driven.

It might be possible to have a longer frequency set up for when the vehicle is "idle" and a shorter one for when the vehicle is in use. You can leverage the companion app's WIFI and movement sensors to help with those transitions, too.

It might be possible to have a longer frequency set up for when the vehicle is "idle" and a shorter one for when the vehicle is in use. You can leverage the companion app's WIFI and movement sensors to help with those transitions, too.

One thing I'd like to do is make the pip library a little more intelligent with regards to updates too. It should be fairly trivial for that lib to keep a little bit of state somewhere it can have some sensible default behavior that only hits the status endpoint to determine if anything has changed (such as location, fuel level, etc) and then call the rest of the data endpoints to do a full sync.

Additionally remote_request actions would probably automatically trigger a refresh_status so the next poll for update would return the correct state further reducing the need to always do a full sync from Toyota. This negates the need to call refresh_status today after doing anything to your doors or windows (currently required because the vehicle doesn't seem to push that state to the cloud immediately).

Hypothetically a refresh_status service in HA still makes sense because if any state actually changed the update function would do a full sync. But I'd argue pretty strongly the pip library should make it no-op if it's called more often than some threshold. I may be overthinking the rate limit bit, but it seems to be the heaviest API call given it causes the toyota cloud to poll the vehicle, so I want to be extra cautious here about preventing abuse.

But I'd argue pretty strongly the pip library should make it no-op if it's called more often than some threshold. I may be overthinking the rate limit bit, but it seems to be the heaviest API call given it causes the toyota cloud to poll the vehicle, so I want to be extra cautious here about preventing abuse.

No, you're not overthinking it. The logic for handling this should be in the library itself. I was merely keeping things on a HA-centric topic due to this repo.

And for sure the library can keep the logic, just make sure things are being handled in such that multiple vehicles won't break it.

I'm still interested in this. And I've got some ideas to implement an aggressive back-off rate limit so it's useful to get oneself out of a bind or force a refresh once in awhile without being something that can be abused.

A service to refresh data was added in v2.4