Node Red Alexa Best Practices

Hi everyone, I relatively new to Node Red as I was looking for an alternative to emulated_hue that stopped working for me and the cost of the newly announced Cloud service being unrealistic. With that said, I found the documentation was a little sparse with Node-Red. So this thread is for any cool tricks and best practices for Node Red specifically when using for Alexa. There is some assumptions though, you should already know the basics how Node-Red works.

The first I found, was the debug is YOUR FRIEND! First, you’ll need to add an Alexa node, and then scan in the Alexa app to add to your devices. Assuming you have that already done.

1. Add a Debug node and change the properties to this:

51 PM

22 PM

2. Next, open the debug tab on the right side and ask Alexa something like “Turn on the Fan”. You will notice Alexa sees it’s a Power On command since there’s a property on_off_command: true

09 PM

3. Now Try saying something like “Alexa, increase the fan”. Notice it’s not an on_off_command but yet the change_direction is now a 1. If you say "Alexa, decrease the fan, it will be a -1.

38 PM

4. So now we can actually do something with this! For a fan as an example, you can create a switch that determines if it’s a Power command or a Change Direction command and separate the two possibilities. Then From there, you can further break them into Power On/Power Off and a Fan Speed Up/Fan Speed Down command. I have a separate script in HA for each possibility.

33 PM

5. Now configure the switch which determines whether Alexa thinks it’s a power command like this:

28 PM

6. Next, configure the other switch which determines whether Alexa sends to a increase or decrease command like this:

04 PM

7. Finally, connect the nodes up together and you should have something like this!

That’s it really! Pretty simple. Looking forward to any other tricks people have!!

6 Likes

Hi,

Great work! Can’t wait to try it.

What Node do you use for Alexa?

nice write up. My only thing is I wouldn’t use a regex match for on/off matching and I would just do a string comparison. And on top of that, I’d “cheat” even more and just do a comparison for “on”, and then do otherwise for the 2nd output.

This is purely from a performance standpoint, that regex is expensive, and there is absolutely no reason to check for off if you already checked for on.

I personally am running Alexa through HA still (I’m still on 56.2 since anything newer causes my CPU to spike to 100% use), but if I ever get something that needs speed/volume/whatever control I’ll have to take a look.

(EDIT: and yes, I know that it doesn’t need to be super high performance, it is just what i’d do out of habit for all of my nodes as some are triggered a lot faster than by alexa)

1 Like

@nordlead2005 Good point! I should definitely change it to be more efficient. Thanks

@outrun I’m using the local Alexa node. Some people were having issues with it, but I think the same principles would work for the cloud based one.

1 Like