teslamate-org / teslamate

A self-hosted data logger for your Tesla 🚘
https://docs.teslamate.org
MIT License
5.76k stars 717 forks source link

Tesla API Changes #3364

Closed SebastianGode closed 7 months ago

SebastianGode commented 11 months ago

Is there an existing issue for this?

What happened?

Tesla will shutdown the current Owners-API starting in 2024: https://developer.tesla.com/docs/fleet-api#announcements-amp-api-changelog

Instead they will offer a new and improved API with proper OAuth authentication. However that API is limited for free-users and likely will have paid tiers.

How will Teslamate then handle this? here are the docs: https://developer.tesla.com/docs/fleet-api#overview

The limits are the following: image image

Expected Behavior

Teslamate should offer different options to use the new API once plans are available.

Steps To Reproduce

No response

Relevant log output

-

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

1.27.3

cwanja commented 11 months ago

At first glance, and definitely not a professional, but it seems like the vehicle commands API is being retired. But not the vehicle endpoints API. And since TeslaMate does not send commands, but only consumes the API, the impact is TBD?

SebastianGode commented 11 months ago

As far as I understand it the streaming-API also should be impacted as only up to 10fields per minute can be retrieved. And I bet all the data we have is from way more than 10 fields.

cwanja commented 11 months ago

As far as I understand it the streaming-API also should be impacted as only up to 10fields per minute can be retrieved.

And I bet all the data we have is from way more than 10 fields.

The fleet API is different than the owners API (as far as I know). And if you look at the URLs in the documentation, that's all Fleet APIs that seem impacted.

According to the linked documentation, it is the commands API that is being retired. Not the vehicle data.

pradeeppattamatta commented 11 months ago

From what I see, The approach would be the same as outlined in fleet-api. The Readme from this new Vehicle Command SDK is pointing to fleet-api docs about process to get the OAuth tokens.

EasternPA commented 11 months ago

Can TeslaMate be modified to pull data from the CAN bus or an OBD-II adapter?

petariga commented 11 months ago

Can TeslaMate be modified to pull data from the CAN bus or an OBD-II adapter?

