Home Assistant, Tips

A Christmas automation Easter Egg with Node-RED, Alexa, and Inovelli smart switches

I’m going to show you how I used Home Assistant and Node-RED to make the LEDs on my Inovelli switches do a holiday dance whenever someone plays Christmas music with Alexa. Here’s what we’re going for:

Pointless? Pretty much. But maybe you’ll pick up some tricks to use in useful automations! Also, it was fun.

I bought some new Inovelli smart switches and dimmers for our new house. I’ve owned and sampled a lot of types of smart switches, and these are my favorites now (supplanting my previous choice, the Leviton Z-Wave). I like the Inovellis because they pack so much functionality into a well-built product at a good price, and the company is super engaged with its customers. Full review coming later.

Anyway, one of the features on Inovelli switches is a multi-colored LED. For on/off switches it’s a single light in the bottom right; for dimmers it is a multi-light bar that runs almost the entire height of the paddle.

On/off switch on the left with small LED; dimmer on the right with LED bar.

Out of the box, these LEDs are blue and are used to show whether the switch is on/off and, for the dimmers, what the dim level is. But they can do so much more than that.

If you want to know how to do it, read on…it’s somewhat involved, but I learned a lot about Node-RED and Z-Wave configuration possibilities while doing this, so hopefully it will be enlightening (pun totally intended).

What you’ll need

The below assumes you have the following. It’s not a short list of stuff to setup, but I already had everything here installed for my normal home automation needs.

  1. Some Inovelli smart switches, obviously
  2. Home Assistant with the Open Z-Wave (beta as of now) integration setup, and your Inovelli switches added to it.
  3. The Node-RED add-on for Home Assistant and a basic familiarity with using it. There are tons of great tutorials out there for Node-RED, and I’ve switched to using it almost exclusively for my automation rules instead of the built-in Home Assistant automation framework.
  4. The wonderful Alexa Media Player add-on, which lets you take control of Alexa through your automations. This guide assumes you have this setup and your Alexa devices are shown in Home Assistant as media players.

For #2, it’s very important you use the new beta Open Z-Wave integration for managing your Z-Wave devices, not the “legacy” Z-Wave that’s the default in Home Assistant (as of late 2020). Only the newer Open Z-Wave will let you capture the events and send LED configuration parameters to the Inovelli switches that affect the LEDs.

Step 1: Detecting Christmas music from Alexa

The trigger for this all to happen is someone playing Christmas music with Alexa. To detect this, we’ll use the common “Events: State” node in Node-RED:

This node fires when my Alexa group called “Whole House” starts playing something.

I use an Alexa group called “Whole House” as my default speaker when we ask Alexa to play music, so that’s what I have this event node configured for. You should set it to whichever Home Assistant media player entity represents the right Alexa device for your situation.

Now, when this node activates, it fires off a message that includes the information we’re going to need next — that is, what music is playing. It’s buried in the object, which we can see if we send the message to a debug node:

The object output by Events: State node when a media player starts playing.

So using the information in this message, we can setup rules that will be able to determine when Christmas music is playing with an acceptable level of accuracy. Since I really only care about the “new_state” part of the above message, I use a Change node to quickly set that as the msg.data object (this saves a lot of typing in later nodes):

Then I use Switch nodes to check the title, album, and artist elements in the object for the string “Christmas”, since one of those will almost always contain that string when you ask for Christmas music. It’s not foolproof but it’s close enough:

If the part of the message I’m targeting contains that string, the message is passed along. If not, it stops.

And that’s the Alexa part of the automation. Next we’ll dip into the Z-Wave part, which is where things get a bit more complicated.

Step 2: Setup your Z-Wave Node IDs and colors

Most Z-Wave devices have configuration options, called parameters, that can be set to control the device’s behavior. What parameters are available and what they do are up to the manufacturer. In the case of Inovelli, some of these parameters allow you to set the switch to display what they call a “notification”, which activates the LED according to a color, brightness, and blink pattern you specify.

The Open Z-Wave integration for Home Assistant allows us to set parameters for Z-Wave devices using the ozw.set_config_parameter service. To use it, you have to provide three values: the node_id (which device we’re targeting), the parameter (which param we want to set), and value (the value to set the parameter to).

Let’s test this on a single switch.

Finding your Node ID

To get the node ID, in Home Assistant go to Configuration > Devices and then search for an Inovelli switch that you have installed. For example, I have one that I had named “Kitchen Main” so I searched for that, and on that device’s details I can find the Node ID:

We’ll eventually need to get the Node IDs for every dimmer and switch we want to make blink. NOTE: Keep the Node IDs for dimmers and on/off switches on separate lists, because the parameters and values we’ll be using are different for each type.

Find your parameter and value

Now that we know what Z-Wave node we’re going after, we have to figure out what parameter and value we’re going to give it. For this, we turn to a wonderful tool by Nathan Fiscus, the Inovelli Notification Calculator.

