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
  • GetTemperatureReading 1
  • GetTargetTemperature 1
  • GetLockState 1
  • SetLockState 1

1 These actions are listed as only available in the US at the moment.

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.

EDIT

The skill should now be generally available in the UK,US and Germany

54 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

  5. Once it is out in the wild, i’d love to translate it to german. Let me know if you need any help with that.

  6. Ben

    I want a skill where Alexa returns the recognised string into node-red via MQTT. I will then parse the string using regex. This will give me the ability to do anything which node red can do with voice activation. Then I want to send Alexa a string via MQTT and she speaks it. With bi-directional MQTT, I can do anything I want and build my own skills. Since you have been through the skills process, do you reckon that such a skill is possible within the existing constraints? It would give me complete voice control of all my node-red functions, because , as you are aware, string slicing to recognise keywords is easy in node red.

    1. This is not going to happen, Amazon have already removed the ability to get the a raw speech to text output (you can still force it by adding a intent of all #’s, but the match quality is crap, the intents help with the matching because it gives the engine a target to aim for). Also the interfaces for building skills are HTTP or Lambda so you would need to shim it to get a MQTT feed which you then need to make synchronous (which isn’t that hard but it does break a lot of point of MQTT).

      The best you can do is the node-red-contrib-alexa node I mentioned in my other post, but that does look to be an abandoned project as I’ve asked the author to add other maintainers to fix things and just been ignored.

      1. errrr without that feature Alexa to me is a useless paper weight……………. doh !!!!

        1. Depending on what you are using it for you could use OpenHab2 to do the mqtt triggering as the Openhab Alexa skill has just gone live. It’s commands like turn on / off / dim / set to 20% etc. Then you can have a lot of rules to handle the commands but I imagine you would use node-red for that.

          1. Those are exactly the same features that the Node-RED Alexa Home Skill offers so once Amazon finally approve it there would be no need to have the OpenHab bit in there as well.

          2. Teaches me to read the whole thread instead of searching terms. Fingers crossed it comes soon as that will be helpful, more so than the openhab one.

    2. Did you ever get anywhere with recieving the text from Alexa. I want to use a pi zero to make a usb keyboard that types messages from Alexa. Most alexa home automation seems to be just on/off.

      1. You can not do that with the smart home skill api, you just get the pre set command states (on/off, set temperature, set %, set colour). If you want more freedom you need to use the other api and then you end up with having to use the skill name e.g. “Alexa, ask foo to type hello world” rather than “Alexa, turn on helloWorld” and having to define the sentence structure

      2. No.

        I contacted Amazon Developers and they gave a the stock reply. I am currently using node_red_contrib_google_home_notify. You can send Google Home any string you want and it speaks it…. great fun. But as yet, the other way around i.e. spoken string received in node_red is not to my knowledge possible.

  7. Very interesting approach, but bit of a worry as well. As there is a shared webserver/appserver in there that sends out MQTT messages to my home automation system, it is possible for the admin owning this system to do anything he/she wants on my system. Or do you foresee people running their own webserver? that is not how I interpreted it until now.

    1. Yes theoretically the admin (me) could inject commands, but then again so could any Alexa Admin at Amazon for any skill, but you have to decide what level of trust works for you.

      If this sort of thing worries you that much, you probably should never have attached a 3rd party black box with a built in streaming microphone and the ability to directly control devices (see how Alexa interfaces with Wemo/Hue devices) to your lan.

      This service has been specifically designed to be multi-user so it is way more complicated (e.g. oAuth) than a single user system would need to be. If you want to own the whole stack you could build your own much simpler version and look at the Jasper project to replace the Alexa. Else most of the source for this project is up on github and linked to in the post if you want to have a look at it.

      Once approved this service and node will allow those slightly less technical users or those that just don’t want to invest the time and effort to build their own to quickly/simply hook up their Node-RED instance to Alexa.

  8. is this still active? will there be a release anytime soon? waiting for a solution like that desperately πŸ™‚

  9. Great work! I am using this on a local RasPi to tie into several mqtt devices in my home including automated sprinklers and window blinds. For the blinds automation though it seems cumbersome to say “turn on/off the blinds”. Is there any way to add a new action so that it will respond to “open/close the blinds”?
    Thanks,
    Bruster

    1. No, the verbs are all controlled by Amazon. The list of verbs can be found here. I’m looking at adding the lighting colour/temperature control at some point, but it may have to wait until I’ve done the equivalent node for Google Home.

      1. If you add the colour verbs you will be my hero! I have been wanting something to flick the colour to red-alert when my phone rings πŸ˜‰

  10. Great work, thanks for the effort you have put in to this. When this is tied in to Node Red there are so many possibilities

  11. I followed all the steps to install your skill with Amazon Echo, updated node-red with your nodes, added your nodes to an existing working flow, and got stuck. The Alexa Home node does not output anything at all. I followed all the instructions on your page at https://alexa-node-red.bm.hardill.me.uk/docs

    Knowns: Alexa recognizes the 3 new devices. I know internally my systems are working as they communicate with MQTT on my network. Node-Red flows that I am using are working perfectly.

    Is there a critical item in your documentation missing? Do I have to say something like “Alexa what is the status of the front door?” etc.

    Ideas? Things to check? Thanks!

    1. Without knowing what type of “devices” you have defined it’s hard to say. The comments section isn’t really the best place to work through this, can you open a issue on github here. Outline what type of devices you have defined (with what actions) and what commands you are using to try and activate them via Alexa

  12. Is there a way to debug the Alexa-home-node service? I upgraded to node-red v0.17.3 recently and now all my Alexa-home nodes constantly cycle though connected->disconnected->reconnecting->connected again every minute or so. I have no idea why they are doing this as they were working fine before the upgrade.
    Thanks,
    Bruster999

    1. Sounds like you have 2 instances running, you can only have 1 instance at a time as they use the same MQTT client id so both instances will kick each other off each time they try and reconnect.

      1. Yup. That was it. Somehow I had set up two instances accidentally. After removing one it got stable.

        Thanks!

        1. Sorry to sound like a numpty, but how can you check whether you have 2 instances running? I too have the same problem whereby the Alexa Home Nodes are cycling between Connected, ReConnecting, etc stages constantly

          Please HELP!

          1. Blog comments REALLY are not the best place to work problems. Ask on Slack in #alexa.

            But if you don’t know if you are running 2 copies of Node-RED then you have much bigger problems.

  13. Didn’t find a thumbs up button on your page so have to leave a comment πŸ™‚

    I just found Node-Red and your Alexa skill tonight after flashing a ton of SOnOff’s hoping to voice control them. The setup including your Alexa skill works a treat. Super happy. Love your work… that’s all.

  14. Just found this, wonderful!!
    I am connected and have discovered the devices created during signup.
    Is there any forum of users as of yet. I have questions regarding getting temperature from the sensors to alexa. Not bug reports, just educational. More examples would be great.
    In my case I have esp8266 with espeasy firmware pushing temps to MQTT. These are already showing on node red dashboards and data logging.
    I am almost there with the addition of your skill… πŸ™‚

    1. Yup me too. I’m using mongoose OS for my esp8266 and esp32 devices with MQTT. It seems too easy a child could do it.

      @Ben thank you for the service – not sure how much mileage we’ll get but thanks again

  15. I would like to see an example how I can use to get temperature. I am able to get the request, but I made a mistake to create a proper response. Thank you in advance!

    1. This is not the right place to address this, read the doc on the site and if that doesn’t help then post in the #alexa channel in the Node-RED Slack team.

  16. This is awesome! It’s the most straight-forward way to use Node-RED from Alexa and the integrating it as home devices is very neat. Thank you!

  17. Thanks for this I signed up for an account, allowed access, added my devices, add then Node Red source all working! Thanks this is great! The documentation is also very good πŸ™‚ I watches lots of Youtube videos etc. and found your site it all worked first time! For the Alexa Home Response I had to read the docs πŸ˜‰ I needed to set the T/F for to show success/fail as you had said! Thanks again! All my ESP8266 controlled 433Mhz Plugs around the house are working like a charm!

  18. This looks very interesting. I have a google home as well. Do you support that or only Alexa?

    1. I have the start of something similar for Google Home, but it is not finished and I’m a too busy to work on it just now.

  19. Hi.

    At first place, I would like to thank you this project.

    This skill seems to be the solution to all my problems related to Alexa and my home automation environment.

    Sadly the skill is not available on Spain. This is maybe because Amazon Echo is available here only 3 days ago.

    Do you know if it will be?

    Many thanks again!

    Regards.

    1. Hi,

      Please raise and issue here then I can get you to help translate the text needed to add it to the Spanish version of the skill store.

Comments are closed.