I have been missing a short write up to how to use the IKEA light bulbs in NodeRED, so it’s time to share some knowledge. I actually had to go and visit my local IKEA again to get the colour light bulb (LED1624G9) as I only had the ones that support dimming (LED1622G12). While I was there I picked up a smart socket with a Zigbee remote, so expect the write up soon.
Adding IKEA light bulbs in NodeRED (Zigbee2MQTT)
I actually run into a hitch when adding the lights, I’m not entirely sure what caused it but I was not able to control my colour light bulb. In all honesty, I’m not sure what fixed it either, but after 3-5 successful power-off cycles on both Zigbee2MQTT & IKEA light bulb side, I was able to make the devices to talk to each other again.
Once you have paired all IKEA bulbs (you can see this if you start Zigbee2MQTT in terminal:
cd /opt/zigbee2mqtt npm start
you should edit the configuration.yaml file and name the new devices to something you will remember. It’s a good practice (since the IKEA bulbs look-alike) to use a permanent pen to mark the bulbs too! You can learn more about flashing the CC2531 and adding more devices in the corresponding links.
Let’s talk NodeRED
Both IKEA light bulbs are controllable in NodeRED. I have the E27 600lm colour bulb (LED1624G9) and dimmable E27 1000lm 2700k (LED1622G12). There is an added benefit of actually having a couple of Zigbee lights in your house as they expand the mesh network.
Getting the IKEA light bulb status
To control the bulbs, you will need to know the assigned name of the bulb (also your Zigbee default topic) and the command structure. Every now and then the device will post an update to the topic (zigbee2mqtt\bulbname) which will look like this:
{"state":"ON", "linkquality":34, "brightness":254, "color_mode":1, "color":{"x":0.699,"y":0.301}}
You can force the update by sending the payload:
{ "state": "" }
to zigbee2mqtt/bulbname/get. Note that the colour is received in X,Y values. You can read more about conversion here.
Setting IKEA light bulbs in NodeRED
To set the bulb to your desired settings, you will need to use this topic structure: zigbee2mqtt/bulbname/set. Then pass one or more arguments from this JSON file:
{"state": "ON", // Or "OFF", "TOGGLE" "brightness": 255, "color_temp": 155, "transition": 3, "alert": "select", // values (select,none,lselect) blink "color": {"x": 0.123, // XY color "y": 0.123} "color": { "r": 46, // RGB Colour "g": 102, "b": 193} "color": {"hex": "#547CFF"} // HEX color "color": {"hue": 360, // Hue and/or saturation color "saturation": 100} }
Despite the colour being provided as XY 1931 colour space, we can set the colours with RGB or HEX. Only pick one of the “color” setters in the payload above.
Let’s create an interactive picker that we can use to set IKEA light bulbs in NodeRED to different colours. The nodeRED dashboard comes with colour picker, so this won’t be very hard. All I need is a slider to control the brightness and I can pass the values over.
First, I have to store the colour values in a flow variable. Each time the bulb updates, I want to make sure I have this value at my disposal as changing the brightness without this causes errors.
var color = msg.payload.color; flow.set("ikeabulbc1_color", color); return msg;
Then I’m ready to deploy a slider linked to the following function node:
var x = msg.payload; var color = flow.get("ikeabulbc1_color"); msg.payload = {"brightness": x, "color" : color } return msg;
To change the colour, all I need is a colour value in HEX to be passed over to my function node:
var x = msg.payload; msg.payload = {"color": {"hex":"#"+x}} return msg;
A payload formatted like this will send the colour value to IKEA light bulb. Set this up for each bulb you own and you are all set.
Buy USB Zigbee Stick CC2531
Buy it using these links to support NotEnoughTech.
Conclusion
Thanks to Zigbee2MQTT you can mix and match your IKEA light bulbs in NodeRED with different ways of driving it. It’s simple and the set up above only takes a couple of minutes to establish. Let me know if you have any questions in this Reddit thread.
Project Download
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.