Using the calculator, we set our switch type (dimmer or on/off), then click on the Notifications tab. From here we can setup our LED to do whatever we want. Here I’ve picked a green color that uses the Fast Blink effect:

You can also, usefully, set a duration, so the switch stops blinking on it’s own after awhile. You can do that, but I’m leaving mine at infinity because I am going to build my own control to stop them from blinking.

The box at the bottom called Configuration Value is what you’re after. For the dimmer shown above, to get the effects we’ve selected we’re going to set parameter 16 to the value 67045968.

Test it out in Developer Tools

Now that we have our node ID, parameter number, and value, we can test it in Home Assistant’s developer tools before we start wiring everything together in Node-RED. Go to Developer Tools > Services, then fill it out with your values:

When you click Call Service, you should see the LED on the Inovelli switch start doing its thing.

Setup array of nodes

Now we need to get all the Node IDs and set them up as a flow object in Node-RED. We’re doing this so we can use other nodes later on to iterate/loop through all the switches we want to include in our automation.

Using an Inject node that fires on startup, linked to a Change node, we will set flow.xmas to an array of objects, each of which has a node ID, switch type, and the color we want it to be (red or green).

Set flow.xmas with the Change node. Click on the … to bring up the full JSON editor (see next image)
The array of objects I set for flow.xmas. Each object has the node ID, type, and color.

Getting the type correct for each node is very important, since the parameters for on/off switches and dimmers are different.

Step 3: Tie it all together

So by now we should have:

  1. A trigger and switches to check if Alexa is playing Christmas music.
  2. A flow.xmas object that contains all our Inovelli node IDs, along with the type and color for each.

Now comes the real Node-RED magic, where we’ll parse through our flow.xmas object and setup a message object for each switch.

The algorithm we’re creating is essentially this: Split the flow.xmas object, so that for each item in flow.xmas…

  1. Is it a dimmer or switch?
    1. If dimmer…
      1. Set parameter 16
      2. Red or green?
        1. Red: Set value = 67045889
        2. Green: Set value = 67045961
    2. If switch…
      1. Set parameter 8
      2. Red or green?
        1. Red: Set value = 50268673
        2. Green: Set value = 50268749
  2. Set node_id
  3. Call ozw.set_config_parameter service

To make that work in Node-RED, we’re going to use a combination of Switch and Change nodes. Along this flow, for each node ID we’re tying to build a message object that looks like this:

"payload": {
  "data": {
    "node_id": 6,
    "parameter": 16,
    "value": 6745889

When this message reaches the Call Service node at the end, the data object will be used as the service parameters (just like we did in Developer Tools).

What this piece looks like in its entirety:

The leftmost node (which I have labeled as “Node IDs” is setting msg.payload equal to the flow variable flow.xmas, so we have a copy of our list of nodes in the msg object for processing by each node. Then, since that’s an array, we split it, so that the above sequence runs for each item in our xmas list. Therefore, the input to “Dimmer or switch” is an object where msg.payload looks like this:

    "node_id": 21,
    "type": "dimmer",
    "color": "green"

From there it’s just a series of conditionals (Switch nodes) and setting values (Change nodes).

For instance, we first check to see if it’s a dimmer or switch:

Then, if it’s a dimmer, the first Change node sets the parameter to 16:

We follow a similar pattern for setting the parameters for each color. Then the last step is to set the node ID, and finally call the ozw.set_config_parameter service:

There’s no “Data” explicitly provided on the ozw.set_config_parameter service call, because it will automatically pick up our object in the msg.payload called “data” that we’ve been building with all our Change and Switch nodes.

Now we hook together our Alexa piece from Step 1 with this part we built in Step 3, and we’re done!

The finished product

The whole thing looks like this:

The complete flow for Inovelli+Alexa Christmas lights

A few things to mention:

  1. Note the “Fire at startup” Inject node in the bottom left…the Change node it’s connected to is where the flow.xmas object (containing our switch/dimmer node list) gets set when Node-RED starts running.
  2. Along the bottom (after the 5 minute timer) I have a part of the flow that sets parameters to shut the blinking lights off. This follows a very similar pattern to turning them on, just setting different values. See the Inovelli calculator for the values to use to turn the notifications off.
  3. I have Inject nodes setup to Manually activate lights and Stop lights. This is useful for debugging and testing without having to be constantly asking Alexa to start and stop Christmas music.

And that’s it! After an hour or two of fiddling, you too can surprise your spouse with obnoxious green and red blinking LEDs whenever they ask Alexa to play Christmas music.

All kidding aside, there’s plenty of good stuff in here about how to build Node-RED flows and interact with Z-Wave device configurations, and I learned a lot building it. I’m still pretty new to Node-RED so I’m sure there’s much better ways to do this, but this worked for me.

Have you done any pointless/fun holiday automations? Share them!

Leave a Reply

Theme by Anders Norén