Tesla API Access


Since I also use TeslaFi, I’ve been relying on its auto-generated token to copy/paste it into WebCoRE. I find if I use these WebCoRE routines for token generation, it becomes a conflict with the TeslaFi token and is null since a new token was generated via WebCoRE. It would be great if there was a way to just automatically take the TeslaFi token and use here in WebCoRE.


Thank you!.. I use TeslaFi as well, so I’ve resorted to that for now and paused the refresh piston.


Great, thanks! I’ll keep an eye out for an update. In the meantime I’ll use the manual method noted by @PrometheusXex below.


Like I said before, unless of course it was working out for you, but when WebCoRE would do the refresh, it would kill the TeslFi token (and vice versa). They compete… not work with each other. So even though this issue is resolved with WebCoRE, it’s still a pain… at least it was for me.


I thought I had documented this potential conflict, but reading back it’s apparent I didn’t do so within this thread. To the best of my knowledge, you’re right that you cannot have webCoRE and TeslaFi both generating and/or refreshing the access tokens independently.

Sharing the token or allowing an account to have more than one token are both good solutions, but a bit beyond the purpose of these pistons, which was to demonstrate how webCoRE could be used to access the API. However, with webCoRE and ST parting ways before the end of the year due to the demise of the groovy platform, I’ll probably be focusing my efforts elsewhere unless I decide to move to Hubitat.


Here is the updated Access Token Refresh Piston for the v3 API.

To use this piston, you will first have to obtain a Refresh Token. I used a python script available here. There is also an iOS app called Authla that purportedly can do this as well. I 'm sure there are other options I’m not familiar with. .

The piston employs a workflow workaround for a webCoRE bug that arises with pistons containing multiple POST statements, so a new global variable (type: Boolean) @tokenSwitch is needed. See the instructions within the piston itself for startup instructions.

As noted in this post, if you are using TeslaFi or another third-party service that maintains the access token, do not use this piston. You will have to manually update the value of @accessToken whenever those services refresh your token. (That should occur approximately every 45 days).

Because of the requests here and elsewhere, I’ve posted this without the longer range testing I usually prefer. I’ll update the original post with this new piston after seeing what, if any, feedback, I receive.


Web Requests are not working, can't access API's etc?

Thanks for putting this together @bthrock. I’ll try this out in a bit. Question regarding the variable @tokenSwitch. Should I use the variable type Boolean for it?


Question regarding the variable @tokenSwitch. Should I use the variable type Boolean for it?

Preferably, yes. Good catch.


Thanks again @bthrock! I’ll try to implement it this weekend and hopefully things go smoothly fingers crossed :smiley:


Sorry to bother, but I tried importing the piston and had a quick question. After importing I noticed that the URLs are replaced with :xxxxxxxxxxxxxxxxxxxxxxxx0: instead of the [https://anonymized.webcore.co] as illustrated on your screenshot. Should I leave it as the xxxx… string or replace it with the [https://anonymized.webcore.co] from your screenshot?

Thanks again!


Many thanks for updating this! Are you saying that I can’t have separate refresh tokens for TeslaFi and webCoRE (this piston) that will create separate access tokens? Does the Tesla API only allow for one refresh token and one access token at a time?


I’ve updated the piston, using variables to define the URLs, so it should import cleanly now. The piston value under “Execute Piston” statement will likely still have to be manually entered and needs to refer back to the piston itself.

I’ve also tweaked the piston to address an issue with the refresh scheduling. Hopefully I’ve got it straightened out now. The new import code is dy93.


My understanding is that you can only have one Refresh Token per account. I don’t claim to possess comprehensive knowledge of the API, however, so it might be a question worth posting on Tim Dorr’s github page.


Thanks again @bthrock! I’ll try it later today and will let you know if anything else comes up :smiley:


Thanks agian @bthrock for updating the piston. I loaded everything into webcore and ran a test. It seems like it worked but I noticed in the log that there were 11 errors noted, like the one below:
:+304ms ║Error executing external web request: groovyx.net.http.HttpResponseException: Bad Request

Do I have to worry about this? It seems like it’s hitting a error when attempting to connect to the API but I’m not familiar with the Webcore to know for sure.

Thanks again!


Hi @bthrock, I tried to run the new piston. It runs, I don’t get any error messages but the global variables aren’t filling with anything. Can you see any errors in my piston? I added the boolean global, I added my refresh token and I’ve chosen the correct piston to run. Any ideas?


Just to add here are my local and global variables too…


The token value you’ve provided for refresh_token is an access token, not a refresh token. The refresh token is an 800+ alphanumeric token starting with the letters “ey”.


Yes, that’s a problem. Without looking at a full log and trace, it’s hard to say where the error is coming from.

Be sure both the log and trace do not contain personally identifiable information (i.e., you can redact all but the first two characters of the refresh token). Feel free to DM the log and trace rather than posting them here (you can still redact the token) if it makes you more comfortable.

Two things to consider: (a) be sure the refresh token is an 800+ alphanumeric token beginning with the letters “ey”. (b) do you have more than one tesla vehicle or a tesla powerwall on your account?


Oh - in that case i’m not sure Authla does support it. It created the access token and the refresh token is just numbers starting with 96a.

Looks like i’ll have to installed Chrome momentarily then.

Edit. Sorted. Used the Chromedriver thing, got the long one and plugged it in. Reimported your script again as i’d fiddled around trying to get it to work and recreated the global variables with no entries set - it’s worked and now all pistons that rely on the access code work too, happy days!