Tesla Integration to Query Status and Send Commands to Your Car

Teslafi is free as well

1 Like

I'm pretty sure it's a paid service. There's a 2 week free trial, or 4 weeks if you use someone's referral code (*).

(they did just add an iOS & Android app that will generate an API refresh token for you, and have a Chrome extension that will get one for you)


(*) Personally, I think TeslaFi is really great and use it on both my cars. I describe it here: https://teslamotorsclub.com/tmc/threads/best-tesla-apps.210626/#post-5088042
The map at that link is the lifetime travels of The BlueS, which sadly was in an accident last week.

FWIW, my username is a TeslaFi referral code.

sorry about the car.. you could be right .. i dont remember paying but that must mean it is coming due soon.

Just managed to set it up using TeslaFi.

The other one looks like TeslaPy but not had any luck yet with the code but I'm not a linux person so probably my error not theirs. Don't know if anyones tried it?

Anyone consider adapting the refresh token logic from Pulling data out Tesla Powerwall?

Thanks for this awesome app. Works great doing all of my Tesla automation for Hubitat. I’m wondering if there’s a way to completely disable logging. Turning off debug only eliminates some of the debug logs. Thanks!

With debugging off

dev:6762022-02-24 08:17:34.906 debugprocessData: [state:asleep, motion:inactive, speed:0, vin:5YJYGDEE1MF#####, thermostatMode:off]
app:6262022-02-24 08:17:34.354 debugauthorizedHttpRequest GET /api/1/vehicles/14931015######## attempt 0
dev:6762022-02-24 08:17:34.346 debugExecuting 'refresh'

With debugging on


dev:6762022-02-24 08:17:07.300 debugRefresh time currently set to: 1-Hour
dev:6762022-02-24 08:17:07.297 debugExecuting 'initialize'
dev:6762022-02-24 08:16:43.460 debugprocessData: [state:asleep, motion:inactive, speed:0, vin:5YJYGDEE1MF######, thermostatMode:off]
app:6262022-02-24 08:16:42.770 debugauthorizedHttpRequest GET /api/1/vehicles/14931015######## attempt 0
dev:6762022-02-24 08:16:42.763 debugExecuting 'refresh'

Has this app/driver been updated to adjust charge rate? Would love to automate charging my Tesla on excess solar generation after powerwalls are fully charged. I’m already using Tesla Powerwall Manager https://darwinsden.com/powerwall/ so I can get SOC data from there.

It is possible to set charge limit, but not charge rate. Though if I remember correctly, being able to adjust the charge rate via the app is a fairly recent feature. I'm sure this driver is older than that, but I'm not sure if Tesla even supports adjusting charge rate in their API. Though, I assume they would, since the phone app offers that functionality now.

1 Like

It appears that my vehicle ID with Tesla changed yesterday. Tesla Connect calls started to fail. I had to manually generate a new token, and after re-adding to the app, a different vehicle device with a different ID was created. Has anyone had/seen this happen yesterday (or at all)?

Ok, odd… now the new vehicle device has started to fail and the old one has started working again (luckily I hadn’t yet switched my rules over and removed it).

I think this happened to me once. At one point my automations quit working. In my 'start the car' command I have a loop that tries 3 times, and if it fails all 3 times it notifies me that the climate didn't start. I went in, saved a new token (old one wasn't expired though), and re-added the car. Though, I had to repair it with all my automations and then it started working properly again. Not sure what happened, I just chocked it up to some weird anomaly and didn't think about it any further. Though the last 5 months or so have been completely fine ( I got my car in Aug of 2021, so I haven't had it that long)

I've had this a couple of times. it went so.far as to delete the old one. now i.save the.network id.

When it happens you can change the network id of the new device to the old one, thus leaving all rules and automations intact.

Genius! Saving my network ID now, incase this happens again

I am interested in learning more about how to do this. I just installed the Tesla drivers and was able to see my car within HE, but I need to know the location of the car in order to do what I want.

My ultimate goal is if the car is at home, charging, and it is between 4 PM and 9 PM, stop charging.

