Alexa Home Skill for Node-RED

Following on from my last post this time I’m looking at how to implement Alexa Home Skills for use with Node-RED.

Home Skills provide ON/OFF, Temperature, Percentage control for devices which should map to most home automation tasks.

To implement a Home Skill there are several parts that need to created.

Skill Endpoint

Unlike normal skills which can be implemented as either HTTP or Lambda endpoints, Home Skills can only be implemented as a Lambda function. The Lambda function can be written in one of three languages, Javascript, Python and Java. I’ve chosen to implement mine in Javascript.

For Home Skills the request is passed in a JSON object and can be one of three types of message:

  • Discovery
  • Control
  • System

Discovery

These messages are triggered when you say “Alexa, discover devices”. The reply this message is when the skill has the chance to tell the Echo what devices are available to control and what sort of actions they support. Each device section includes it’s name and a description to be shown in the Alexa phone/tablet application.

The full list of supported actions:

  • setTargetTemperature
  • incrementTargetTemperature
  • decrementTargetTemperature
  • setPercentage
  • incrementPercentage
  • decrementPercentage
  • turnOff
  • turnOn

Control

These are the actual control messages, triggered by something like “Alexa, set the bedroom lights to 20%”. It contains one of the actions listed earlier and the on/off or value of the change.

System

This is the Echo system checking that the skill is all healthy.

Linking Accounts

In order for the skill to know who’s echo is connecting we have to arrange a way to link an Echo to an account in the Skill. To do this we have to implement a oAuth 2.0 system. There is a nice tutorial on using passport to provide oAuth 2.0 services here, I used this to add the required HTTP endpoints needed.

Since there is a need to set up oAuth and to create accounts in order to authorise the oAuth requests this means that is makes sense to only do this once and to run it as a shared service for everybody (just got to work out where to host it and how to pay for it).

A Link to the Device

For this the device is actually Node-RED which is probably going to be running on people’s home network. This means something that can connect out to the Skill is probably best to allow or traversing NAT routers. This sounds like a good usecase for MQTT (come on, you knew it was coming). Rather than just use the built in MQTT nodes we have a custom set of nodes that make use of some of the earlier sections.

Firstly a config node that uses the same authentication details as account linking system to create oAuth token to be used to publish device details to the database and to authenticate with the MQTT broker.

Secondly a input node that pairs with the config node. In the input node settings a device is defined and the actions it can handle are listed.

Hooking it all together

At this point the end to end flow looks something like this:

Alexa -> Lambda -> HTTP to Web app -> MQTT to broker -> MQTT to Node-RED

At this point I’ve left the HTTP app in the middle, but I’m looking at adding direct database access to the Lambda function so it can publish control messages directly via MQTT.

Enough talk, how do I get hold of it!

I’m beta testing it with a small group at the moment, but I’ll be opening it up to everybody in a few days. In the mean time the code is all on github, the web side of all of this can be found here, the Lambda function is here and the Node-RED node is here, I’ll put it on npm as soon as the skill is public.

12 thoughts on “Alexa Home Skill for Node-RED”

    1. Because it’s doesn’t support Home Skill’s as far as I can tell so you need to prefix your commands with a skill name which is not as natural, and you need to open your Node-RED instance up to the internet to accept the incoming HTTP requests. My system connects out with MQTT so doesn’t need any port forwarding to work through NAT firewall/routers.

      Also as I mentioned in my previous post it doesn’t work if you’ve moved the Node-RED admin route. My pull request to fix that has been sat for over 2 weeks with out any response.

  1. Hi there,

    I found the node on NodeRed.org, but I can’t seem to find the skill in the Alexa app. Is it out yet? If not, is there any estimate of release?

    Best regards

    1. The skill is with Amazon for approval, they don’t give estimates on how long that will take.

      The node was published to allow the beta test team and Amazon to test the skill. The will be another post when it is publicly available.

    1. Still waiting for a reply after resubmitting for approval. First time took over 3 weeks, I expect even longer with Christmas in the middle this time

  2. Great work Hardillb, installed node-red & tested working but awaiting Amazon Skill, looking forward to it, keep up the good work!

    Thanks

  3. Can’t wait for Amazon to approve this skill, really looking forward to using it on my raspberry pi with node-red!

  4. Can’t wait to test the skill! Also it would be nice if there was any way to add electronic locks. I’m already using Homebridge to open my Lockitron, if I could do the same with alexa it would be awesome.

    1. There has been a suggestion that new verbs will be added to the Home Skill to allow Open/Close actions in the future

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>