Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Nikola, an Amazon Echo/Skill for your Tesla

This site may earn commission on affiliate links.
That seems to be another disadvantage of the Cloud9 implementation (at least for the free version)... Inactive Workspaces · Cloud9

They kill inactive workspaces (I am assuming that also applies to Python processes running in them) after 2 hours.

That would do it. With it killing the workspace so soon, I cannot determine if sleeping is a result of my change or simply the workspace dying off as my car is currently awake and charging. Maybe later today I can test that out. I'll end up deleting my fork soon and rebuilding it now that the master has been changed so I don't lose the enhancements @BizJet and @wayner have incorporated.
 
I don't know why this would be causing battery drain or car sleeping issues. If you are not invoking the skill then it shouldn't be polling the API at all, never mind interacting with the car.

As the master is written, it is calling the car immediately when the Python instance is run. It is not waiting for an Alexa call. That was one of the changes I made in my fork.
 
But the python code is just runs once and then it sits and waits for an invocation from Alexa, doesn't it?

I would imagine it all depends on what timeout values Cloud9 and/or Tesla use since there is no explicit close on the connection. Even though it opens and there is request to send (and JSON is supposed to be stateless), the underlying http call is not closed and Tesla may view that similarly to having the app open and prevent sleep until a timeout is hit on the connection. But this is conjecture, not definitive.

I should also note that if this is indeed what is preventing sleep, preventing the connection until a call is made only delaying the problem. Which is likely what is happening in my case since I eventually hit the timeout and Cloud9 stops running my workspace and the car eventually sleeps.

I wonder if we incorporate an @ask.on_session_closed we could explicitly disconnect and maybe that would make a difference?
 
I would imagine it all depends on what timeout values Cloud9 and/or Tesla use since there is no explicit close on the connection. Even though it opens and there is request to send (and JSON is supposed to be stateless), the underlying http call is not closed and Tesla may view that similarly to having the app open and prevent sleep until a timeout is hit on the connection. But this is conjecture, not definitive.

Alexa to Cloud9 is using HTTP 1.1 (console has "POST / HTTP/1.1" 200). If hopping to Tesla is also HTTP 1.1, that supports persistent connections to (1) prevent building/tearing down HTTP connections (somewhat expensive) for burst traffic and (2) prevent SSL handshaking for each request (significantly expensive). Implementing persistence at my full time employer significantly improved response time, in particular b/c the SSL handshake is not repeated.
 
I'll end up deleting my fork soon and rebuilding it now that the master has been changed so I don't lose the enhancements @BizJet and @wayner have incorporated.
@Cyclone, feel free as you make enhancements to generate a pull request back to the main code, so we can merge your enhancements into the main code base. That way, we'll be all running off the same code and benefit from each other's insights!
 
My Cloud9 instance has not gone to sleep in 36 hours or so - perhaps that is because I keep it up in a browser window on a PC that stays booted up?

The Amazon Lambda solution will use something called zappa that facilitates building flask-ask applications. But it still has the issue of getting authentication that prevents us from using a centralized solution.

Raisin' it up, waxen it down!
 
Yes, I am just putting together the how-to and should have it posted later today. I have done this in Linux but I want to be able to do a Win version as well. This should be even easier for Windows 10 users as they pretty much have Linux enviro if they install the Bash prompt for Windows 10 Anniv edition.
 
  • Like
Reactions: SteveW25561 and rog
@Cyclone, feel free as you make enhancements to generate a pull request back to the main code, so we can merge your enhancements into the main code base. That way, we'll be all running off the same code and benefit from each other's insights!

I redid it from the current master and think I created the pull request this time (it asked me if I want to merge the request, so I assume that pull is out there). If I did that incorrectly (this is the first GitHub project I've ever worked on), please let me know. Thanks!
 
I think I originally was trying to merge updates into my own fork, rather than back into the master. Could you check now? There should be 3 pull requests. Two for using OAUTH tokens (I forgot to update the Read Me in the original pull request) and one because I noticed geopy.distance is being used, but the Cloud9 setup instructions didn't include installing it, so I added that in.

I also have an update to make the Tesla Connection more multi-user friendly but haven't put that in yet since I didn't want to change too many things at once, especially since the problem of configuring Alexa to send in individual tokens hasn't been solved yet.
 
I stumbled across this thread while looking for a solution for generating access tokens for a Alexa -> Tesla Skill that I have been developing. I really like the work thats been done here and think the ideal solution is to have this running on a Lambda instance (as opposed to Cloud9, PC, Pi etc.). That would help make it a solution that non-techies can use. Hope you guys can figure out the authentication issues.
 
Somebody at Ford must be watching this thread:
The first Alexa applications will show up later this month in Ford’s Focus electric car and its two plug-in hybrids, the Fusion Energi and C-Max Energi. Those cars will be equipped with an “Alexa at home” app that enables drivers from their couch to start their cars, lock and unlock the doors and check driving range and how much charge is left in the battery.

From inside their home, a driver will say, “Alexa, ask MyFord Mobile to start my car.” Alexa will respond: “Sending start command to your car.”
Alexa, Take the Wheel: Ford Models to Put Amazon in Driver Seat
 
Yes, I am just putting together the how-to and should have it posted later today. I have done this in Linux but I want to be able to do a Win version as well. This should be even easier for Windows 10 users as they pretty much have Linux enviro if they install the Bash prompt for Windows 10 Anniv edition.

Any updates on this? :) My Pi seems to be crashing on a daily basis now (I might just have overloaded it with dash button watcher, home automation stuff etc.)...
 
@wayner: Thanks so much for this! (and of course to Michael Kolowich, Andrew Payne). This is really amazing.

I managed to install this on my Mac, and as well on an Raspberry Pi. It's working well so far but I'm really not too sure what I'm doing!!

Regarding using ngrok: (this app is totally new to me.) Do you just run ngrok once, and the URL it generates lasts forever? It seems too easy! I'm wondering if the host computer reboots, or the python script is aborted, and then restarted, will the ngrok URL work again? Or, do we have to regenerate the URL for each reboot or restart of the host computer or python script?
Edit: I asked the developer of ngrok: it has to be continuously running in order to keep the url open, and that url goes away when it stops. Any suggestions for a more permanent way to set a URL to get to your local installation? I'm familiar with dynamic dns services (I use no-ip.com), but not sure if it will pass an https: request.

I'm trying to see if running on a Mac gives faster response than on the Raspberry Pi 3. I'm trying to see how to execute the python script on startup for either the Mac or Rasp Pi. Any pointers out there? Right now, I manually run:
Mac: python /Applications/nikola-tesla-alexa-master/nikola.py email password
Rasp Pi: python ./home/pi/Documents/nikola-tesla-alexa-master/nikola.py email password

Thanks again for this! It works great - I just need to make it reboot proof. Sorry for the basic questions!
 
Last edited: