HankLloydRight
No Roads
Hi there,
unfortenately i cannot send any code to this Forum - i've coded a tiny PHP-Script who can communicate with the Tesla API. Anybody interested?
I'm very interested! Can you PM me? thanks!
You can install our site as a web app on your iOS device by utilizing the Add to Home Screen feature in Safari. Please see this thread for more details on this.
Note: This feature may not be available in some browsers.
Hi there,
unfortenately i cannot send any code to this Forum - i've coded a tiny PHP-Script who can communicate with the Tesla API. Anybody interested?
<?php
class SimpleTeslaAPI {
// Quick&Dirty Tesla API
// 9.1.2016 (V1.1)
// von [email protected]
var $token;
var $vehicleID;
// Implementierung
function SimpleTeslaAPI() {
// !!!!!!!!! set in token and vehicle_id (example out of mobile app "Remote S" !!!!!!!!!
$this->token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$this->vehicleID = "xxxxxxxxxx";
}
private function curlexec($command,$mode="GET",$params=array()) {
$url = 'https://owner-api.teslamotors.com/';
$ch = curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$params['vehicle_id']=$this->vehicleID;
if ( $mode == "POST" ) {
if ( $command == "oauth/token" ) {
curl_setopt($ch,CURLOPT_URL, $url.$command);
} else {
if ( $command == "wake_up" ) {
curl_setopt($ch,CURLOPT_URL, $url."api/1/vehicles/".$this->vehicleID."/wake_up");
} else {
curl_setopt($ch,CURLOPT_URL, $url."api/1/vehicles/".$this->vehicleID."/command/".$command);
}
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Authorization:Bearer ".$this->token) );
}
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $params);
} else {
if ( $command == "vehicles" ) {
curl_setopt($ch,CURLOPT_URL, $url."api/1/vehicles");
} else {
curl_setopt($ch,CURLOPT_URL, $url."api/1/vehicles/".$this->vehicleID."/data_request/".$command."?".join("&",$params));
}
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Authorization:Bearer ".$this->token) );
}
$result = curl_exec($ch);
$rc=curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return json_decode($result);
}
//base functions
function vehicles() {
return $this->curlexec("vehicles","GET");
}
function wake_up() {
return $this->curlexec("wake_up","POST");
}
//data-requests
function charge_state() {
return $this->curlexec("charge_state","GET");
}
function climate_state() {
return $this->curlexec("climate_state","GET");
}
function drive_state() {
return $this->curlexec("drive_state","GET");
}
function gui_settings() {
return $this->curlexec("gui_settings","GET");
}
function vehicle_state() {
return $this->curlexec("vehicle_state","GET");
}
// commands
function charge_port_door_open() {
return $this->curlexec("charge_port_door_open","POST");
}
function charge_standard() {
return $this->curlexec("charge_standard","POST");
}
function charge_max_range() {
return $this->curlexec("charge_max_range","POST");
}
function set_charge_limit($percent) {
return $this->curlexec("set_charge_limit","POST",array("percent" => $percent ));
}
function charge_start() {
return $this->curlexec("charge_start","POST");
}
function charge_stop() {
return $this->curlexec("charge_stop","POST");
}
function flash_lights() {
return $this->curlexec("flash_lights","POST");
}
function honk_horn() {
return $this->curlexec("honk_horn","POST");
}
function door_unlock() {
return $this->curlexec("door_unlock","POST");
}
function door_lock() {
return $this->curlexec("door_lock","POST");
}
function set_temps($tempDriver, $tempPassenger) {
return $this->curlexec("set_temps","POST",array("driver_temp" => $tempDriver,"passenger_temp" => $tempPassenger ));
}
function auto_conditioning_start() {
return $this->curlexec("auto_conditioning_start","POST");
}
function auto_conditioning_stop() {
return $this->curlexec("auto_conditioning_stop","POST");
}
function sun_roof_control_state($state) {
return $this->curlexec("sun_roof_control","POST",array("state" => $state ));
}
function sun_roof_control_percent($percent) {
return $this->curlexec("sun_roof_control","POST",array("state" => "move", "percent" => $percent ));
}
function remote_start_drive($password) {
return $this->curlexec("remote_start_drive","POST",array("password" => $password ));
}
// deprecated
function trunk_open() {
return $this->curlexec("trunk_open","POST",array("which_trunk" => "rear" ));
}
}
// Main
$tesla = new SimpleTeslaAPI();
print_r($tesla->honk_horn());
Has anyone developed or is willing to develop a simple web site that just turns on the climate control when one goes to that site. That allows one to put a bookmark icon on the home screen and turn on the climate control with a single button press. Someone did this for the LEAF and it avoids having to wait for the Nissan app to start up and log n. While the Tesla app is faster than Nissan's, it would still be nice to have this most used feature available with a single button press and no waiting. For the LEAF, the person who did it was willing to put the script on his own server if you were willing to trust him with your login credentials or he gave clear directions about how to install it on your own server. If this already exists, I'd appreciate a pointer to it. If someone is willing to write it, I can find amd give a pointer to what was done for the LEAF, if that would help.
Has anyone developed or is willing to develop a simple web site that just turns on the climate control when one goes to that site. That allows one to put a bookmark icon on the home screen and turn on the climate control with a single button press. Someone did this for the LEAF and it avoids having to wait for the Nissan app to start up and log n. While the Tesla app is faster than Nissan's, it would still be nice to have this most used feature available with a single button press and no waiting. For the LEAF, the person who did it was willing to put the script on his own server if you were willing to trust him with your login credentials or he gave clear directions about how to install it on your own server. If this already exists, I'd appreciate a pointer to it. If someone is willing to write it, I can find amd give a pointer to what was done for the LEAF, if that would help.
Has anyone developed or is willing to develop a simple web site that just turns on the climate control when one goes to that site. That allows one to put a bookmark icon on the home screen and turn on the climate control with a single button press. Someone did this for the LEAF and it avoids having to wait for the Nissan app to start up and log n. While the Tesla app is faster than Nissan's, it would still be nice to have this most used feature available with a single button press and no waiting. For the LEAF, the person who did it was willing to put the script on his own server if you were willing to trust him with your login credentials or he gave clear directions about how to install it on your own server. If this already exists, I'd appreciate a pointer to it. If someone is willing to write it, I can find amd give a pointer to what was done for the LEAF, if that would help.
This sounds like exactly what I am looking for. I'm fairly computer literate. Please post instructions. Probably best to do it here in this thread as others may be interested.I wrote a simple app called "restla" that creates a local webpage (only for your car) and creates a link for every one of the REST commands. These links can be bookmarked for quick access without having to go to the full menu page which is shown below. You would have to install and configure the app on your laptop and keep it continually running as I have no interest in running this as a service for others. I also wrote a command line "teslacmd" that you can run in a terminal window to turn climate control on and off and another called "climatemon" that monitors the temperature for you in real time. The apps are all written in Javascript so they work on Mac, Windows, or Linux. PM me if you are interested in trying it out. Takes a little bit of computer skills to install and configure (command prompt and text editing skills) but you don't have to be a programmer or system administrator. I could modify the app to make it look like an actual button to press rather than a simple html link to click but that sounds like what you want anyway.
View attachment 107512
This sounds like exactly what I am looking for. I'm fairly computer literate. Please post instructions. Probably best to do it here in this thread as others may be interested.
Thanks.
Thanks. I will give it a try.It's all part of the package of open source software called "TeslaMS". I put it up on github at hjespers/teslams · GitHub
There is another thread on the forum for this software at TeslaMS tools for telemetry data visualization so post questions there.
You will need to install Node.js first from https://nodejs.org (I recommend the LTS "Long Term Support" version).
Once NodeJS is installed start a terminal window and run "npm install -g teslams" or on a Mac or Linux run "sudo npm install -g teslams". Sudo will prompt you for your root/admin password. This is only ever used once for the install.
Once installed you will be able to run "restla -u <username> -p <password>" with your TeslaMotors username (your email) and password.
This should start a web server which you can access at http://localhost:8766
After that the only OS-dependent trick is to make sure the restla app always starts when you reboot or when you login. Also you can setup a config file so that you don't have to specify username and password every time as command line options.
If you have a computer that could run the Apache2 web server, and that includes a $5 Rapsberry Pi Zero, then this is pretty easy to set up and I will give you some code to do this in Python. You just create a Python script put it in your /usr/lib/cgi-bin folder and hit the URL http://myserver/cgi-bin/climeon.py . And you can learn a bit about how to easily write scripts that you can execute from pretty much any web browser.Has anyone developed or is willing to develop a simple web site that just turns on the climate control when one goes to that site.
Has anyone developed or is willing to develop a simple web site that just turns on the climate control when one goes to that site....
Something like that. Tesla really should allow third party apps to be registered and generate OAUTH tokens for them.@hans
You have an own client_id and client-secret, packed in the last line of teslams.js ??
People get nervous if they see the code talking to an external server other than Tesla. The point is to make the software self contained and not dependant on anything else but Tesla's normal mobile app infrastructure.What about storing the secrets on a server and having the code query for them? Secrets in clients is not ideal.
I think I can manage that if you will give me the code. Is there a security issue in that the script will presumably have to have my account and password in it? I'm not worried about someone turning on my climate control, but if they can unlock my car via this website, I would be worried.If you have a computer that could run the Apache2 web server, and that includes a $5 Rapsberry Pi Zero, then this is pretty easy to set up and I will give you some code to do this in Python. You just create a Python script put it in your /usr/lib/cgi-bin folder and hit the URL http://myserver/cgi-bin/climeon.py . And you can learn a bit about how to easily write scripts that you can execute from pretty much any web browser.
I think I can manage that if you will give me the code. Is there a security issue in that the script will presumably have to have my account and password in it? I'm not worried about someone turning on my climate control, but if they can unlock my car via this website, I would be worried.
By access to the site, do you mean just knowing the URL or do you mean ability to log on to the server. Only the former worries me.The ability to do anything with the API is predicated upon having a security token. You get a security token by sending username and password. Once you have that security token, you can do anything the mobile app can - so yes, someone with access to that site could indeed unlock your car.
That said, if you follow good security practices with configuring and maintaining the web site, you're unlikely to be exposed too much. Certainly not any more than having the mobile app in the first place. If you have that concern, then you may want to just disable mobile access altogether.