[tesla]/[teslapowerwallcloud] Time to think about Fleet API

Hey all,

As many would be aware, Tesla has introduced a public API and support for 3rd party apps, rather than having to use the previous reverse engineered APIs.

Developer docs are at: https://developer.tesla.com/docs/fleet-api
github page for Command API: GitHub - teslamotors/vehicle-command

At some point it is likely Tesla will charge for use of the API - how open source projects will be considered is TBD.

I’ve started playing around with use of the Fleet API - and don’t think it would be too difficult to adapt the current [tesla] binding, as well as my [teslapowerwallcloud] binding which uses the energy api’s to manage Powerwalls.

The key issue is that the vehicle command SDK uses Go not the Rest API - but does include a proxy server which translates the Rest API into the new proto commands that are requried.

I’ve hacked enough of powerwallcloud to have some ideas on paths forward.

My current proposal is:
Add Advanced ‘Things’ for the following items:

  • Configurable App ‘client-id’ - which would default to my registered client-id
  • Configurable Tesla Server (Tesla runs NA, EU and CN servers depending on vehicle location)
  • Configurable Proxy Hostname - which would default to a proxy that I would run
  • Configurable Proxy port - which would default to a proxy that I would run

This would allow those users who want to register their own account with Tesla to run their own proxy and client-id for privacy reasons. Also, if Tesla introduce API limits, the client-id can be changed without the binding having to be recompiled.

Note: All of this is based on my exploration of what’s required to update [teslapowerwallcloud] - I haven’t looked closely at [tesla] yet but I expect a similar approach would work.

Thoughts appreciated - and no timeline for me to look at this yet - firstly - I want to finalise/test the changes to [teslapowerwallcloud] as that is my most pressing need for my own HA.

2 Likes

OK - 1st problem - the tesla-http-proxy is designed to run only on localhost - and installs a self-signed certificate - which will cause problems…

Edit: I wonder if I can run nginx or something public facing - with a lets encrypt key - and forward incoming requests to the proxy running on localhost?

Edit2: looks like this might work - need to do some more testing :slight_smile:

Edit3: Actually, I don’t need to ask for the server as I can query it using the API - https://developer.tesla.com/docs/fleet-api?shell#orders & the region call

I have a WIP version of the [tesla] binding using the Fleet API. Querying data seems to work OK. Trying to send a command yields a 404 :frowning: I need to work out how to display the URL it’s trying to load - trying to use getUri() is giving an error :frowning:

Changes (so far) are in GitHub - psmedley/openhab-addons at tesla-fleet-api

I think I found the problem - I had a brainwave and checked the nginx logs I’m using to forward cmds to the tesla-http-proxy. The binding is using /api/1/vehicles/3744xxxxxxxxxxxx/command/charge_port_door_open - when with the fleet API, you need to use the vehicle VIN. Off to find the offending code…

OK - sending commands works now. I need to add the ability to:

  • Change the Client ID
  • Change the URL for the server running tesla-http-proxy
  • Change the port number for the server running tesla-http-proxy

So that people can either register using my client-id - or if they choose, register their own account and run their own proxy.

If someone wants to test either the [tesla] or [teslapowerwallcloud] binding using the fleet API - please PM me and I’ll send you a link to register your tesla account with my client_id, and send you a link to a JAR to test.

6 Likes

OK, seems Tesla broke things already and I need to make further changes.

See: 2024-02-01 announcement at https://developer.tesla.com/docs/fleet-api?shell#announcements-amp-api-changelog

Once you use a refresh_token to generate a bearer_token, it expires the previous refresh_token and returns an updated refresh_token. So I need to work out how to override the configured refresh_token and update it in the binding code - hopefully there is a way to do this.

I’ll update this post once I figure it out.

Edit: I think I need to use editConfiguration & updateConfiguration but on compiling, I’m getting:

[ERROR] /home/psmedley/openhab-addons/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaSSOHandler.java:[80,47] The method editConfiguration() is undefined for the type org.openhab.binding.tesla.internal.handler.TeslaSSOHandler
[ERROR] /home/psmedley/openhab-addons/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaSSOHandler.java:[82,17] The method updateConfiguration(org.openhab.core.config.core.Configuration) is undefined for the type org.openhab.binding.tesla.internal.handler.TeslaSSOHandler

I think there’s a missing ‘import’ statement, I just need to find the right one. More after work tonight

2 Likes