This sounds as a great idea for an alternative data source solution regardless whether the API will be paid or not. However, I am not sure that for example location information is available over the OBD, it may require to combine it with other GPS source and probably a RPi or so. It would be nice to support the same OBD adapters as ScanMyTesla uses (https://www.scanmytesla.com/adapters).

EasternPA commented 11 months ago

Reviewing the DBC for Model 3/Y (a key player in the world of car hacking), GPS data appears on multiple buses. I believe the Vehicle Bus is on the tap at the rear of the center console. I also believe the Chassis Bus is under the dash on the front right. Kim Java highlighted that tap when installing a new cluster display behind the steering wheel. There's a third one behind the center screen that I've heard is called The Party Bus, where they all come together. We would want to tap the Vehicle Bus since that seems easiest.

More than just lat and long, though, TM also displays altitude, but I haven't found that in the DBC yet.

Check out lines 3121-3122 and 3169-3170 for some GPS data on the Vehicle Bus:

https://github.com/joshwardell/model3dbc/blob/master/Model3CAN.dbc#L3121

Using a White or Gray Panda from comma.ai and a Pi 0, Pi 4, or Pico in OTG mode, you can power the Pi and communicate with the car via the Panda. The White Panda even has WiFi, so if there are some really good hackers here, someone could effectively recreate the deprecated Tesla API on a private WLAN inside the car. Then, a companion app on the phone could ship the data over cellular back to a TM server at home or out on the cloud. It may not be easy, but it doesn't seem impossible with the right motivation and skills.

Panda code is here: https://github.com/commaai/panda/tree/master

cods4 commented 11 months ago

Using a White or Gray Panda from comma.ai and a Pi 0, Pi 4, or Pico in OTG mode, you can power the Pi and communicate with the car via the Panda. The White Panda even has WiFi, so if there are some really good hackers here, someone could effectively recreate the deprecated Tesla API on a private WLAN inside the car. Then, a companion app on the phone could ship the data over cellular back to a TM server at home or out on the cloud. It may not be easy, but it doesn't seem impossible with the right motivation and skills.

Or look into using the OVMS hardware. It only supports two canbus networks AFAIK, but it has built in 3G/4G modem so can communicate straight back to the Teslamate server without relying on a phone or wifi network.

EasternPA commented 11 months ago

Or look into using the OVMS hardware. It only supports two canbus networks AFAIK, but it has built in 3G/4G modem so can communicate straight back to the Teslamate server without relying on a phone or wifi network.

Oh, that's nice. I've been in the comma world for so long that I'm not familiar with other options in the market. On another note, I bought a lifetime license for Tessie before he had a chance to raise the prices, and only then did I learn that they have their own API. That might be yet another possible data source for TM. "Simply" pulling from another API (easy for me to say)

dyxyl commented 10 months ago

More than just lat and long, though, TM also displays altitude, but I haven't found that in the DBC yet.

TM gets the altitude (elevation) using SRTM (https://github.com/adriankumpf/srtm).

Basvg commented 10 months ago

As far as I understand it the streaming-API also should be impacted as only up to 10fields per minute can be retrieved. And I bet all the data we have is from way more than 10 fields.

The fleet API is different than the owners API (as far as I know). And if you look at the URLs in the documentation, that's all Fleet APIs that seem impacted.

According to the linked documentation, it is the commands API that is being retired. Not the vehicle data.

The documentation is indeed confusing, because that is how I read it at first too. However I have found this on their repository:

Some developers may be familiar with Tesla's Owner API. Owner API will stop working as vehicles begin requiring end-to-end command authentication. If you are one of these developers, you can set up the proxy server or refactor your application to use this library directly. Pre-2021 Model S and X vehicles do not support this new protocol. Fleet API will continue to work on these vehicles.

So it does seem like both the Owner API and the newer Fleet API will be retired at end of this year for almost all cars. Only pre-2021 S and X will still be able to use the Fleet API.

brianmay commented 10 months ago

Wish they wouldn't say "Pre-2021 Model S and X vehicles". Do the really mean this? Or do maybe they mean cars without the MCU2 upgrade? If so, can I downgrade my car back to MCU1 ;-) ?

This is a link to the HTTP proxy server: https://github.com/teslamotors/vehicle-command/tree/main#using-the-http-proxy - complete with full source code (I think...)

But not really sure if this will work for older cars. And looks like this proxy only implements the fleet API.

Glancing through the code, the new API is based on protobuf instead of json. Easy enough. But not sure why they needed to make this change, really.

So, for Teslamate, considering it sounds like the owner API is going to stop working, that presumably will mean Teslamate will stop working to. We could update to use the fleet API via the proxy, but major changes to support another deprecated protocol seems pointless. Although presumably it would work with old cars (direct connection) and new cars (via http proxy). So maybe we need to look at the newer API.

But is this actually worth while? If Tesla start charging large amounts of money to access their APIs (look at what happened with Twitter...) then that could be pointless too.

I think like it or not, Tesla has never really appreciated the benefits that their free API provides. And until now, it certainly has been a key reason why I prefer Tesla to its competitors.

SebastianGode commented 9 months ago

The current Command API will be hard-shutdowned in January: image https://developer.tesla.com/docs/fleet-api#2023-11-17-rest-api-vehicle-commands-endpoint-deprecation-timeline-action-required

I'm not sure what this means for Teslamate but I'd assume there need to be some changes also for telemetry data.

brianmay commented 9 months ago

See my post here https://github.com/teslamate-org/teslamate/discussions/3366#discussioncomment-7603851

The above seems to suggest that all REST API points will be deprecated. I think this isn't correct, I believe the auth API and streaming API are not affected, and both of these could be considered REST APIs. In fact the new repo docs point to the fleet api which is mostly a Rest API. It does mention a "signed_command" which I assume is the new command protocol, which seems to indicate that the page is reasonably up-to-date.

So exactly what is deprecated is somewhat confusing. It could be that only commands are deprecated. i.e. any call that changes the state in some way (e.g. wake_up. Or start/stop charging). And requests for information - such as what Teslamate uses - are not deprecated. But don't take my word for it.

When I looked last, I could not find the *.proto files we would need to access the command protocol directly. Except via go programs, and obviously we use Elixir, not go. I could not find any documentation outside the go library either.

We could use the supplied - open source - http proxy - written in go. My feeling is if we point Teslamate at that, it should "just work"(TM) - but somebody should really test this.

Regardless of how we talk to the command protocol, users need a private/public key combination. And that public key needs to be deployed to their cars. This is going to be the awkward part. In order to enrol a public key to your car, it looks like you will need to have your own DNS domain. Something I could do, but is yet another obstacle for people running Teslamate.

denouche commented 9 months ago

Hello, I started to have emails from users concerned by this changes on my 2 android apps (Tesla advanced notification and Tesla Automation). The error they have for example when calling https://owner-api.teslamotors.com/api/1/vehicles/xxxxxxxxxxxx/command/set_sentry_mode is a 403 answer and in the response headers I see: Header[name=x-signed-commands-required,value=true] Not all the users are concerned, on my side with my Model 3 I don't have any issue for now. Maybe it's enabled for new cars only?

SebastianGode commented 9 months ago

@denouche The Command API has been shutdowned for all new cars as well as existing cars which haven't used it since 30days. All other cars will also be shutdowned starting January. See the official timeline. You will need to use the new commercial fleet-api for this.

Teslamate has nothing to do with it.

denouche commented 9 months ago

Yes sorry for that @SebastianGode , I wanted to share and try to understand this changes. Sorry for the off topic.

Zegorax commented 8 months ago

It's still working fine on my side. I did not try to log out and then in, but the API scrapper is still working without any changes.

cwanja commented 8 months ago

Stopped working Jan 3rd about midnight:

sudo docker-compose logs teslamate

shows the following

teslamate_1 | 2024-01-06 21:34:27.808 [error] GET https://owner-api.teslamotors.com/api/1/vehicles/1492931601438200 -> error: "non-existing domain" (8013.626 ms)

teslamate_1 | 2024-01-06 21:34:27.808 [warning] TeslaApi.Error / non-existing domain

logging out and trying to log back in, I get:

teslamate_1 | 2024-01-06 21:39:15.183 [error] POST https://auth.tesla.com/oauth2/v3/token -> error: "non-existing domain" (8015.483 ms)

teslamate_1 | 2024-01-06 21:40:08.707 [error] POST https://auth.tesla.com/oauth2/v3/token -> error: "non-existing domain" (8011.224 ms)

I'd check that devices internet connectivity. Had zero issues logging drives. And continue to see the location sharing icon today without the native Tesla iOS app open.

Nils154 commented 8 months ago

apologies, got it working again, something with pi-hole is causing the problem.

SebastianGode commented 7 months ago

SO now the first people seem to have issues with Teslamate as the Owners API gets rejected as expected. https://github.com/teslamate-org/teslamate/issues/3620

Sad that this issue was marked as closed despite Tesla announced the shutdown quite early on...

JakobLichterfeld commented 7 months ago

Sad that this issue was marked as closed despite Tesla announced the shutdown quite early on...

This issue was never closed, only labeled as invalid. You cannot solve a problem in advance, if you do not know the exact change beforehand. Using fleet API with developer account is not a solution for everybody and his parent.

Up to now, only a restart of TeslaMate will cause no data recording. First PR already in testing, follow #3629

SebastianGode commented 7 months ago

Thanks for the quick help to all @JakobLichterfeld :)

JakobLichterfeld commented 7 months ago

As of now we found a workaround, will close this