One of the really nice features of my car is the ability to control certain functions remotely from the smartphone or web app. This is especially handy if you want to defrost it on a cold day or cool it down on a hot day, amongst other things. For the ultimate convenience, I decided to hook Alexa up to the Nissan API so I could control my car with voice commands!


The smartphone app

I wrote a blog earlier this week and went in to quite a bit of detail on my electric car and how I've found driving one for almost 3 years, you can read Driving an Electric Vehicle - The Nissan Leaf if you want a bit more info on the car itself. Regular readers may remember that the API that controls my car has had some issues in the past. Back in February I worked with fellow hacker Troy Hunt to demonstrate how anyone in the world could take over my car using The vulnerable web API for my Nissan Leaf. With those issues now fixed, the API is back to being useful and I wanted to make it even more useful by integrating it with Alexa on my newly purchased Echo devices. There is nothing wrong with the app as such, but being able to simply ask Alexa questions instead of going through the chore of getting my phone out of my pocket seemed like a much better solution.

This is the main screen of the app where you can see battery level, whether or not it's charging and the current range.

app battery status screen


This is where you can operate the climate control or set a timer for it to come on in the morning or when you leave the office, for example.


app climate control screen


It's pretty straightforward and easy to use, but it could be easier!


Integrating with Alexa

I will do a more detailed post on how to create custom skills for Alexa, but for now I'm just going to release the source for my current implementation and give a demonstration so that others can hack around and tinker with the code if they like. I've created a repo on GitHub and you can head over to AlexaNissanLeaf if you want the code. Here is a demonstration of the kind of things I can now do.



These are some of things I can now ask Alexa:

  • Alexa, ask my car to preheat.
  • Alexa, ask my car how much power it has.
  • Alexa, ask my car how much range it has.
  • Alexa, ask my car to cool down.
  • Alexa, ask my car to send an update.
  • Alexa, ask my car if it's charging.
  • Alexa, ask my car if it's connected to power.

You can also substitute 'ask' with 'tell' or just say "Alexa, launch my car" to get a description of what the skill does.


Reverse Engineering the Nissan API

I've done quite a lot of work around reverse engineering the Nissan API, both the previous version called CarWings that was an XML API and the current incarnation called NissanConnect that is a JSON API. You can see some of my previous code to extract all of your telematics data here, for example. My trusted setup of using Fiddler as a proxy with a root certificate installed on my phone allows it to decrypt traffic coming out of the smartphone app for me to understand how everything works. I can then construct my own requests to issue against the API which is exactly what my Alexa skill does.


fiddler as a MiTM proxy


I can write a more detailed blog on how to do this so if there's interest, please let me know in the comments below.


Credit: I was originally creating my own web service in PHP for Alexa to call but I came across some code provided by Danny Tuppeny that made things a lot easier. This is now hosted in an AWS Lambda function and I essentially just hacked his code to do what I needed. Thanks Danny!