Tesla Integration to Query Status and Send Commands to Your Car

Just to make note of what I ended up doing to connect Tesla data to hubitat, in case it’s of interest to anyone.

I’m using Teslamate (GitHub - adriankumpf/teslamate: A self-hosted data logger for your Tesla 🚘) to collect various metrics and statistics about my car. Part of that install includes an mqtt server, which Teslamate publishes various information about the car. Teslamate also includes geofence capability, so I can geofence and location of my house.

My goal was an integration that would be quick enough for presence detection to open my garage door on car arrival and include functionality that wouldn’t keep the car awake by polling. I was less interested in being able to control the car from my hub.

So I ended up modifying an existing mqtt driver out in the community to collect the published metrics from Teslamate. I also added functionality to detect distance from my house based on the car’s long/lat coordinates. I ended up relying on the Teslamate geofence capabilities, but I had originally planned to use this distance calculation to do car presence detection.

Teslamate seems to be receiving data via some sort of streaming API from Tesla so it has been super reliable and quick to detect presence and open the garage door on arrival.

Just throwing it out there as an option to the Tesla owners out there, in case anyone is looking for alternatives for data collection.

3 Likes

So are you running TeslaMate with HomeAssistant and then sending the data to Hubitat?

The auto garage opening does sound interesting to me. Though, I was more concerned with setting up a system that would remind me nightly if the car was not plugged in to charge overnight. I don't have my car yet, but I assume I am not going to plug it in when I get home from work if I plan to go somewhere else in the evening. This would mostly be beneficial if I was planning on going somewhere else, decided at the time to not plugin to charge, and then decided not to go to that place later in the evening and forgot to plug in. This may not be an issue for me, but since I am waiting patiently on Tesla for delivery, I'm just trying to think of any case where having Hubitat integration would be beneficial. I do also like the idea of having car features in Hubitat too.

1 Like

No Home Assistant involved, just Teslamate collecting data and Hubitat pulling it in via mqtt.

I’ve only had my car for a couple weeks now, but I’ve pretty much just been plugging it back in whenever I return, even if I’m only down a couple percent. It only takes a second to plug/unplug. I am pulling charge state via mqtt as well though.

I see, I looked a little more into install and I see now that it runs standalone in a docker container. I was assuming it needed HA to run the backend, and didn't think it was standalone.

Do you have the ability to control car functions from Hubitat via TeslaMate? Or is it purely a data logging system? From the looks of it, it seems to be just data logging. Though, I wasn't sure if there were any options to control that the dev just didn't list on the Github.

Thanks for sharing your findings btw, it seems like a good option to get some more data about the car aside from what it / the app tells us. Could definitely be beneficial to learn more about driving and charging habits.

Data collection only, there isn’t any control ability.

1 Like

I have been using Trent Foley's original driver/app and have noticed that the setThermostatSetpoint isn't always accurate when sent to the car. Does yours have the same issue or is it accurate? See Tesla Car to Hubitat - #4 by makirules for more information.

as far as i can tell mine is working.. i believe the set therm. was not in trents original driver?

Weird. I wonder why mine isn't working correctly.

i added extra codce to do a wake command first.. have you tried that

Yes I have. Here is my rule:

I am just saying, if I set it to 67, it will actually set it to 66. Same goes with 76, it will actually set to 75 in the Tesla app.

i dont use mine that way i use it through a dashboard/. try using 67.0 maybe a rounding error.




also i meant i added the wake command directly in the settemp command in the code.

it could be a rouding error in how your version of the code converts to celsius

I just tried 66.0 and it still changes to 64 on the Tesla app itself:
image

Mine is also set to Fahrenheit:

it is definately rounding errors in the driver..

Setting to F has nothing to do with it.. The api only accepts temps in C so there are obviously rounding errors in the conversion as I mentioned.

I changed from number to double in the code to preserve the digits and now it is working correctly. You will need to get my version of both the driver "teslaconnect" and the device from here

2 Likes

Also, very interesting that the api seems to allow setting a different temp for driver and passenger.

I have not seen anywhere in the screens in the car that allows that..Or in the app for that matter?

Has anyone?

In my model 3 there is dual climate for driver and passenger. If I tap on the temp along the bottom of the screen a slider pops up. Just to the right of the slider there is a sync button. If that is toggled it adds two temp controls along the bottom status bar, allowing for dual climate control. Interesting it can be set with Hubitat, because I don't think you can control them separately from the app

1 Like

I have not seen the ability to set dual temperatures on the app, just in the car when the sync button is not selected.

Thank you for the updated driver and app.

Update: I just updated both these and it works flawlessly. Thanks again!

1 Like

Trying to get the token sorted, I've gone through all the steps for the python script above but get this back as a response - I'm on Windows10 for reference.

Traceback (most recent call last):
File "C:\tesla-oauth2-main\tesla.py", line 268, in
login(args)
File "C:\tesla-oauth2-main\tesla.py", line 225, in login
code = parse_qs(resp.headers["location"])["https://auth.tesla.com/void/callback?code"]
File "C:\Python310\lib\site-packages\requests\structures.py", line 54, in getitem
return self._store[key.lower()][1]
KeyError: 'location'

I try to repeat the steps again and now get this error (which I was getting before)
Traceback (most recent call last):
File "C:\tesla-oauth2-main\tesla.py", line 268, in
login(args)
File "C:\tesla-oauth2-main\tesla.py", line 127, in login
raise ValueError(f"Didn't post auth form in {MAX_ATTEMPTS} attempts.")
ValueError: Didn't post auth form in 7 attempts.

Edit - also tried doing it in a WSL fresh install and get the same message

Not sure where to go next?

Ya its no.longer working. I've been just copying my token into the device panel from teslafi periodically.

I use an android app called Tesla Tokens. It is free (I think teslafi is paid?) and seems to work well. Works for 45 days or so then I have to manually set it again. Been using it for a few months now (since I have had my car) and everything seems to work pretty well