Tesla API Access


#104

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!


#105

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?


#106

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


#107

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”.


#108

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?


#109

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!


#110

Glad to know it’s working. I hadn’t actually tried Authla, so I apologize if I sent you on a wild goose chase. I’ll have to take another look at the app when I get a chance.


#111

What are your long term plans? Are you expecting to move over to Hubitat in the future? Or something else?


#112

Thanks @bthrock, I think I’m good to go. The error was that I wasn’t using the proper refresh token. The Authla app’s refresh token isn’t the ey one, but after getting python installed and running the script I was able to put in the proper refresh token and everything worked. No errors :slight_smile: .

I do have more than one vehicle (my friend’s) is that going to be a issue? We worked together to address this before and since this piston only stores the access token it shouldn’t be a issue right?

Thanks again!


#113

On the second screen of Authla (below) is the refresh_token at the bottom the same a long “ey” token? If so, can it be copied/pasted? Just curious…


#114

The piston as written isn’t going to get both vehicleID’s, but with a small tweak of the code you should be able to get both. The second code should be under $response.$response[1].id. If you have a problem getting it, let me know and I’ll look back through our previous conversation when I’m back in front of the desktop.


#115

I’m waiting to see exactly what ST’s new offering will be. webCoRE is a bit old and creaky in places and sees limited maintenance anymore, so if I can find the capabilities I need elsewhere, I may move on. I’m skeptical that either ST or Hubitat is going to give me 100% of what I need, but then what ever does?


#116

The refresh token on my screen doesn’t start with ‘ey’ and i tried both the access token and the stated refresh token and in both instances it threw an error. So I’m not sure if the app provides the refresh token that we are looking for. But I’m not familiar with this :smiley:


#117

Thanks for the clarification! This makes sense and I don’t believe I need to modify anything yet as the automations I’m doing is simple and only for my vehicle. If things change I’m sure I can try an make a slight tweak to the piston to have it log a additional Vehicle ID.


#118

I did use that token and it didn’t work - although I didn’t try reimporting your piston to check.


#119

Thanks. Even in the image on the Authla page, that so-called “refresh token” doesn’t appear to start with “ey,” so I doubt that it would work. I’m not sure what that token is, as the response to the POST request that produces the access token should include the actual refresh token itself.

I’ve removed any reference to Authla in the open for now.


#120

Strange it ran at 1am as scheduled and left me with a JSON error which has deleted all the data (and this broken my pistons)

