DurgNomis-drol / ha_toyota

Toyota Connected Services integration for Home Assistant.
MIT License
142 stars 27 forks source link

Feature request: Add last trip as a sensor #145

Open BertVereecke opened 1 year ago

BertVereecke commented 1 year ago

Would it perhaps be possible to add a sensor that holds information about the last trip? The necessary functions are already present in the mytoyota python library, but this data is not retrieved by ha_toyota.

I think it would be nice to have a sensor, with:

I personally believe only the last trip should be added as a sensor, as adding older trips would become too messy.

Kind regards, Bert

CM000n commented 7 months ago

Hello @BertVereecke, in principle that would be interesting. The problem here, however, is that Toyota does not have an independent API for querying the last trip. You can only make requests to the Toyota Trips API that contain a from_date and to_date and then get back all trips that are within this period.

Now, of course, we don't know when your last trip took place, for example. You could have been travelling 3 days ago, but also 1 month or 1 year ago.

Toyota itself stores the trip data for 1 year. We would therefore have to retrieve all trip information for 1 year each time and filter for the last trip in it. In my initial opinion, this would probably cause too much load.

Ishima commented 3 months ago

It's possible. I already implemented that & currently testing with few other options, like sending remote commands. API takes offset & limit, so knowing the limitations, we can ask for 1 entry in the last 90 days (I thinks this period should have some entries). API seems to be sorting trips descending, so asking for only one will return the 'last trip' we need.

gthbcrvs commented 1 month ago

I would love this as well.

If possible it would be great to add all trips to InfluxDB. Would it be possible to check the date and time of the last known trip in HA and search the result from the API for everything after that date? Then add them one by one to InfluxDB and have the new last known trip available in the sensor in HA.

It would be awesome to be able to compare rides, fuel use, eco score, EV mode, etc. over more rides.