Tesla HTTP Proxy with Traefik #53
Olen
started this conversation in
Show and tell
Replies: 2 comments
-
Excellent work well done. I appreciate your detailed write up here which will no doubt help others who have the same setup |
Beta Was this translation helpful? Give feedback.
0 replies
-
I totally agree that @Olen 's discussion was helpfull. Thank you :) Adding the prints helped me to identify my issue related to 400 response. I'll open another thread for it, as different root cause :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just spent the better of two days getting this to work, and I'll just summarize my findings here.
Some of these might be added as PRs, some might just be FYIs and I hope someone finds them useful.
Access lists
First of all - you need to ensure there is IP access between the Tesla servers and your server.
com.tesla.3p.public-key.pem
file. You can probably limit the firewall opening to a subset of the addresses for now, but the nature of these kind of apps is that they can float around, so the tighter the policy, the more chance of something not working.In addition to this, Tesla also blocks access to/from certain providers. At least DigitalOcean is known to be blocked by Tesla. This means that you probably will not be able to host the Proxy at DO. It could be the same with other providers.
Tesla accounts
Make sure the account you use is set up as a primary account. If you use a different account, you need to be physically close to the car when you want to give yourself access as you must verify the connection with a key card. Using a primary account avoids this.
There is currently no way to remove an app from Teslas developer portal, so if you need to switch accounts, you probably also need to change the public domain name and use a different FQDN for the new account.
Troubleshooting
At least for me, the biggest problem (after I got my access lists sorted out) was the "Register Partner Account" step.
It helped a lot when I accessed the Docker container and added a few lines for more debugging:
After each
I added a:
So they end up as
The
req.text
gives much more useful info about what is wrong than just the status_codeFor instance, it will tell you if the problem is that Tesla is unable to access your certificate, or if the domain is already registered with another Tesla account etc.
I'm going to add a few PRs for this so it might get added as default.
Traefik
With Traefik, you can use the same domain for both the proxy host and the public address.
I used most of the docker-compose config as-is from this repo, but here are a few modifcations:
(The same must be added to
/data/config.sh
)Since Traefik handles the SSL certificate and give you a real cert, there is not really any reason to care about the private cert in HA, but the config in HA requires a valid path, so you still need that last path.
The Traefik labels can be set as following:
After the initial setup, all you need to do is remove the last line and add the following instead:
For the NGINX-server to serve the single certificate file, I have the following:
This makes sure only requests for
.well-known
are handled by this container, while all other requests to the same domain is handled by the other container.After starting the containers, you just need to add a few lines to the default nginx-config (located in
/local/path/tesla_proxy/nginx/conf.d/default.conf
under theserver {
section somewhere:Make sure your domain
tesla-proxy.mydomain.com
points to the right IP-address, and that any access lists, port-forwards etc. are open for the mentioned ip-ranges.And you should be good to go.
HomeAssistant
When you configure HA, remember that you must use slightly different values from what the container tells you.
Migration
For me, the migration in HA was very easy. I just added a new entry to the Tesla Custom Integration, selected the fleet API, and with the proper Refresh Token and SSL Certificate path added, the new entry showed up. I then removed the old entry from the HA config, and all the entity_ids etc. were nicely converted, so all my automations and dashboards etc. was working fine after the migration.
All in all, it was a bumpy road. Mostly because it took me a long time to get the access lists right, and because I wanted to use a specuial developer account first, instead of my own main account. Once that was sorted, it was mostly trial and error to get the files in the right place and understanding how these things are connected.
A few things I would consider
/data/access_token
and restarted the container to try again. So to be able to keep the flask-app running while the proxy is also up would be a nice feature..well-known
path. That way, we could avoid the extra container just to serve up that single file.Beta Was this translation helpful? Give feedback.
All reactions