Alexa controls Lights, Blinds, and Window Openers with Node-RED

Alexa™ + Node-RED + BroadLink™: A Simple Flow Example - Controlling Lights

Adrian Biffen, Senior Partner

Please Note: This series covering Alexa™ assumes you have set up your BroadLink hub with the phone app (see home theater phone app article series), and you are running Node-RED on the RPi.

The previous Part 3 of this series discussed how the BroadLink™ RF-IR hub (and Alexa™) can be configured to work with the Node-RED visual design system to control blinds, lights, window openers and many other devices.

In this article (Part 4), we'll create a simple flow that will enable an Alexa™ node and the BroadLink RM Pro node to control a simple on/off flow to control lights. We selected this as the first example because it is the simplest type of action that can be performed, with 2 states (ON/OFF). The next installment in this article series will deal with blind and shade control, which requires 3 states (OPEN/CLOSE/STOP).

Light control with Alexa™ can also involve dimming and color change, but we will not be covering that here. Keep in mind that this version of the Alexa™ node component uses the Philips Hue emulation mode to issue commands.

Our lights are actually controlled by an old x10 light switch that operates at 315 MHz, and this is another nice feature of the BroadLink™ hub, if you happen to have a lot of old x10 devices in your home like we do (the BroadLink™ hub will learn those codes).

Drag 'n Drop Your Nodes For Alexa™ Light Control Onto the Workspace

You may remember seeing this graphic in part 2, when we introduced you to the Node-RED workspace, and this is the flow that we want you to set up:

Node-RED workspace with Alexa running on Raspberry Pi

Note that you can arrange these nodes in your workspace however you want. The only thing that matters is that the wiring is the same, so you can drag the nodes around and position them wherever you want. We chose a compact format to keep the screen images as small as possible, but you could add some INJECT nodes, if you want screen buttons that will test the BroadLink™ transmission. Here are the steps to follow:

  • Start by dragging an ALEXA™ NODE instance onto the workspace design panel

  • Next, drag a SWITCH NODE onto the design panel. This node is found in the FUNCTION section of the node palette, not to be confused with the SWITCH NODE used in the DASHBOARD. You can change the name to something more meaningful (as we did by naming it LOGIC), but the icon always stays the same.
  • Follow this with 2 instances of the BroadLink™ RM
  • And finally, add 2 instances of the DEBUG node. This node is probably the most used because it delivers the output of your testing to the DEBUG panel on the right side of the workspace

Once you have placed all the nodes, please add the wires as seen in the above picture. Just click on the output dot of one node, and drag the wire to the input dot of the next node. You can still reposition nodes with the wiring attached, if that becomes necessary.

Test & Adjust the Configuration Properties of the Alexa™ Node

The Alexa™ voice control system works with any of the various voice modules that Amazon sells: the Echo, Dot, Tap, etc. Once it is plugged in and initialized, it should be ready to go. You can test it with this directive:

Alexa, open the pod bay doors

Alexa™ should respond with an appropriate statement that may be a bit of an admonishment. Some of you may remember this scene from Stanley Kubrick's fantastic movie "2001 A Space Odyssey" that was released in 1968, when I was 18. Here we are, 50 years later, implementing an artificial intelligence (AI) voice control system doing essentially the same thing.

The Alexa™ node has only the one NAME parameter, so please double-click the node and give it a unique name (we used SPOTS). This is the name that Alexa™ will automatically recognize as a device.

Once you have determined that "she" is working properly, and you have named the device, you can then ask "her" to discover your light module by saying this:

Alexa, discover devices

She will then activate the DISCOVERY mode and report back in about 20 seconds. You should get an acknowledgement that she has found your named light device.

Set the Configuration Properties of the BroadLink™ Nodes

Please refer back to the previous article to see the setup of the BroadLink™ nodes; we won't cover that here. Essentially, if you don't have any lights in your system, just choose something that you can turn ON and OFF, then set the nodes for the appropriate buttons.

Set the Configuration Properties of the DEBUG Nodes

There isn't much you need to do with the DEBUG node, it just feeds the message payload to the DEBUG screen. You can double-click it and give it a more meanigful name, if that helps, and you should make sure the DEBUG WINDOW is checked.

Set the Configuration Properties of the SWITCH Node

Node-RED example properties dialog for the SWITCH node We haven't seen this node yet, so we'll study it in more detail.

Essentially, this node will determine if you are issuing an ON or an OFF command, and feed the result to the appropriate BroadLink™ node.

You could also use the FUNCTION node and write some code to do the same thing, but the overhead load of that on the Pi CPU will be much higher, not to mention the fact that you might not be into coding.

The SWITCH node provides a way of setting up conditional branching logic, and it is really doing the same thing that programmers do with IF ... THEN ... ELSE statements in code.

The SWITCH node always loads with the first parameter in place, which you can then modify. You have numerous conditional choices in the drop-down selector; we are using the CONTAINS parameter, with the keyword On

After you have set the first parametrs, click the ADD button to create the next condition with the keyword Off.

Every time you add a condition, you'll see a new OUTPUT DOT appear on the node. The OUTPUT DOTS get wired to the appropriate BroadLink™ node, which actually executes the command from Alexa™.


Spot Lights Are DONE!

So that's about it, the system should work at this point. You should be able to issue commands to Alexa:

Alexa, turn on spots


Alexa, spots on


Alexa, turn off spots


Alexa, spots off

In the next article, we'll tackle the slightly more complicated system of blind and shade control.


Buy The BroadLink™ Hub and Accessory Modules In Our Online Store

In the meantime, we have the excellent BroadLink phone apps that are very capable, and they may very well be all you need (they work stand-alone, the RPi is not needed). This will give you direct control over our blind motors and window openers. Please note that you will need to set up the phone app if you want to implement the system described in this series.

If you are interested, you can purchase these products in our DIY online automation store.

Articles in this series:

Part 1: Alexa™ + RPi + BroadLink™ Hub + Node-RED: Blind Control Introduction

Part 2: Alexa™ + RPi + BroadLink™ Hub + Node-RED: Installing Node Components into Node-RED

Part 3: Alexa™ + RPi + BroadLink™ Hub + Node-RED: Configuring Nodes in Node-RED

Part 4: Alexa™ + RPi + BroadLink Hub + Node-RED: A Simple Flow Example: Light Control (you are here)

Part 5: Alexa™ + RPi + BroadLink Hub + Node-RED: Control Blind & Shade Motors

Part 6: Alexa™ + RPi + BroadLink Hub + Node-RED: Configuring the Node-RED Dashboard Light Switch

Part 7: Alexa™ + RPi + BroadLink Hub + Node-RED: Configuring the Dashboard Blackout Blinds