Flow to link Ikea Trafri Buttons to Tradfri Bulbs

Hi all, I know that quite a few people are interested in the Ikea Tradfi range of relatively low-cost Zigbee devices. I got a load at the weekend to go with the Zigbee USB dongle I picked up a week or so ago.

I wanted to replace a couple of my old on/off 433MHz LightwaveRF switches with smart bulbs so I thought I would share a quick flow that lets you use one of the E1743 on/off buttons to control lights.

Note that:

  • I am using Zigbee2MQTT for all the controls, running on my home server (Debian) that also runs Node-RED, InfluxDB, etc.
  • You don't need an Ikea Zigbee controller. But you do need a Zigbee controller connected to a device capable of running Zigbee2MQTT
  • The Ikea buttons actually do fade-up/-down not just on/off even though the button only looks like on/off. You can, in the UK anyway, pick up a warm-white bulb and remote switch in a single pack for ÂŁ10 at the moment. Good value.
  • The Ikea buttons can be "bound" directly to a bulb and this is recommended in most cases as it removes the need for other services and hardware (Node-RED, MQTT, Zigbee2MQTT, etc) to be running. However, that wouldn't be using Node-RED :grinning:

Should be pretty obvious except for the function node, here is the code for that:

const input = msg.payload

const speed = 40
let topic = ''

// TODO: Replace with lookup
if ( msg.topic === 'zigbee2mqtt/Ikea_Button_01') {
    topic = 'zigbee2mqtt/Ikea_Bulb_01/set'
} else if ( msg.topic === 'zigbee2mqtt/Ikea_Button_02') {
    topic = 'zigbee2mqtt/Ikea_Bulb_02/set'

if ( Object.prototype.hasOwnProperty.call(input, 'action') ) {
    const action = input.action.toLowerCase()
    let out = ''

    if ( action === 'on' || action === 'off' ) {
        out = { "state": action }
    } else if ( action === 'brightness_move_up' ) {
        out = { "brightness_move": speed }
    } else if ( action === 'brightness_move_down' ) {
        out = { "brightness_move": 0 - speed }
    } else if ( action === 'brightness_stop' ) {
        out = { "brightness_move": 0 }
    if ( out !== '' ) {
        return { 'topic': topic, 'payload': out }

It is really nice that you don't have to output loads of messages for the fading, you only need to tell it when to start and at what speed and then when to stop.

Worth noting that changing the brightness only works when the bulb is turned on.

Of course, lots more you could do with this flow such as turning on when changing brightness and the bulb if off. Changing speeds, changing max/min brightness depending on the time of day, ....


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.