Teslamate: Feature request: Automation for climate

Created on 10 Sep 2019  路  28Comments  路  Source: adriankumpf/teslamate

Hi,

Thanks a lot for an really great project.
I got an feature request that might or might not be possible to implement.
Winter is coming in Norway (Europe), and the Tesla app lacks the possibility to automation of the climate.

It would be really nice to implement something like this.

If the temperature outside the car goes under 0 degress celcius, and the car is at geolocation "work" or at home. And the time is 07:00 or 16:00. Turn on climate automatically 15min before leaving home or work.

Is this possible to implement in teslamate?

Thanks again

/Jo Christian

idea

All 28 comments

This is possible with the limitation that the car needs to be online to get the outside temperature reading i.e. it would have to be woken up by TM.

I imagine it to work like this:

At 07:00 (and at 16:00) check the status of the car:

... if "online" proceed otherwise wake up the car
... if the outside temperate is below 0 degrees Celsius proceed 
... if the car is located at "Home" or "Work" proceed

Finally start the climate control system. 
Stop it after 15 minutes (if the car is not driving already).

Does that sum up your suggestion correctly?

Edit: If TeslaMate knows that the car is not located at those geo-fences it could abort to early to avoid waking up the car unnecessarily.

Hi @adriankumpf,

Yes that sum's up my suggestion. :-)
Sorry for not being to precise on my suggestion in the first post.

No worries! Just wanted to make sure I understood everything. That would definitely be a useful feature!

There are a few things to keep in mind when implementing it. Plus, the UI part needs to be figured out. If I can find the time, I'll see how far I can get :-)

No worries. I don't expect anything.
Got the idea when leaving work today. Starting to get colder and colder these days :-(
This should have been an basic feature implemented in the car or in the Tesla app tbh.

This should have been an basic feature implemented in the car or in the Tesla app tbh.

Yes, I think so too. It would be great to have some kind of automation feature built-in.

Do you think the ios shortcuts and curl scripts can help manage this? Not difficult from a Tesla api perspective.

Sure. It does not matter how the API is called, right? But there are still a few things to consider, for example:

  • after sending the wake_up command the car is not "online" immediately
  • the climate control system must not be turned off if the car is driving
  • you don't want to wake up the car if if you know beforehand that is not parked at one of the given locations

etc.

This would actually be an awesome feature. But would it not be better to check for the temperature inside the car?

@espenu Inside or outside the car would not matter much I think?
Reason for outside is the risk of the door handles freezing when it get's really cold. Not sure if this is something that could happen.

I just want to raize the question if TeslaMate is meant for this. For sure this can be implemented, but I do like the focus on logging. For Automation/remote control there are other applications available.
I do not want to have additional dead weight which may reduce stability

That's a really good point. TM is primarily a logger. Until now it only reads data from the vehicle and doesn't send any commands to it. Maybe it makes sense to put the automation part in an extra application or even use an existing solution.

Hi,
Yes I can agree on this.
Can anyone suggest an existing solution like TM that can do this?
I don't want to give my credentials away. All the other solutions that I have found is like this.
I want to run an application on my own hardware.

What I want to look into is the Tasker Plugin for Tesla, credentials are stored locally from what I read so far.
I first try to avoid the use of paid SW. So i set up a task to share route information with Tesla App and therefor with Tesla. Up to now I have to wait for my delivery before further testing :-)

I have looked at Tasker Plugin earlier. But I'm not convinced that the credentials are stored locally. Where did you find this information?

I've found this shell script: https://github.com/dfuhrer2007/TeslaAutomation Not as polished as the Tasker plugin of course but maybe it gets the job done anyway :D

@adriankumpf
Nice find. I will look at this. Just need to create some crontab's and it's up and running :-)
Thanks

I have looked at Tasker Plugin earlier. But I'm not convinced that the credentials are stored locally. Where did you find this information?

In this Reddit post the Author claims:
"Email and API token are stored on the device. If the user requests, the password is encrypted with a key in the Android Keystore and stored on the device. The local password storage is required for Remote Start, otherwise you'd have to re enter your password to start the vehicle"

So I looked a bit deeper in Tasker and Tesla API and played a little bit with it, because I am not 100% convinced that the Tasker Plugin for Tesla, is safe :-)
Get Token and Refresh is working directly in Tasker. Other stuff not yet implemented nor tested. I will do a code clean-up (remove Auto-Tools dependencies if easy way around it on all things) and more testing.
As soon as this is done and I found a way to automate the deletion of my token in the exported data I will share it on GitHub.

So I looked a bit deeper in Tasker and Tesla API and played a little bit with it, because I am not 100% convinced that the Tasker Plugin for Tesla, is safe :-)
Get Token and Refresh is working directly in Tasker. Other stuff not yet implemented nor tested. I will do a code clean-up (remove Auto-Tools dependencies if easy way around it on all things) and more testing.
As soon as this is done and I found a way to automate the deletion of my token in the exported data I will share it on GitHub.

