Software apps and online services
There are already a lot of 'off-the-shelf' IoT devices for the home out there. But what if you could use the IKEA TRADFRI as an input device (for example to control your Sonos) The TRADFRI remote can cope with up to 13 different functions. This article explains how you can use this low-cost device (15€) with your home IoT projects.
If you want to communicate with the Ikea TRADFRI remote controller, we need to setup our own Zigbee Gateway (the Ikea gateway does not allow to connect directly with the Remote).
- Install a Raspberry Pi
- Install Node-Red
- Install the Zigbee2MQTT repository
The Zigbee2MQTT repo will communicate with the Zigbee controller and translate all messages into MQTT topics. From there we can wire any kind of flow within our Node-RED environment.
# Clone zigbee2mqtt repository
sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
sudo chown -R pi:pi /opt/zigbee2mqtt
# Install dependencies (as user "pi")
Note that the npm ci produces some warning which can be ignored.
All credits go to Koen Kanters who did a magnificent job.
To be able to communicate with the IKEA TRADFRI devices, we need to connect a ZigBee controller on the Raspberry Pi with a specific firmware that supports the Zigbee2MQTT stack.
A good working device is the Wireless Zigbee CC2531 USB stick which you can find for around 10€ on the Internet. You need to flash the device as outlined in this guide https://notenoughtech.com/home-automation/flashing-cc2531-without-cc-debugger/
The procedure is quite cumbersome. You can also find pre-flashed Zigbee CC2531 USB sticks on the Internet. I got mine from a guy called Yezzer from Oudenaarde (Belgium).
Insert the Zigbee USB stick on one of the USB ports of the Raspberry Pi.
- Insert the Zigbee USB stick on one of the USB ports of the Raspberry Pi.
Before we can start Zigbee2mqtt we need to edit the configuration.yaml file. This file contains the configuration which will be used by Zigbee2mqtt.
Open the configuration file:
For a basic configuration, the default settings are probably good. The only thing we need to change is the MQTT server url and authentication (if applicable). This can be done by changing the section below in your configuration.yaml.
# MQTT settings
# MQTT base topic for zigbee2mqtt MQTT messages
# MQTT server URL
# MQTT server authentication, uncomment if required:
# user: my_user
# password: my_password
Save the file and exit.
Now that we have setup everything correctly we can start zigbee2mqtt.
Before we can receive payloads from the TRADFRI remote controller, we need to pair it.
To pair a zigbee device, make sure that the permit_join: true is set in your configuration.yaml file. Otherwise the new devices cannot join the network!
- Set PermitJoin : true (this puts the Controller in Join mode)
Note: To follow the commissioning process, you can view the Node-RED log on the Raspberry-pi. The output would look similar to the one below.
Once you see something similar to below in the log your device is paired.
zigbee2mqtt:info 2019-11-09T12:19:56: Successfully interviewed '0x00158d0001dc126a', device has successfully been paired
Next we are going to create a digital representative for the TRADFRI Remote control on AllThingsTalk Maker. Although we can identify 13 different functions behind the TRADFRI remote control. Let’s just implement a few of them as a showcase.
If you don’t have an account yet, you can create a free account on maker.allThingsTalk.com.
- If you don’t have an account yet, you can create a free account on maker.allThingsTalk.com.
- Within a Ground, create a new device example: TRADFRI Remote Control.
- Choose ‘+New Device’
- Select ‘Your own Device’
- Give your device a name: for example: TRADFRI Remote Control
- Click Connect.
- Under your device, Let’s create 3 assets of kind ‘sensor’ and data type ‘string’ and call them Brightness, arrow and toggle.
The result should look as follows:
Note: For each of the assets, the necessary MQTT Topics are auto generated which we can use further in our Node-RED application to upload the device state.
Example for the toggle asset, the MQTT topic looks like:
Now we can wire everything up by creating a Node-RED flow to upload the device state from the different buttons on the TRADFRI Remote Control.
The Flow looks as follows and can be imported from the code below in Node-RED.
The Flow subscribes to the MQTT topics from the zigbee2MQTT component, interpretes the data and forwards the states on the MQTT Topics created by the digital representative of the TRADFRI remote Control on AllThingsTalk Maker.
Use your imagination and think of how you can use the TRADFRI Remote Control to actuate anything in or around your home or office. With the above solution, you are not bound anymore to the IKEA IoT eco-system but now you can use the Remote for anything you want to control. For example your SONOS speakers, Blinds, television set, you name it...