My utility company charges an arm and a leg between 4 PM and 9 PM. I have the car se to start charging at 9, but sometimes during the mid-day I need a little top off and don't want the top off to run into the high peak $$ time. If you have anything on how you fed the data from TeslaMate's MQTT into HE, I'd love to see it. I too am a TM user. Just need this last integration information.

All that can.be done with only this. Go back and look at my rule examples.

Are you referring to post 108 for your example? I don't have the Home Connect and am wondering how you set your Mod 3 arrives. Is this a presence detection based on pinging an IP address?

it has nothing to do home connect as far as i know that is just to open the garage door. one of the attributes of the driver is presence it will show like a normal presence sensor as present or not depeing on whether the car is local.. tesla always knows the location of your car.

it should just be transparent as long as you set your home address in the car

ie

if (data.vehicleState) {
if (debug) log.debug "vehicle state = $data.vehicleState"

    	sendEvent(name: "presence", value: data.vehicleState.presence)
        sendEvent(name: "lock", value: data.vehicleState.lock)
        sendEvent(name: "odometer", value: data.vehicleState.odometer.toInteger())
        sendEvent(name: "sentry_mode", value: data.vehicleState.sentry_mode)
        sendEvent(name: "front_drivers_window" , value: data.vehicleState.front_drivers_window)
        sendEvent(name: "front_pass_window" , value: data.vehicleState.front_pass_window)
        sendEvent(name: "rear_drivers_window" , value: data.vehicleState.rear_drivers_window)
        sendEvent(name: "rear_pass_window" , value: data.vehicleState.rear_pass_window)

ie

Screenshot 2022-03-28 204105

1 Like

As noted in some of the other replies, you may be able to do this with the other code, I needed real time presence updates to effectively open my garage door when my car arrived, and I wasn't going to be able to do that via polling alone. Also keep in mind that this code is for reading data about the car only, it won't be able to control things like Kahn's code can.

So here's the very rough code - keep in mind that I'm not a dev. I made the bare minimum updates in places to get this to work, some of the stuff is unnecessary, and the code may not be entirely clean. Basically this code could be cleaned up some, but it works well enough for me, so I don't have a strong desire to do so.

Some things would need to be updated in the code:

  • There is a lat and long value in the code at line 389 and 390, I was originally going to use this to calculate a distance from a location (home or otherwise). Ended up using teslamate's geofence capability instead. The code that calls this function should be commented out at the moment.
  • There's some assumptions about geofence locations made. I only have a single geofenced location, so the code assumes if it gets any geofence data, that it is at home. Would need to tweak this code if there were multiple teslamate geofence locations configured.
  • Some of the attributes are kind of noisy, especially when driving - long, lat, and odometer. These can be commented out. I don't have perf issues with the hub as far as I can tell, but I also have this integration configured on a fairly empty hub that only does cloud integrations.
  • I had one instance where teslamate reported the car leaving and then returning, I imagine some sort of junk data from the TeslaAPI. Result was the incorrect presence change triggered a rule to open my garage door unnecessarily. There is a 2 minute delay in the code to try and prevent phantom updates like this, however as a warning, as with any sort of automation that controls doors or locks, use at your own risk and think about the implications/protections that can be put in place via rules. It has only happened once in a year of ownership and hasn't been an issue for me, but it doesn't mean it couldn't be an issue for someone else.

Basically use at your own risk, I got it working for me, it may not work for anyone else without tweaks.

1 Like

version 1.2 on git hub with these changes

lgk 3/29/22 add attributes for longitude and latitude
so maybe people without home connect can add some rule machine rules with math to determine if you are home or approaching home to open garage door.

  • speed is already there as was heading but not as attributes that can be queried by rules so added that as well.
  • also some more info if debugging is on

i am assume a rule like..

if longitude between x and y and latitude is between x and y
speed is < xxx and > zzz
heading is xxx or > y and < x (depeding on precision and trial and error)

and motion is active.. etc. open garage door.

you also may need to increase polling time.. not sure how the load on the hub or if the tesla api will get too pissed if you poll too often.. May be cheaper to buy homelink ... lol

And probably more reliable. (I just use HomeLink in our two Tesla cars and let them automatically open/close the garage doors)

1 Like