TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker and becoming a Supporting Member. For more info: Support TMC

Nikola, an Amazon Echo/Skill for your Tesla

Discussion in 'Model S: User Interface' started by wayner, Dec 31, 2016.

  1. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    Nikola is an Alexa skill created by Michael Kolowich and Andrew Payne to allow you to use an Amazon Echo to get information about your Tesla and to take certain actions on your Tesla, like start charging, unlock, lock, etc. This Skill leverages off of the Tesla Python JSON module written by Greg Glockner.

    It allows you to ask your Tesla things like:
    What is the charge level?
    How far can I drive?
    What is the temperature of my car?
    Unlock my car
    Lock my car
    Start charging

    This skill is written for deploying on a Cloud9 cloud server. I (wayner) have forked this code and made minor changes to be able to run the Skill on your own PC and then use a tunnelling application called ngrok to access the Skill. My fork is located here. Over time we will likely be merging my fork back into the main module.

    Enjoy and please post any bugs/issues or suggestions on how to improve.
     
    • Like x 7
  2. AEdennis

    AEdennis Active Member

    Joined:
    Jul 23, 2013
    Messages:
    2,127
    Awesome. I'll have to try this.
     
  3. The RosieHeart

    Joined:
    Oct 7, 2016
    Messages:
    22
    Location:
    Warkworth, Auckland, New Zealand
    Will this work on any Alexa?
     
  4. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    Yes, but currently there is a bit of config work for you to do such as setting up a back end process to handle the requests. Hopefully we will be able to set up one service for everyone to use but the issue currently is figuring out how to securely authenticate individual users.
     
    • Disagree x 1
  5. rog

    rog Member

    Joined:
    May 30, 2015
    Messages:
    294
    Location:
    Connecticut
    Thanks so much @wayner! I have this running on my Pi - using the basic plan from ngrok with a fix subdomain on the tunnel, it even survives Pi reboots now! :)
     
    • Informative x 1
  6. EdA

    EdA Model S P-2540

    Joined:
    Mar 24, 2011
    Messages:
    1,945
    Location:
    Massachusetts
    Will it work with multiple cars?

    @rog - what exact PI do you have?
     
  7. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    I have been running this on a Pi3. It should work on any Pi, but Pi3s would be recommended as they are much faster. But I would recommend that everyone try to implement on a Cloud9 server.

    Not sure about the multiple cars, probably not right now but we could try to add the code to do so I am guessing that right now it will pick whatever is the first car in your account.
     
  8. EdA

    EdA Model S P-2540

    Joined:
    Mar 24, 2011
    Messages:
    1,945
    Location:
    Massachusetts
    We have separate accounts believe it or not...my wife's car auto-locks but it would be handy to use this when I have to access her car instead of hunt for the keys!
     
  9. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    If you have separate accounts then this shouldn't be an issue. Here is how I would set it up - call one of them Nikola in the Echo Skill setup page. Call the other one something else. Then the car that the Skill is using will simply depend on the Invocation name that you use. The downside is that this is essentially using two skills so it will require using two instances of the python code and two instances of ngrok or a cloud9 server, but that shouldn't be a big deal, you just have to make a minor change in the code to run one of them on port 5001.
     
    • Informative x 1
  10. rog

    rog Member

    Joined:
    May 30, 2015
    Messages:
    294
    Location:
    Connecticut
    I have a Pi3, Model B.

    I tried that, but don't like the fact that I have to set the project to "public" in order to get it to work (I am using the authentication token directly in the code in order to be nice to the Tesla API).
     
  11. Cyclone

    Cyclone Cyclonic Member ((.oO))

    Joined:
    Jan 12, 2015
    Messages:
    4,781
    Location:
    Charlotte, NC
    It can with certain tweaks. The vehicle list is returned as an array and right now, the code is looking at the first car.
     
  12. Cyclone

    Cyclone Cyclonic Member ((.oO))

    Joined:
    Jan 12, 2015
    Messages:
    4,781
    Location:
    Charlotte, NC
    I created a fork in GitHub that allows it to accept a passed in token. Sadly, I can't get Alexa and Tesla to play nice to issue a token without an intermediary. If you can build a secure site to act as the intermediary, you can remove the token from within Cloud 9.

    Alternatively, you can use my fork and use a different type of intermediary that would forward Alexa's request but with your token added into the JSON request. You won't get this as multi-user Alexa skill, but you will be able to get around the concern of the service being Public.
     
    • Helpful x 1
  13. BizJet

    BizJet Member

    Joined:
    May 19, 2016
    Messages:
    106
    Location:
    Boston
    I have now merged all of @wayner's changes into the main branch of my original code in my GitHub repository:

    Nikola: An Alexa Skill (and Python intent handler) for Monitoring and Managing a Connected Tesla Automobile

    @wayner and I are working together to keep our versions coordinated. If you want to run this on Cloud9, then you'll find instructions in my repository. @wayner's version (here) has instructions and code for how to run it on a local machine and tunnel through to the internet. Otherwise, the code bases are identical and we'll endeavor to keep them that way.

    We're continuing to look for a collaborator who has the DevOps chops to help us turn this into a multi-user application!
     
    • Like x 1
  14. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    And someone who can help figure out the account linking that could facilitate the token handoff between Tesla and Alexa.
     
  15. sbtz

    sbtz Member

    Joined:
    Jan 18, 2016
    Messages:
    149
    Location:
    southern california
    I wonder if this is contributing to increased vampire drain? I lost 6mi overnight... (no other changes)
     
  16. Cyclone

    Cyclone Cyclonic Member ((.oO))

    Joined:
    Jan 12, 2015
    Messages:
    4,781
    Location:
    Charlotte, NC
    The original version would prevent my car from sleeping. I forked it to prevent it connecting to the car until Alexa actually makes a call to it. My car since goes to sleep, but overnight it seems the Cloud 9 instance stops. I haven't figured out why that instance stops and if that is what is letting my car go to sleep overnight.
     
    • Informative x 1
  17. rog

    rog Member

    Joined:
    May 30, 2015
    Messages:
    294
    Location:
    Connecticut
    Cool, thanks a lot! Would be great if you could add an option to provide a Tesla Auth Token instead of username/password as an environment variable. I still don't feel comfortable storing my Tesla credentials somewhere in the "cloud" (I know, old fashioned :-D )
     
  18. rog

    rog Member

    Joined:
    May 30, 2015
    Messages:
    294
    Location:
    Connecticut
    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.
     
    • Informative x 1
  19. Cyclone

    Cyclone Cyclonic Member ((.oO))

    Joined:
    Jan 12, 2015
    Messages:
    4,781
    Location:
    Charlotte, NC
    It's an easy change to do in your application.py file. Change line 36 from "tesla_connection = teslajson.Connection(TESLA_USER, TESLA_PASSWORD)" to "tesla_connection = teslajson.Connection(TESLA_USER, TESLA_PASSWORD,ASSIGNED_TOKEN)" and passing in your token in that third field. The first two fields can contain gibberish, they won't be used.
     
    • Helpful x 1
    • Informative x 1
  20. wayner

    wayner Active Member

    Joined:
    Oct 29, 2014
    Messages:
    2,062
    Location:
    Toronto
    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.
     

Share This Page