08/03/2021, 01:01:22 +159ms
+1ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 0ms
+78ms ║RunTime Analysis CS > 28ms > PS > 10ms > PE > 39ms > CE
+80ms ║Runtime (52922 bytes) successfully initialized in 10ms (v0.3.110.20191009) (79ms)
+81ms ║╔Execution stage started
+106ms ║║Error retrieving JSON data part null
+108ms ║║Executed virtual command setVariable (1ms)
+111ms ║╚Execution stage complete. (30ms)
+113ms ║Setting up scheduled job for Tue, Mar 9 2021 @ 1:00:00 AM GMT (in 86317s)
+124ms ╚Event processed successfully (124ms)
08/03/2021, 01:01:19 +376ms
+4ms ╔Received event [Home].time = 1615165278680 with a delay of 695ms
+1840ms ║RunTime Analysis CS > 1728ms > PS > 48ms > PE > 65ms > CE
+1843ms ║Runtime (52984 bytes) successfully initialized in 48ms (v0.3.110.20191009) (1836ms)
+1844ms ║╔Execution stage started
+1950ms ║║Executed virtual command setVariable (2ms)
+1960ms ║║Executed virtual command setVariable (3ms)
+1964ms ║║Executed virtual command setVariable (2ms)
+1967ms ║║Cancelling statement #15’s schedules…
+1980ms ║║Calculating (string) Bearer + (string) null >> (string) Bearer null
+1983ms ║║Sending external web request to: owner-api.teslamotors.com/api/1/vehicles/
+1986ms ║║Executed virtual command httpRequest (3ms)
+1989ms ║║Requesting a wake up for Mon, Mar 8 2021 @ 1:01:45 AM GMT (in 24.0s)
+2036ms ║╚Execution stage complete. (191ms)
+2048ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:01:45 AM GMT (in 23s), with 1 more job pending
+2058ms ╚Event processed successfully (2058ms)
08/03/2021, 01:00:55 +897ms
+1ms ╔Received event [Home].:9ec73a46b11bd7fca0d29d69cf01d2ed: = @tokenSwitch with a delay of 63ms
+75ms ║RunTime Analysis CS > 29ms > PS > 9ms > PE > 37ms > CE
+77ms ║Runtime (53006 bytes) successfully initialized in 9ms (v0.3.110.20191009) (76ms)
+78ms ║╔Execution stage started
+112ms ║║Comparison (integer) 68 is (integer) 0 = false (1ms)
+113ms ║║Condition #103 evaluated false (6ms)
+114ms ║║Condition group #38 evaluated false (state did not change) (8ms)
+122ms ║║Comparison (integer) 68 is_greater_than (integer) 800 = false (1ms)
+124ms ║║Cancelling condition #106’s schedules…
+125ms ║║Condition #106 evaluated false (7ms)
+126ms ║║Cancelling condition #87’s schedules…
+127ms ║║Condition group #87 evaluated false (state changed) (9ms)
+159ms ║╚Execution stage complete. (80ms)
+166ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 22s), with 1 more job pending
+175ms ╚Event processed successfully (175ms)
08/03/2021, 01:00:55 +690ms
+0ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 0ms
+70ms ║RunTime Analysis CS > 19ms > PS > 8ms > PE > 42ms > CE
+72ms ║Runtime (53740 bytes) successfully initialized in 8ms (v0.3.110.20191009) (71ms)
+73ms ║╔Execution stage started
+93ms ║║Executed virtual command setVariable (2ms)
+98ms ║║Executed virtual command setVariable (1ms)
+103ms ║╚Execution stage complete. (30ms)
+105ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 22s), with 1 more job pending
+115ms ╚Event processed successfully (115ms)
08/03/2021, 01:00:54 +503ms
+0ms ╔Received event [Home].:9ec73a46b11bd7fca0d29d69cf01d2ed: = @tokenSwitch with a delay of 40ms
+58ms ║RunTime Analysis CS > 16ms > PS > 7ms > PE > 34ms > CE
+60ms ║Runtime (53672 bytes) successfully initialized in 7ms (v0.3.110.20191009) (59ms)
+61ms ║╔Execution stage started
+97ms ║║Comparison (integer) 823 is (integer) 0 = false (1ms)
+99ms ║║Cancelling condition #103’s schedules…
+99ms ║║Condition #103 evaluated false (7ms)
+100ms ║║Cancelling condition #38’s schedules…
+101ms ║║Condition group #38 evaluated false (state changed) (9ms)
+109ms ║║Comparison (integer) 823 is_greater_than (integer) 800 = true (1ms)
+111ms ║║Condition #106 evaluated true (5ms)
+112ms ║║Condition group #87 evaluated true (state did not change) (7ms)
+114ms ║║Cancelling statement #71’s schedules…
+118ms ║║Executed virtual command setVariable (2ms)
+122ms ║║Executed virtual command setVariable (1ms)
+133ms ║║Calculating (string) bearer + (string) eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Im9UaDR1ZXNoM2tlZXpvWDB1In0.eyJpc3MiOiJodHRwczovL2F1dGgudGVzbGEuY29tL29hdXRoMi92MyIsImF1ZCI6WyJodHRwczovL293bmVyLWFwaS50ZXNsYW1vdG9ycy5jb20vIiwiaHR0cHM6Ly9hdXRoLnRlc2xhLmNvbS9vYXV0aDIvdjMvdXNlcmluZm8iXSwiYXpwIjoib3duZXJhcGkiLCJzdWIiOiI1ZjE1MjYwZS1iZWQyLTRkNTItYWNhOS1hZmRjZmM4ODhhNTEiLCJzY3AiOlsib3BlbmlkIiwiZW1haWwiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicHdkIl0sImV4cCI6MTYxNTE2NTU1NCwiaWF0IjoxNjE1MTY1MjU0LCJhdXRoX3RpbWUiOjE2MTQ5NjA1ODF9.Sti_D56xLQnQYPylh8TtRXXhbo3hgVZdV-NyEV2rBEFgOA9n5KYQ8IkSTdwjF1j14Fr3pJvqjD7gcrP4LHnFCLV_XQnEVqxJQTH9fuoDo2frcHZZPMTggJjkUE5SLfkSkmriJCF8k6CgSfK9hE0QElk3A0Jjxmss4gmJOQ_lQXt1hHxJcqCp7vNrs8gwPs2eQ78KiWztm-WopiY3fXCOBS7y-zDRv8j0AEpQwWgHUjtqB-biY3JDBSVfFxE_z4sa8iJj3aMrPF5lfiX-tlK-svammM1Qpm25MXBiTecHR_G6k7w6qBAdrDqjV5-H2mZuQX-U9jl3Yypam_YklZ9DWg >> (string) bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Im9UaDR1ZXNoM2tlZXpvWDB1In0.eyJpc3MiOiJodHRwczovL2F1dGgudGVzbGEuY29tL29hdXRoMi92MyIsImF1ZCI6WyJod…[TRUNCATED]
+147ms ║║Sending external web request to: owner-api.teslamotors.com/oauth/token
+175ms ║║Executed virtual command httpRequest (40ms)
+176ms ║║Requesting a wake up for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 24.0s)
+193ms ║╚Execution stage complete. (131ms)
+195ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 23s), with 2 more jobs pending
+205ms ╚Event processed successfully (205ms)
08/03/2021, 01:00:54 +317ms
+0ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 0ms
+70ms ║RunTime Analysis CS > 20ms > PS > 8ms > PE > 43ms > CE
+73ms ║Runtime (52826 bytes) successfully initialized in 8ms (v0.3.110.20191009) (72ms)
+74ms ║╔Execution stage started
+94ms ║║Executed virtual command setVariable (3ms)
+100ms ║║Executed virtual command setVariable (1ms)
+105ms ║╚Execution stage complete. (31ms)
+107ms ║Setting up scheduled job for Tue, Mar 9 2021 @ 1:00:00 AM GMT (in 86345s)
+118ms ╚Event processed successfully (118ms)
08/03/2021, 01:00:53 +878ms
+1ms ╔Received event [Home].execute = recovery with a delay of 64ms
+65ms ║RunTime Analysis CS > 18ms > PS > 9ms > PE > 38ms > CE
+68ms ║Runtime (52907 bytes) successfully initialized in 9ms (v0.3.110.20191009) (66ms)
+69ms ║╔Execution stage started
+105ms ║║Comparison (integer) 0 is (integer) 0 = true (1ms)
+107ms ║║Cancelling condition #103’s schedules…
+108ms ║║Condition #103 evaluated true (8ms)
+109ms ║║Cancelling condition #38’s schedules…
+110ms ║║Condition group #38 evaluated true (state changed) (11ms)
+111ms ║║Cancelling statement #38’s schedules…
+117ms ║║Executed virtual command setVariable (4ms)
+121ms ║║Executed virtual command setVariable (2ms)
+140ms ║║Sending external web request to: auth.tesla.com/oauth2/v3/token
+145ms ║║Executed virtual command httpRequest (17ms)
+147ms ║║Requesting a wake up for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 24.0s)
+198ms ║║Calculating (decimal) 0.0 - (decimal) 2.0 >> (decimal) -2.0
+202ms ║║Comparison (datetime) 1615165254070 is_after (datetime) 1618676295076 = false (3ms)
+203ms ║║Condition #33 evaluated false (12ms)
+204ms ║║Condition group #32 evaluated false (state did not change) (14ms)
+213ms ║╚Execution stage complete. (145ms)
+215ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:01:18 AM GMT (in 23s), with 1 more job pending
+227ms ╚Event processed successfully (227ms)
08/03/2021, 01:00:46 +257ms
+14ms ╔Received event [Home].time = 1615165200000 with a delay of 46255ms
+6933ms ║RunTime Analysis CS > 6729ms > PS > 78ms > PE > 127ms > CE
+6936ms ║Runtime (52920 bytes) successfully initialized in 78ms (v0.3.110.20191009) (6910ms)
+6937ms ║╔Execution stage started
+6938ms ║╚Execution stage complete. (1ms)
+7150ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:00:00 AM GMT (in 1s)
+7170ms ╚Event processed successfully (7170ms)
08/03/2021, 01:00:30 +742ms
+5ms ╔Received event [Home].time = 1615165200000 with a delay of 30740ms
+7407ms ║RunTime Analysis CS > 7224ms > PS > 52ms > PE > 132ms > CE
+7410ms ║Runtime (52919 bytes) successfully initialized in 52ms (v0.3.110.20191009) (7390ms)
+7411ms ║╔Execution stage started
+7412ms ║╚Execution stage complete. (1ms)
+7515ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:00:00 AM GMT (in 1s)
+7532ms ╚Event processed successfully (7532ms)
08/03/2021, 01:00:08 +442ms
+24ms ╔Received event [Home].time = 1615165200000 with a delay of 8441ms
+11704ms ║RunTime Analysis CS > 11440ms > PS > 139ms > PE > 126ms > CE
+11707ms ║Runtime (52923 bytes) successfully initialized in 139ms (v0.3.110.20191009) (11677ms)
+11708ms ║╔Execution stage started
+11709ms ║╚Execution stage complete. (1ms)
+11908ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:00:00 AM GMT (in 1s)
+11926ms ╚Event processed successfully (11926ms)
07/03/2021, 01:00:26 +302ms
+4ms ╔Received event [Home].time = 1615078800000 with a delay of 26300ms
+3416ms ║RunTime Analysis CS > 3325ms > PS > 36ms > PE > 57ms > CE
+3419ms ║Runtime (53002 bytes) successfully initialized in 36ms (v0.3.110.20191009) (3405ms)
+3420ms ║╔Execution stage started
+3527ms ║║Calculating (decimal) 0.0 - (decimal) 2.0 >> (decimal) -2.0
+3534ms ║║Comparison (datetime) 1615078829822 is_after (datetime) 1618676295076 = false (4ms)
+3536ms ║║Condition #33 evaluated false (17ms)
+3537ms ║║Condition group #32 evaluated false (state did not change) (18ms)
+3569ms ║╚Execution stage complete. (149ms)
+3596ms ║Setting up scheduled job for Mon, Mar 8 2021 @ 1:00:00 AM GMT (in 86370s)
+3605ms ╚Event processed successfully (3605ms)
07/03/2021, 01:00:07 +653ms
+3ms ╔Received event [Home].time = 1615078800000 with a delay of 7651ms
+11508ms ║RunTime Analysis CS > 11293ms > PS > 94ms > PE > 122ms > CE
+11512ms ║Runtime (53004 bytes) successfully initialized in 94ms (v0.3.110.20191009) (11485ms)
+11513ms ║╔Execution stage started
+11514ms ║╚Execution stage complete. (1ms)
+11706ms ║Setting up scheduled job for Sun, Mar 7 2021 @ 1:00:00 AM GMT (in 1s)
+11842ms ╚Event processed successfully (11842ms)
06/03/2021, 01:00:41 +123ms
+0ms ╔Received event [Home].time = 1614992400000 with a delay of 41122ms
+207ms ║RunTime Analysis CS > 135ms > PS > 38ms > PE > 35ms > CE
+210ms ║Runtime (53000 bytes) successfully initialized in 38ms (v0.3.110.20191009) (209ms)
+211ms ║╔Execution stage started
+811ms ║║Calculating (decimal) 0.0 - (decimal) 2.0 >> (decimal) -2.0
+819ms ║║Comparison (datetime) 1614992441928 is_after (datetime) 1618676295076 = false (4ms)
+823ms ║║Cancelling condition #33’s schedules…
+824ms ║║Condition #33 evaluated false (20ms)
+825ms ║║Cancelling condition #32’s schedules…
+826ms ║║Condition group #32 evaluated false (state changed) (23ms)
+1073ms ║╚Execution stage complete. (862ms)
+1101ms ║Setting up scheduled job for Sun, Mar 7 2021 @ 1:00:00 AM GMT (in 86357s)
+1108ms ╚Event processed successfully (1108ms)
06/03/2021, 01:00:31 +482ms
+1ms ╔Received event [Home].time = 1614992400000 with a delay of 31480ms
+6393ms ║RunTime Analysis CS > 6217ms > PS > 82ms > PE > 95ms > CE
+6396ms ║Runtime (53002 bytes) successfully initialized in 82ms (v0.3.110.20191009) (6377ms)
+6397ms ║╔Execution stage started
+6398ms ║╚Execution stage complete. (1ms)
+6791ms ║Setting up scheduled job for Sat, Mar 6 2021 @ 1:00:00 AM GMT (in 1s)
+6812ms ╚Event processed successfully (6812ms)
06/03/2021, 01:00:06 +679ms
+17ms ╔Received event [Home].time = 1614992400000 with a delay of 6677ms
+15826ms ║RunTime Analysis CS > 15355ms > PS > 157ms > PE > 316ms > CE
+15829ms ║Runtime (53007 bytes) successfully initialized in 157ms (v0.3.110.20191009) (15800ms)
+15830ms ║╔Execution stage started
+15831ms ║╚Execution stage complete. (1ms)
+16086ms ║Setting up scheduled job for Sat, Mar 6 2021 @ 1:00:00 AM GMT (in 1s)
+16092ms ╚Event processed successfully (16092ms)


#121

I think the old piston was still activated by accident and might have caused issues - still not sure why this ran at 1am and got the JSON data error though. Ran it with test manually and it’s worked fine and recreated the token with no problem.


#122

If the old piston was still active (I actually had this happen to me during testing), it probably flipped the value of @tokenSwitch, causing both pistons to run from top to bottom again. That would cause all sorts of confusion.


#123

Yeah I’ll put it down to that and keep an eye on it. Seeing lots of strange JSON parse errors in Webcore lately i’ve never seen before though.