Skip to content
Aaron B. Russell edited this page Jan 15, 2019 · 7 revisions

Setting up the Alexa Skill

by Toby Riding

(Huge thanks to Toby for putting this updated version of the guide together! --Aaron)

Introduction

The purpose of this guide is to show you how to make an Alexa Skill for your Nissan Leaf. This means that instead of using your smartphone app to contact your Leaf you can ask your Amazon Alexa device to do things like check how many miles you have left in your battery, charge the car if it’s plugged in when at home, or ask the car to preheat for you as well as many other options. A list of these will appear at the end of the guide.

This guide does make a few assumptions though. First things first. Have you set up your Leaf so it can speak to your smartphone app? You have? Great! The rest will be easy. If not, then you’ll have to sort that out first. You’ll need to know your Nissan Connect username and password, this is essential. You’ll also need to know what your Amazon username and password is for your Alexa devices, this is usually the same as your normal Amazon account. Got that? Great.

The last thing you’ll need is to download a small file that has been prepared for you by Aaron B. Russell, you can thank him later but for now download this zip file. Unzip the contents, but keep a copy of the zip file too as you'll need that later.

Ready? Deep breath.

Here we go.....

You are going to be copy and pasting data between two Amazon websites, so I’d suggest getting two browser tabs or windows ready to go.

You are going to need to sign up to two Amazon services, don’t worry these are free and will only take a few moments. You’ll be signing up to Amazon Web Services (AWS) and the Alexa Developer Console (ADC).

Go to https://aws.amazon.com/console/ and click on the large Create Free Account button.

Follow the instructions.

Use your normal Amazon account details for this, that way you won’t forget the login and also, it’ll be the same account details that you use to speak with your Alexa device. Once done, log in to the AWS console.

Believe it or not this next part is VERY important! Make sure that your location in the top right corner is set to Ireland. Yes, even if you aren’t located in Ireland, just select Ireland.

Click Services and then search for Lambda. Select Lambda.

Click Create Function.

Choose Blueprints.

Search for color – yes, the American spelling.

Choose alexa-skills-kit-color-expert

Click Configure.

Under Name, give it a nice name, Nissan_Leaf for example

Under Role, choose Create new role from one or more templates

Under Role Name, name your role, for example, Leaf

Under Policy Templates, choose Simple microservice permissions from the template list

Leave this page open and go to your other open browser tab or window as you are now going to login to your Alexa Developer Console account. Make sure this is the same account you have on your Amazon Alexa device, it should be the same account details as you used before so just enter those details and login.

Click on the Alexa tab and select Alexa Skills Kit.

Click the blue Create Skill button

Under Skill Name, name your skill (Nissan_Leaf for example) and choose the Custom model.

Choose Start from Scratch

Click on Invocation Name

In the Invocation Name textbox, type my caror any another invocation name appropriate to you (like the leaf, my leaf, or whatever you like). This will be used to make requests to Alexa like “Alexa, ask THE LEAF to heat up” or “Alexa, ask MY CAR how many miles I have left”.

On the left-hand side, scroll down and select the JSON editor.

Open the folder you unzipped earlier, and drag and drop the intentschema.json file you downloaded earlier onto drag and drop a .json file.

Click Save Model.

On the left-hand side, scroll down and select Endpoint.

Choose AWS Lambda ARN (Amazon Resource Name) as the endpoint

Copy the Skill ID (you can click on Copy to Clipboard if you want) and go back to your other open AWS window.

Scroll down until you see Alexa Skills Kit Trigger and paste the Skill ID into the Skill ID text box.

Scroll down and click Create Function.

Scroll back up to the top of the page and copy the ARN code. Then go to the other open ADC window.

Paste the ARN Code into the Default Region text box and click Save Endpoints.

Go to the other open AWS window.

Click on Nissan_Leaf (or whatever you decided to call your function), then scroll down.

Under Function Code use the select Code entry type pulldown menu to select Upload a .Zip file

Click the Upload button and select the zip file you downloaded earlier (the zip file itself, not the unpacked version).

You’ll then see more items appear in the window, and an error saying File not found /index.js.

Don't panic, we'll fix that error.

Click the first file in the list, then hold down the Shift key on your keyboard and click the last file so that they're all highlighted, like this:

Drag and drop them all onto the top folder in the list, and the list of files should look like this:

Now we'll remove the second folder called AlexaNissanLeaf-master as we don't need that. Right click it, and choose Delete.

When asked if you're sure, say yes.

The list of files should now look like this:

Under Runtime, choose Node.js 4.3

Under Handler, if it’s not already there, in the text box type index.handler then click Save.

Scroll down to Environment Variables and enter the required information. For example, under key enter username then in the box to the right enter your Nissan Connect username. Do that for the following items. I’d suggest copy and pasting both the key and the relevant information as the case of the characters is vital, like the upper case I in the applicationId key box.

applicationId = [the skill ID from ADC]
regioncode = NE
username = [your Nissan Connect username]
password = [your Nissan Connect password]
scheduledEventArn = [the arn code from the top right corner of your AWS window]

Scroll down and under Basic Settings, set the timeout to 1 minute.

Click Save and go back to the ADC window.

Click on the Build tab, then on the right-hand side click on the Build Model button, this may take a moment to do its thing, but it will notify you when it’s ready, it usually only takes a few seconds.

Click on the Test tab. Select Development in the Skill testing pulldown menu.

Here comes the fun part!

In the Alexa Simulator text box, type a command as if you were speaking it to your Alexa Device. For example, ask the car how much battery it has then press enter. In just a few seconds time, if everything is working, you should get a text response and code appear, which you can ignore really, but you’ll also hear the voice of Alexa giving you the answer to your question.

If you get a response to your question then all is well and you can sign out of the two windows, both ADC and AWS.

If not then... oh dear! What usually goes wrong is that you haven’t copied and pasted some bit of vital information EXACTLY as it’s expecting. A lowercase something here, the incorrect ARN code, etc etc etc. Don’t panic. Just go back to the top and follow it again, clicking on the various points and checking that the information entered is all correct. If you have found and corrected the problem, just click Build Model again and then Test it via the simulator again.

If you are still having issues then reach out to the friendly and helpful UK Nissan LEAF Owners Group over on Facebook.

Enjoy!

Acknowledgments

This guide was written by Toby Riding based on the original guide by Matt Thompson and the follow up by Lewis James Ash. I thank them both for the original hard work they did.

None of this would have been possible would it not have been for the amazing Alexa coding and deciphering of the Nissan app coding by Scott Helme in the first place. We all owe you a huge debt of gratitude.

Finally, raise a glass to Aaron B. Russell who made some improvements, fixed some nasty coding bugs, and provided you with the downloadable files to make this super easy.

-- Toby Riding, January 2019

Commands

Just like you did in the Test of your Alexa skill you can ask the car quite a few questions with a few permutations of speech. Give these a go but if it doesn’t work, don’t be afraid to ask ‘the leaf’ in a different way as it might understand what you are asking for then!

For example, Alexa ask my car (or "ask the leaf", etc, depending on the invocation you chose)...

  • to warm up
  • to pre heat
  • to turn the heater on
  • to start the heaters
  • to make it toasty for me
  • to heat my seat up
  • to turn the air conditioning on to cool down for me
  • to turn the air conditioning off to stop preheat
  • for an update
  • how many miles are in the tank how far can I drive
  • how much range
  • how much charge it has
  • what percent battery
  • is it charging
  • if it's plugged in
  • to start charging
Clone this wiki locally