IKEA Trådfri Gateway [Zigbee]

It seems they are working on DTLS 1.2 in PyDTL so that shouldn’t be a problem, tho it would add a dependency on OpenSSL.



Thanks for the link @Danielhiversen! From there, it shouldn’t be that tricky to build an integration into HA. Just tried downloading a few python-based CoAP-implementations, of which one was based on Python3. Have to resume tomorrow as I’m on a too low version level of Python.

1 Like

Nice work. Had problems with PSK in a too old version of Wireshark when rev. engineering communication. Are you using the PSK unmodified from the sec code? What are they using as “Client Identity” in DTLS?

…and again, really great work. Time to download CoAP- and DTLS-library in fav. lang.

Another forum has linked to this thread and an interesting post regarding libcoap and the dtls branch was just posted. Check out the post by arturo182 here:

1 Like

After pairing the hue bulb with the IKEA gateway did it work as intended from the IKEA app? (Was it a white or multi colored bulb?)
Also any chance you could try with a hue light strip? (it seems IKEA has no plans of adding a smart light strip when i asked their support last time).

Based on what I’ve found so far online, I’ve put together a very simple implementation on my raspberry pi. Taking no credit of all the hard work others have put in and just put my code here if you want to play around :slight_smile:

I first installed the libcoap-library as such:

apt-get install libtool

git clone --recursive https://github.com/obgm/libcoap.git
cd libcoap
git checkout dtls
git submodule update --init --recursive
./configure --disable-documentation --disable-shared
sudo make install

I’ve put together a very simple Python-script that I’m planning to execute by running a shell_command:

Edit: depreceated, please look at the Github-link below instead.

You then run the code by invoking:

python ikea.py "65537"  "100" "Yellow"

Or, from within Home assistant as a shell command:

ikealight_off: '/usr/bin/python3 /home/homeassistant/.homeassistant/extraconfig/python_code/ikea.py "65537"  "0" "Yellow"'
1 Like

To make code maintenance a bit easier, I’ve put the script here:



I just wrote a minimal web interface for controlling the brightness of Trådfri bulbs.
It’s absolutely dirty code, but I just wanted an working example to start with for now.
You need to install libcoap with dtls like I described here: https://github.com/bwssytems/ha-bridge/issues/570#issuecomment-292036357
You also need to have Flask installed.
Then you can download the server https://gist.github.com/r41d/65be2c7a111ac6c32f24d762ba38612c
Place it one the same level in the file system as the libcoap folder and heed the instructions in the file.
The interface is ugly as hell, but it’s a first step.
Have fun.


I wonder how feasible will it be to wrap the integration with Tradfri with the Hue API. Given the Hue is widely adopted it would give instant compatibility with many other platforms.

1 Like

Is it possible to control the lights without the official gateway - using a zigbee hat or USB stick?

Of course HASS users could do this with the emulated hue, assuming that there is a tadfri component developed.

XBee S2C Modules are available on AliExpress and can be hooked up to Arduino/Raspberries. They are surprisingly expensive though (didn’t see one for less than 22€). But with this I guess you would have to figure out a lot of the details
There’s also a professional ZigBee module available from a german company (https://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control/raspbee/) for ~35€.
They also sell the “ConBee”, which is a ZigBee USB gateway for around 50€.
Both work with HUE, but don’t have Tradfri support yet.
Also they are both more expensive than an official Tradfri gateway… so I think the way to go for now is to speak to the gateway instead of directly to the bulbs.

WIsh we can use the
Tradfri dimmer
Tradfri motion/light sensor

Getting some help from @balloob and @turbokongen, I’ve gotten a bit further in building a light platform for IKEA Tradfri today. All lights (including their name) are loading into the hass frontend, but I’m not able to read or change their states. Have to get some sleep now but will try to continue tomorrow. :slight_smile:


Alright, so after @pautomate went to bed I bought myself some Ikea bulbs and started playing with his code. I extracted the Ikea code from the platform into a standalone file and cleaned it up a bit. This allows for a lot faster iterating on the API code.

I put the final version of my code up on a gist. @pautomate, it’s your code so please make a repo on GitHub so that we can contribute :thumbsup:

To run this code, download the file and name it pytradfri.py. Build coap-client as per instructions above. Then run the following command to execute the file and drop into an interactive shell: python3 -i pytradfri.py IP KEY. As you can see at the bottom of the file, we setup some basic variables to play with:

  • api is method to call the hub
  • hub is a Hub instance
  • lights is a list of your devices that contain lights
  • light is the first device that has lights

Things to try in the shell

  • lights
  • light.set_light_brightness(10) (this works up to 254)

I have a method to set the XY color light.set_light_xy_color(x, y) but couldn’t get it to work yet.

I got some of the constants from homebridge-ikea


Awaiting this news too … I am starting to have too many hubs …

I see. Oh well …

DOes anyone know how the mesh network of Tradfri works (good/bad, with lamps)?

Awesome stuff guys! I have been following very fast ongoing progress made by different developers:


If you have all not already seen that then would advice you to checkout all the links collected there.

Looks like the overall open source home automation community really got together on this one.

One has to believe that developers at Ikea will also be following your public progress on this too.

is this good or bad? :stuck_out_tongue: