Tesla API Access


#46

@bthrock this has stopped working for me this last week and i’ve no idea why. Is yours still working?

I’m getting the following when I run the token request piston for instance (i’ve changed the token btw)

07/09/2020, 12:11:25 +586ms
+0ms ╔Received event [Home].test = 1599477085585 with a delay of 0ms
+90ms ║RunTime Analysis CS > 20ms > PS > 43ms > PE > 27ms > CE
+92ms ║Runtime (50315 bytes) successfully initialized in 43ms (v0.3.110.20191009) (91ms)
+94ms ║╔Execution stage started
+100ms ║║Cancelling statement #2's schedules...
+131ms ║║Sending external web request to: owner-api.teslamotors.com/oauth/token/
+1046ms ║║Executed virtual command httpRequest (936ms)
+1057ms ║║Calculating (integer) 1 + (integer) 13 >> (integer) 14
+1061ms ║║Executed virtual command setVariable (1ms)
+1073ms ║║Calculating (integer) 84 + (integer) 11 >> (integer) 95
+1086ms ║║Calculating (integer) 107 + (integer) 11 >> (integer) 118
+1091ms ║║Calculating (decimal) 1.599477086E9 + (decimal) 3888000.0 >> (decimal) 1.603365086E9
+1095ms ║║Calculating (decimal) 1.603365086E9 * (decimal) 1000.0 >> (decimal) 1.603365086E12
+1098ms ║║Executed virtual command setVariable (1ms)
+1100ms ║║Cancelling statement #15's schedules...
+1111ms ║║Calculating (string) Bearer + (string) qts-7ba2640dfab4ede614daf71aa38aa6292c15bf4d5c63b6f0ef7f709f9ce9 >> (string) Bearer qts-7ba2640dfab4ede614daf71aa38aa6292c15bf4d5c63b6f0ef7f709f9ce9
+1114ms ║║Sending external web request to: owner-api.teslamotors.com/api/1/vehicles/
+1727ms ║║Error executing external web request: groovyx.net.http.ResponseParseException: Unauthorized
+1728ms ║║Executed virtual command httpRequest (615ms)
+1756ms ║╚Execution stage complete. (1663ms)
+1759ms ║Setting up scheduled job for Tue, Sep 8 2020 @ 12:00:00 AM BST (in 42512.656s)
+1767ms ╚Event processed successfully (1767ms)

#47

Hmm it’s really strange. I can get the API working in my API testing program, so it appears to be a part of the code - but it’s affecting all pistons I’ve built that use the Tesla API.

I just keep getting
Error executing external web request: groovyx.net.http.ResponseParseException: Unauthorized

I can generate a new token and then the second part of the token piston causes the same error. I can’t work out why - nothing appears to have changed in the API, and nothing has changed in my piston - is it just me having this?


#48

I’m seeing this error as well:

Error executing external web request: groovyx.net.http.ResponseParseException: Unauthorized

This, of course, prevents the Vehicle ID from updating properly.

I’ll have to take a closer look at this, although I seem to remember this happening elsewhere in the past.

Edit: Found it


#49

It then seems to happen in every command too - I can’t currently issue any commands to the car (even if I hard program the Vehicle ID as 1)

I don’t’ see a fix in that thread? Just talking about it…


#50

Just a thought, it might be that 2FA has been activated on the server? Although if that’s the case wouldn’t it have broken TeslaFi too?

It’s imminent but i’m not sure if it would affect us or not?


#53

Ah, it was the piston after all. It’s been so long since I wrote the original piston, I forgot how sloppily I originally parsed the tokens. Looks like Tesla made a minor change and killed it. This should fix it.


#54

Thanks! That sorted the token generation (although i’m getting a vehicle id of “null3691219499162923”) but no error when it’s generated.

All my buttons and actions are still broken though. What’s the changed I need to make here so they work?


#55

Ah ok, it was vehicle ID issue - it shouldn’t have “null” in front of it - any idea how to filter that out or why it’s happening?


#56

I’m not seeing the null issue here, but I have a guess as why it might be happening. Do you or have you had multiple cars in your account at any time?

Either way, it might be helpful if you logged the full $response after the GET request to TeslaApiURL and forwarded it to me by PM. For security, you can mask or replace any private data if you want to, just don’t change the structure of the JSON.


#57

Only ever one car. I’ve tried to adjust things in the expression but it always gives me a null followed the the number.

Let me try and get the full response now from Webcore


#58

I have never done anything with an API before but I have been trying to figure out a way to get Alexa to control my climate! Would I be able to use this piston to do that?


#59

You can control climate with the API, however, the pistons posted here aren’t currently working and I am currently attempting to determine the reason and come up with a solution, but I don’t have a time frame on that just yet.


#60

Hi @bthrock, I imported your code but nothing happens when I hit the test button. The variables don’t populate and the last execute time doesn’t change. Did I do something wrong? I imported the file three times and the only thing I changed was the username and password field.

Any assistance is appreciated.

Thanks in advance!


#61

Known issue, as yet unresolved. See Web Requests are not working, can't access API's etc?


#62

Thanks for letting me know @bthrock. I seriously thought I broke something :smiley:


#63

If you haven’t noted already, the Tesla API access is working again.


#64

Thanks for letting me know. I didn’t notice until you posted. I lost my vehicle Id during the Tesla/Aws failure and it wasn’t scheduled to pull the new token for another couple days. I executed the piston and it ran flawlessly. Thanks again for letting me know and for putting the piston together.


#65

Greetings…
I’m not entirely sure if I’m doing something wrong with the first piston. It assigns the string @accessToken and datetime @tokenExpiration global variables, but does not assign the string @vehicleID.

Perhaps I’ve overlooked something?

I’ve entered my email and password in ONLY the two areas provided as per instructions, but when I TEST the piston, I get an error. :frowning:


#66

From your log, it looks like you’re using an out-of-date version of the piston—which is my fault, as I should have updated the top post after some recent changes. Try the piston included in this post here.

Thank you for the reminder to update the post.


#67

@bthrock

Thanks for the reply.
One thing I was thinking, I use TESLAFI.COM which generates its own token for car access. Does your piston generating its own token interfere with TeslaFI’s token? The reason I’m asking is I literally just got an email from them saying:

" TeslaFi.com was denied access using your token with Tesla.com and logging has been turned off.
This may be because your token has expired or you changed your password on Tesla.com. You can generate a new token in settings->account->Tesla API Token."