Jump to content
dc15

Tesla Model S integration?

Recommended Posts

13 hours ago, zaphod said:

biggest security risk of this API is that a hacker could know where you car is, could unlock the car and start the car

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

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites
1 minute ago, zaphod said:

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

This. Let's try to deal with fact and not propoganda or silly generalizations gleamed from tidbits on the internet.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

FWIW.. I would love a tesla.. , if only the people on here would break their control4 systems more, and get me  to fix it.. maybe one day in about 20 or so years, I would be able to afford one

Share this post


Link to post
Share on other sites

The Model 3 should be available for under $40k and when you consider very low operating costs it should cost less than the average car over a typical ownership cycle.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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. :)

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...