Creating a standing LED light with Home Assistant and NodeMCU — Part 3
By: Glenn Ruysschaert
Tags: Lighting, Home Automation, Home Assistant, Node Red, Led

In the previous parts we created the entire light. Now all that’s left is group to all the lights together and use an Ikea remote control to turn them on/off.

This part assumes you have a basic understanding of Home Assistant, Node-RED and Zigbee. If you haven’t used Node-RED before, here is a good getting started guide.

For Zigbee, if you haven’t set it up yet, follow the steps on the HA website.

In terminal on your Hassio device (I’m using a Raspberry Pi 3B+), you can use the following command to detect your Zigbee stick (as you will need its path in the steps). Look at the list to find you radio type.

ls -l /dev/ttyU*

The stick I’m using is HUSBZB-1.

Grouping the lights

This step is very straightforward, grouping is already a part of Home Assistant. So go ahead to the file editor of your choice (I use this one).

If you don’t already have a lights.yaml file, create one in the same directory of your configuration.yaml file.

Open configuration.yaml and add the following line (if you haven’t already).

light: !include lights.yaml

In lights.yaml paste the following

- platform: group

name: Standing lights

entities:

- light.led_standing_light_1

- light.led_standing_light_2

- light.led_standing_light_3

- light.led_standing_light_4

Replace the entities your LEDs.

Go to Configuration > Server Controls. Press the Check configuration button to make sure everything is set up correctly. At the bottom of the page, restart Home Assistant to make sure everything is loaded properly after rebooting.

Pairing the Ikea remote

The remote I’m using is the round 5 button one.

© Ikea

If you have used the Ikea Tradfri Gateway before then you probably already know how to pair devices. First off, if you have used the remote before make sure to remove it from the gateway using the Ikea app. Open the back of the button to reveal the battery and a button inside.

In Home Assistant go to Configuration > Zigbee Home Automation > Add Devices. It will now start searching for new devices. Hold the button no further than 2cm away from the Zigbee stick. Now press the button inside the remote 4 times. Wait a bit and you should see logs coming through in Home Assistant. After a few seconds a popup will ask you to name the device, you’re done pairing!

Using the remote in Node-RED

Head over to Node-RED. The first thing we want is to be able to listen for Zigbee events. Create a new workflow and add an events: all node.

Set the event type to:

zha_event

Or import the following (remember to fix your Server)

[{"id":"7c05f341.3b617c","type":"server-events","z":"b16c9e0.0dfa16","name":"","server":"edecb673.6d66a8","event_type":"zha_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":130,"y":100,"wires":[["1e22dac1.7ed685"]]},{"id":"edecb673.6d66a8","type":"server","z":"","name":"Home Assistant"}]

Now link a debug node to the output of that node. Set the debug node’s Output to ‘msg.payload.event’. Publish the workflow.

Wait for the event node to say ‘connected’, then press Ikea button.

Look at the debug messages. You will find the device_ieee and then command there. The device_ieee is the unique identifier of your button. This way you can split the flow depending on what remote control was used, if you are using multiple remote controls. With command you can detect the button that was pressed.

Below you can find a screenshot of a simplified version of how I set it up (to make it more understandable).

I have created a gist here, so you can import this flow as well.

You will need to change the lights and properties of course. But this way you get an idea of how I did it. Take this as an example and apply it to your setup.

And with this, we are finished! I hope you enjoyed created this standing light, and maybe learned something new.

The end result should look something like this