I try Sending external web request to: owner-api.teslamotors.com/api/1/vehicles/Id/command/set_temps?driverTemp=25
Tesla API Access
You canât send a command with a simple web request. You first need to ensure that you vehicle is awake and accepting commands, then a POST request with the parameter(s) exactly as written in the API and a proper authorization header are required.
Iâm going to assume you have the first piston at the top of this thread working and correctly populating your global variables: @accessToken and @vehicleID. If not, STOP, and donât proceed until you do as I wonât be able to help you.
Once you have that piston working correctly, this piston will set the driver_temp to 25C as requested.
As written, there is no trigger for the piston, but you can use the TEST button to execute it, call it from another piston, or add a trigger of your own.
This is great work, thank you for doing this!
I am uncomfortable entering my username and password in a piston, so I decided to make a small tweak. Rather than having to enter username/password, I changed the first (authentication) piston to accept a refresh token instead.
To use it, create a global variable named @refreshToken, entering a valid refresh token in it. The updated code is below for anyone interested. It replaces the code that takes email and password (piston zb8d3, above). Then run it once (via the Test button). After that point, the other pistons, to access car data, change climate, etc., work with this new code just like it does with the old (email/password) code.
I also had a problem with the vehicle ID starting with null so I made a tweak to fix that. It should work fine as long as there is one or more vehicles on the account.
@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)
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?
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
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âŚ
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?
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.
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?
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?
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.
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
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?
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.
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!
Known issue, as yet unresolved. See Web Requests are not working, can't access API's etc?