Tesla Connect 3.0 - Integration to Query Car Status - Deprecated, see below for replacment

i see you did fill in the query right here. nice.

I'm sure I didn't explain everything that well as I barely understand what I did :grimacing:

It was a long afternoon of Google and error (the modern version is trial and error)

1 Like

i believe all you need to do is this change.. not all that you did try it..

def query = ['endpoints':'charge_state;climate_state;closures_state;drive_state;gui_settings;location_data;vehicle_config;vehicle_state;vehicle_data_combo']

	def requestParameters = [
        uri: serverUrl,
        path: path,
        query: query,
        headers: [
            'User-Agent': userAgent,


            Authorization: "Bearer ${state.teslaAccessToken}"
        ]

i added two lines the definition of query and added it to the call..

it did not break a car with the old s/w version anyway

but thanks for doing all the legwork

1 Like

It is also concerning that they say they will start charging for use of the api next yr.. that is fine for websites like teslafi where you pay them for access, but not for us home users that go direct to their api like this implementation.. i know there probably will be an uproar but Elon basicly doesn't give a SH** what anyone else says.

1 Like

Weird... the first time I tested it didn't work, but I decided to double check my work, and it looks like the minimal change you suggested is working. I tested on both cars and it is good for both software versions. I probably messed up the cut & paste the first time.

So starting from the original app code at line 250:

private authorizedHttpRequestWithChild(child, Integer attempts, Map options = [:], String path, String method, Closure closure) {
    if (debug) log.debug "in authorize http req with child child=$child attempts=$attempts"
    
    if (attempts > 1) log.debug "Attempt: $attempts"
 
    if (descLog) log.info "authorizedHttpRequest2 ${child} ${method} ${path} attempt ${attempts}"
    try {
        def query = ['endpoints':'charge_state;climate_state;closures_state;drive_state;gui_settings;location_data;vehicle_config;vehicle_state;vehicle_data_combo']
    	def requestParameters = [
            uri: serverUrl,
            path: path,
            query: query,
            headers: [
                'User-Agent': userAgent,
                Authorization: "Bearer ${state.teslaAccessToken}"
            ]
        ]

The "def query" is inserted below line 256, on line 257. The "query: query," is inserted below what is now line 260, on line 261.

Also, if I may make an additional suggestion, down around line 508 and 514 there are commented-out debug log commands that will log the results of the vehicle_state and charge_state requests. I would think those should be left uncommented to make debugging easier in the future. If someone needs to debug the code, logging the response seems like a good idea. I'd also add a "log.debug "drive_state: $driveState" and "log.debug "climate state $climateState" just to be thorough.

version 3.52 on github.. pull using hubitat package manager...

  • v 3.52 fix to add extra parameter to vehicle_data request for changes in tesla's api. Necessry for version 2023.38.x onward.
  • thanks to Alan for doing some of the initial legwork.
2 Likes

Sorry for not getting the logs. Thank you Alan for doing it.

Does this solve the issue with reporting battery?

It should. Both of my cars are now on 2023.38.6 and updating normally.

Same with me. This integration is working great.

1 Like

Everything is working like it used to again. Thank you everyone!

I've updated to the latest version from HPM and the issue that I was having has been resolved but now when I go to the app, it gives this error:

Unexpected Error

An unexpected error has occurred trying to load the app. Check Logs for more information.

Error: OAuth is not enabled for this App

In the log:
app:2292023-11-19 07:21:40.886 PMerrorjava.lang.RuntimeException: OAuth is not enabled for this App on line 105 (method loginToTesla)

its not installed correctly you should not be using an endpoint for the token.. that is old .. not sure what you are trying to do.. that would need to goto your own server to get the token

I had a problem similar to the above where my app buttons are working but the current states were not updating, so I updated to the newest version via HPM and now the app is inaccessible.

Do I need to remove and re-install?

i am not sure what to tell you. upgrading woud not cause that issue.. the line number you show that error on only gets called if you enable the local endpoint option.. and that is not the normal way to get the token for the tesla.. that was for old configuraitons when you ran an app on a local machine using in php to get the token..

see below..

instead you should get your access and refresh token from some other site and plug it in the 2 fields shown above.

1 Like

For reference, I have used this site in the past to get tokens and it has worked well for me.

Though, I have not gotten one in a while. From what I remember, it was the last time Tesla changed the token process after there were some fixes to the driver to keep the tokens refreshing automatically. Since then, it has been pretty solid for me, and I have not had token issues since. I don't check the Tesla Hubitat integration much, because it works good for me, and I mainly use it in tandem with a contact sensor on my charger to remind me nightly if I didn't plug the car in. I also use it weekly to log the odometer into a google spreadsheet, just to keep track of my weekly mileage usage.

3 Likes

were you able to get it working?

Yes. I found out that I didn't need to remove and re-install.

I went to the app under Apps Code and then chose OAuth and was able to get back into the app and re-adjust all the settings and was able to get it working again.

Thank you so much for your help.

I have the app up and running but the control buttons on the Device page do not trigger any response even though all current states are displayed correctly. Not sure what I am doing wrong, and how do I incorporate Geofencing to automate Garage Door? Any assistance is appreciated. Thank you

Need to post debug logs of both app and car device during operation attempt. Otherwise we have no clue but most likely you have not set it up correctly.