In this article we are going to present how you can configure an Alexa device into your home automation system, allowing you to create customized actions and responses.
Typically you need to have Alexa compatible devices in order to interact with them via voice command. However, with the use of Node-Red, an Alexa Skill, and a compatible home automation system, you can create practically any customizable action and response for your Alexa devices.
The following is an example we demonstrated for a customer who has a cistern that supplies water to their home. The customer wanted the ability to get the status of the cistern volume without having to physically check the level or having to access an app. The solution we presented consisted of a Homeseer automation controller (the customer was already planning to use Homeseer), Node-Red, the Virtual Smart Home (VSH) Alexa Skill, and one or more Alexa/Echo devices.
Getting Started
We started by creating a Virtual device in Homeseer that receives updates regarding the status of the cistern. The Virtual device monitors the water level in inches and volume in gallons on a regular recurring interval. Next, the VSH Alexa Skill was enabled. The last step was to install Node-Red and the necessary modules (node-red-contrib-homeseer, node-red-contrib-virtual-smart-home, and node-red-contrib-alexa-remote2-applestrudel). We won’t explain how to configure Node-Red and Homeseer as there are several tutorials online that already explain this process. Having said that, it is a very simple and straight-forward process.
Node-Red Flow
To create the Node-Red Flow that will allow Alexa to respond to custom voice requests, start by adding a Virtual Device node (node-red-contrib-virtual-smart-home). You will need to configure the node so it can establish a connection with your Alexa account. When you are configuring the Virtual Device node, select Dimmable Light Bulb as the type of device. Doing so allows you to create up to 100 separate voice command actions per connection. We then added a Switch node that will determine the path the Flow should follow based on the value received. Next, we added a Function node that retrieves the current cistern water volume value from the Homeseer Virtual Device, and formats it into a ‘user friendly’ sentence that becomes the message payload (msg.payload). Finally, an Alexa Routine node is added that will receive the message payload from the Function Node. If you have multiple Alexa/Echo devices, you can add and configure an Alexa Routine node for each device.
Alexa Skill (Virtual Smart Home)
With the VSH Skill enabled and configured, open the Alexa app and go to the Routines menu option. Create a new Routine, give it a name to easily identify it; then in the ‘WHEN’ section select ‘Add an event’ and select the ‘Voice’ option. When prompted, enter the voice command Alexa should recognize and response to. Then in the ‘ALEXA WILL’ section select ‘Add an action’ and select the ‘Smart Home’ option and then ‘Lights’. From the list displayed, select the name you gave the VSH device in Node-Red. In our example it is named ‘Command’. After selecting the device, select ‘Next’ and then check the ‘Brightness’ option. You will then adjust the slider to the desired brightness value; this will become the value that is sent to the Switch node in the Node-Red Flow when the voice command is recognized by Alexa.
You can create multiple Routines in the Alexa app, each targeting the same Smart Home Light device that references the Node-Red virtual device you created, but each having a unique brightness value.
A Visual
This Flow shows an Alexa Virtual Device node (Command) that passes a value to a Switch node with three outputs. Each routing to a specific Function node based on the Brightness value defined in the Alexa app Routines. We wanted to demonstrate how one Virtual Device node (Command) can support multiple voice command requests. The comment bubbles indicate the different Alexa voice commands along with the associated brightness values configured with each Routine. The Inject nodes are merely there for manual testing purposes. We also used Link Out and Link In nodes to help keep the Flow design layout cleaner visually. You will also notice we configured three Alexa devices that will all announce the response. You can get creative and expand the Flow and logic to only announce on specific Alexa devices based on your defined criteria.
We hope this example shows how simple creating customizable Alexa voice commands and actions can be. Feel free to reach out to us if you have any questions.