Jump to content
C4 Forums | Control4

Tesla Model S integration?


dc15

Recommended Posts


  • Replies 64
  • Created
  • Last Reply
12 hours ago, Cyknight said:

Actually I'd say it's a bigger risk that he'll stall the car mid-drive on the highway. :o

Except I don't think you can stop the car from the API. Only keyless start.

The security on Teslas has, so far, been pretty good. There was a hack last year that required wired access to the CAN and there was another hack found recently but that seemed to require wifi access and it was quickly patched. 

Link to comment
Share on other sites

29 minutes ago, AnOutsider said:

Silly me. I've been following Tesla since 2009 and still missed the fact that they made Jeep vehicles as well.

Right, and because it's repeatable on one - there's no reason to worry about another? You can 'sigh' and be denigrating all you want, but it won't make a difference.

My point is that Tesla is going to be careful releasing anything publicly because they have been problems with their own functions as it is (auto pilot). Any API has to be rock solid in every respect, from it's intended function to it's safety to it's security.

 

They will be careful to the extreme, because they can't afford NOT to be.

Elon Musk can keep paying for quite some time, but his money (let alone the company's) isn't THAT endless.

 

https://www.ft.com/content/80c45ad6-7ef0-11e6-bc52-0c7211ef3198

http://fortune.com/2016/05/31/telsa-modelx-lawsuit/

http://www.hybridcars.com/tesla-sued-over-solarcity-purchase/

http://www.dailymail.co.uk/news/article-3778869/Tesla-shareholder-sues-Elon-Musk-using-2-6BILLION-Tesla-stock-prop-failing-solar-panel-company.html

https://electrek.co/2016/10/04/tesla-is-being-sued-for-age-discrimination-by-a-former-engineer/

http://www.timesunion.com/cars/article/Tesla-Sued-by-Norway-car-owners-as-speed-not-9237139.php

 

Some of them are absolutely ridiculous of course, but guess what - reason-ability and common sense seems to be gone in the world of law these days.

Make no mistake - I love Tesla for what it's done so far, for pushing the envelope - and certainly hope that they can set a precedent in Michigan with the whole dealer model.

Just don't think I'll take a seat in Musk's rocket just yet.

Link to comment
Share on other sites

  • 3 weeks later...

I have now completed this Control4 - Tesla integration.  It uses RyanE's Webevents driver and the Chowmain TCP/IP generic driver.

The Upper LED on the two-button indicates charging status of Tesla: black/off = not plugged in, green = plugged in but not charging, red = plugged in and charging, purple = charging complete.  Pushing the button starts charging.  This acts as a reminder that the car is not plugged in - this two button is in my Master Bedroom ensuite so I see it before I go to bed.

The Lower LED on the two-button is for the climate system.  Pushing the button turns the climate system on.  The LED is off/black if the climate system is not on and is red when the climate system is on.  I start the climate system when I wake up in the mornings to warm up the car and warm the battery, at least when it is cold outside.

Obviously an improvement would be to convert this into a proper C4 driver which I may attempt if I am able to become a C4 driver developer.

Link to comment
Share on other sites

  • 3 weeks later...
On 27/10/2016 at 10:44 AM, zaphod said:

I have now completed this Control4 - Tesla integration.  It uses RyanE's Webevents driver and the Chowmain TCP/IP generic driver.

The Upper LED on the two-button indicates charging status of Tesla: black/off = not plugged in, green = plugged in but not charging, red = plugged in and charging, purple = charging complete.  Pushing the button starts charging.  This acts as a reminder that the car is not plugged in - this two button is in my Master Bedroom ensuite so I see it before I go to bed.

The Lower LED on the two-button is for the climate system.  Pushing the button turns the climate system on.  The LED is off/black if the climate system is not on and is red when the climate system is on.  I start the climate system when I wake up in the mornings to warm up the car and warm the battery, at least when it is cold outside.

Obviously an improvement would be to convert this into a proper C4 driver which I may attempt if I am able to become a C4 driver developer.

Hi Zaphod,

Fellow Canadian S owner here.

Congratulations on getting this done. I was looking to do some C4/Tesla integration myself and stumbled on this thread.

I was wondering if you'd be willing to share your driver? :) I have a Pi in my garage dedicated to downloading dashcam video which could also run the API calls.

Do you simply login to the Pi every 90 days or so to rotate your auth token?

Please let me know, thanks!

Link to comment
Share on other sites

I am willing to share my code - the stuff in C4 just hits a web URL that runs a bit of python code that calls the Tesla API.  You have to have Apache2 running on the Pi and you have to have it configured to run python code.  Once you do that when you hit http://piserver/cgi-bin/startcharge.py it will execute that python script on the Pi.  But to do that you need to have the Chowmain Generic TCP driver running.  That allows you to link a HTTP POST or GET to a C4 event, like pushing a button.  

This is my startcharge.py file that starts the car charging.  The getstates.py file then just gets the charge state and climate state and sets LEDs on a C4 switch appropriately.

#!/usr/bin/env python

import requests

token="abc123_putyourtokenhere"
VehicleID="1234567"
url= "https://owner-api.teslamotors.com/api/1/vehicles/"+VehicleID+"/command/charge_start"
head = {"Authorization": "Bearer "+token}
r = requests.post(url,headers=head)

print "Content-type: text/html\n\n"
print "Charging Started <br />"
execfile("/usr/lib/cgi-bin/getstates.py")

In terms of the auth token - right now it is just hard coded (as you can see above) so I have to manually change it every 90 days but eventually I plan to error trap a call to the API that would see if the first call is good, if not it would then get a new auth token if the call fails.  You could actually get a new token every time you try to hit the API but that seems like a waste to me.

But you need two drivers to do this - RyanE's webevents driver which allows you to get info into C4 and the Chowmain TCP command driver to get info out of C4.

PM me if you want more info.

Link to comment
Share on other sites

I was just thinking about this a little more and you might actually be able to issue commands to the Tesla API directly from C4 using the TCP driver without using a Pi at all.

Using the TCP driver for HTTP POST commands there are two text fields - one for the URL and one for the data.  I am assuming that the header would go in the data field but I don't know exactly how you would format it.  It might be everything inside the parentheses here:   ("Authorization": "Bearer 012abd5689fe454545452323232") or maybe it is just (Authorization: Bearer 012abd5689fe454545452323232).  But there would be a lot of typing that would be prone to errors and you can only see a handful of characters in the text entry box.  The same thing for the URL, there would be lots of stuff to type in as it is a rather long URL.  And then there is the issue that you raised in that every time the token would expire you would have to redo all of your code and retype it in as there is no way to copy and paste.

Link to comment
Share on other sites

Hey @zaphod,

Thanks for the code snippet!

That's a good point, we could talk to the Tesla API directly... but yeah, it does lack some flexibility.

I'll check out that TCP driver soon.  I'm just getting my C4 system up at home, so I can't say this is my number one priority. :) I'm still trying to get my Sonos stuff controlled. :)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.