So here is the link to the Tasker Profile I set up so far: https://github.com/JakobLichterfeld/Tesla_API_in_Tasker
Token works fine, more features to come when my Tesla is connected to my account :-)

HomeAassistant would be a great program to do this. Lots of automations possible. Unfortunately the Tesla component that is available is not as smart with polling as Teslamate, causing large drain of the battery. @adriankumpf It is a long shot, but would you be able to integrate your teslamate in HA component. The current developer has been silent for months.

HomeAassistant would be a great program to do this. Lots of automations possible. Unfortunately the Tesla component that is available is not as smart with polling as Teslamate, causing large drain of the battery. @adriankumpf It is a long shot, but would you be able to integrate your teslamate in HA component. The current developer has been silent for months.

Implementing a custom HomeAssistant component is definitely out of the scope of this project. If you don't need the component to poll the car maybe a custom bash script that calls the Tesla API would be sufficient? You could start with something like this: https://github.com/dfuhrer2007/TeslaAutomation

There should be no reason to need a dedicated HomeAssistant component for teslamate. Two options that come to mind immediately for me:

  • Consume the MQTT topics published by teslamate

  • Perhaps (and I don't know enough about the teslamate internals for this) teslamate could serve a cache of the Tesla API endpoint data on the same endpoints that the real Tesla API normally would be queried, and we could just put a host file entry in to point to teslamate instead of Tesla's API?

Either way, I quite happily have both Teslamate and HASS components working together and it's great. To do so, I have increased the polling interval significantly in HASS (scan_interval: 1800). This is because my automations don't need fine grained vehicle monitoring to work, they can work with this more coarse interval. That said, if it ever came to teslamate providing cached data when queried like the tesla API, I'd point HASS at teslamate and drop the scan interval way back down.

If you don't need the component to poll the car maybe a custom bash script that calls the Tesla API would be sufficient? You could start with something like this: https://github.com/dfuhrer2007/TeslaAutomation

I definitely wouldn't recommend this - it would not make integration with HomeAssistant particularly easy. You'd need to define a heap of shell commands, scripts and then parse all of the output into parameters which would be super fragile. Manually forking the HASS Tesla component and fixing the polling logic would be much more effective if there's no easy way to integrate with teslamate, however given teslamate has already done the hard work here it would be great to leverage it for other tools which poll Tesla's API if possible.

Perhaps (and I don't know enough about the teslamate internals for this) teslamate could serve a cache of the Tesla API endpoint data on the same endpoints that the real Tesla API normally would be queried, and we could just put a host file entry in to point to teslamate instead of Tesla's API?

That is an interesting idea but TM wasn't made for this. The provided MQTT topics are the way to go to get the current vehicle stats. If more measurements are needed that are currently not published via MQTT, extending the existing logic is no effort.

You'd need to define a heap of shell commands, scripts and then parse all of the output into parameters which would be super fragile.

I was referring to scripts that send commands to the Tesla API (like starting the climate control). Parsing responses of those requests is not _that_ complicated. All it takes is checking the status code (200?) and evaluating the result property of the returned JSON payload (either true or false) .

I was referring to scripts that send commands to the Tesla API (like starting the climate control). Parsing responses of those requests is not _that_ complicated. All it takes is checking the status code (200?) and evaluating the result property of the returned JSON payload (either true or false) .

I think the confusion here is that I'm explaining why it's not the done thing in HomeAssistant - using scripts to glue automations together is highly discouraged for these reasons. The approach that is used is to use common interfaces, preferably the REST API but if not, subscribing to MQTT topics. Shell scripts are not going to cut the mustard for HomeAssistant integrations, since components clearly define values and their types for a given interface, and building that from a shell script is effectively building an entire custom component for the purpose of running a command to avoid the official component - it would be much easier to just copy your connection logic into the official component.

Ok, got it. I agree with that.

So I looked a bit deeper in Tasker and Tesla API and played a little bit with it, because I am not 100% convinced that the Tasker Plugin for Tesla, is safe :-)
Get Token and Refresh is working directly in Tasker. Other stuff not yet implemented nor tested. I will do a code clean-up (remove Auto-Tools dependencies if easy way around it on all things) and more testing.
As soon as this is done and I found a way to automate the deletion of my token in the exported data I will share it on GitHub.

So here is the link to the Tasker Profile I set up so far: https://github.com/JakobLichterfeld/Tesla_API_in_Tasker
Token works fine, more features to come when my Tesla is connected to my account :-)

Just as an update: I released a new version of Tesla_API_in_Tasker which is now tested and included more features, climate will be in on of the next. Up to now it is not as clean as I want it to be, possible cleaner with use of JSON possible

You can close this. This is part of 32.12.4 where charging can be scheduled to end by a certain time and HVAC can pre-condition for use by a certain time.

https://www.reddit.com/r/teslamotors/comments/dmj6h1/tesla_firmware_201932124_includes_power_increase/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olivercho picture olivercho  路  4Comments

bahree picture bahree  路  3Comments

Highlander1694 picture Highlander1694  路  3Comments

kongomongo picture kongomongo  路  5Comments

spacecosmos picture spacecosmos  路  5Comments