Home Home Automation IKEA Tradfri Socket in NodeRED

IKEA Tradfri Socket in NodeRED

Making Smart Sockets better since 2016!

I got another product from the furniture and meatballs company: IKEA Tradfri Socket. This smart socket comes on its own or bundled with a 2 button remote. I actually got both, but I will talk about the button in my next article (a reason to follow me on social media!). I already covered most of the IKEA things in NodeRED, so let’s make IKEA Tradfri Socket a little bit better.

Meatballs of automation & IKEA Tradfri Socket

You might have seen an article about timers in NodeRED earlier on. I wanted to write about timers in detail, otherwise, this article would be much longer. Skim over that write up if you have any questions. My today’s aim is to improve the IKEA Tradfri Socket in NodeRED.

Here are the things that IKEA Tradfri Socket can do in NodeRED:

  • Alexa & Google Assistant compatible
  • Works on LAN only
  • Recovery of timers on reboot|restart
  • Unlimited timers
  • Dashboard Timers
  • Day of the week support
  • Online status of each timer
  • Easy integration with Home Assistant

This is an impressive list. Before we start, I have to point you to a couple of articles about Zigbee2MQTT if this is your first time with IKEA things in NodeRED.

Getting things ready

To make the IKEA Tradfri Socket compatible you will need CC2531 USB Zigbee stick flashed with a custom firmware. Once you have the stick ready you can pair the socket by holding the button in the pinhole at the bottom for a couple of seconds. On release, you should see a new device added to your config file.

Edit the configuration.yaml file and name the new devices to something you will remember.

IKEA Tradfri Socket in NodeRED

Smart sockets are probably one of the easiest things to automate. All you can do with it is to toggle the socket ON|OFF. That’s it (unless you have a Sonoff POWR2 which measures power use).

In this tutorial, I will use the following nodes:



To connect with IKEA Tradfri Socket in NodeRED you will use MQTT. To query the status submit the payload: {"state":""} to zigbee2mqtt/devicename/get. The response will be posted to the topic: zigbee2mqtt/devicename and it will look like this:


To control the IKEA Tradfri Socket in NodeRED simply send msg.payload set as ON|OFF. For some reason, responses from IKEA Tradfri Socket are duplicated, so I used a rate limit node to discard the duplicate messages coming within 1 sec.


There is the entire article explaining how Alexa in NodeRED works (the easy way) so please read it first. Because Alexa commands pass true|false I will need a switch node to translate this into something compatible with the Zigbee2MQTT commands.

Switch node way

You can use a switch node & change node combination to detect the true|false payload and change it to ON|OFF which will toggle the IKEA Tradfri Socket in NodeRED.

Function way

If you want to keep things even more organised, you can combine the 3 nodes above in a single function node:

Function Node: Switch (Alexa)
var x = msg.payload;

if(x === true){
    msg.payload = "ON";
    return [msg, null];

if(x === false){
    msg.payload = "OFF";
    return [null, msg];

Either way, the voice commands will work just fine.

Google Assistant

To connect the IKEA Tradfri Socket in NodeRED to Google Assistant I’m going to use gBridge. Read on how to create devices (you can have up to 4 devices in the free plan) and you can use MQTT to connect the socket with Google Devices. Since the gBridge uses different payloads, you will need to convert it in the way as with Alexa. Use the topic: gBridge/xxxx/devicename/onoff to receive the commands from Google Assistant – the payload will be 1|0.

Switch node way

You can use a switch node & change node combination to detect the 0|1 payload and change it to ON|OFF which will toggle the IKEA Tradfri Socket in NodeRED.

Function way

If you want to keep things even more organised, you can combine the 3 nodes above in a single function node:

Function Node: Switch (gBridge)
var x = msg.payload;

if(x === 1){
    msg.payload = "ON";
    return [msg, null];

if(x === 0){
    msg.payload = "OFF";
    return [null, msg];

To get the status updates over to Google Assistant, you will need to post ON|OFF to the MQTT topic: gBridge/xxxx/devicename/onoff/set. just remember that the state of the socket is stored in msg.payload.status. You can use a change node to reassign the msg.payload.

Dashboard and timers

It’s possible to add a large number of timers to each socket. You will be limited by the memory of the Raspberry Pi, but there is no other limit. I’m working with MQTT update node to create a status notification. You can actually change the colour of the text in the dashboard based on variables:

Function Node: Format Colours
switch (msg.payload.state) {

case "ON" : 
    msg.color = "green";
    msg.payload = "ON";
case "OFF" : 
    msg.color = "red";
    msg.payload = "OFF";
default : 
    msg.color = "black";
    msg.payload = "not updated";

return msg;

Just make sure to set the text node (value field) to:

I also added a switch to my dashboard, and the switch simply sends ON|OFF payload. The switch isn’t updated to reflect the current state.

Lastly, I dropped 2 timers in NodeRED to create morning and evening behaviour. You will spend some time organising your dashboard panel to get the timers displayed correctly.

Sadly, that part is a pain in the neck, and you will have to sit through it all and make sure your dashboard has a correct order of things:

  • Timer Status (text)
  • T1 ON (picker)
  • Set ON (button)
  • T1 OFF (picker)
  • Set OFF (button)
  • Reset Button (button)
  • Mon (switch)
  • Tue (switch)
  • Wed (switch)
  • Thu (switch)
  • Fri (switch)
  • Sat (switch)
  • Sun (switch)

Buy USB Zigbee Stick CC2531

Buy it using these links to support NotEnoughTech.


And that’s how you add IKEA Tradfri Socket in NodeRED! Once you break it down into pieces, it’s not that hard even if the flow on its own looks intimidating. The benefits are clear, the GUI is practical and with recovery options, you will never miss a schedule again. Let me know what do you think about this project in this Reddit thread.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

To server or not to server? That's a very silly question!

Best Automation Projects

Sonoff R3 DIY mode & why it sucks

Long awaited Sonoff R3 DIY mode is even worse than I expected.

IKEA TRADFRI Wireless dimmer in NodeRED

Thanks to NodeRED you can use IKEA TRADFRI Wireless Dimmer to interact with everything

NEST your old thermostat under $5

Nest-ing up your older thermostat under $5

Things they don’t tell you about IKEA Trådfri

There are things you should know about IKEA Tradfri before you make your purchase

Alexa and NodeRED integration

Hey Alexa, turn the lights on!

Smart Home

Shelly 1PM: “PM” stands for Printer Manager

I decided not to use my Shelly 1PM with lights. I had a much better idea in mind! I'm going to show you how to get your printer ready for automatic ON/OFF and print price calculations including electricity used.

Monitor 2 gangs at once with Shelly 2.5

Taking a closer look at Shelly 2.5 switch with 2 switch/gang support and individual power metering

Sonoff DUALR3 has a hidden secret

Hands on on new product from ITEAD: Sonoff Dual R3

M5Paper received UIFlow support

Much desired support for UIFlow for M5Paper has arrived! If you needed an extra reason to get it, now it's the time.

PIR sensor like no other: Shelly Motion

Shelly enters IoT sensor space with their Shelly Motion - a WiFi enabled PIR sensor that can last up to 3 years!