IKEA Trådfri Gateway [Zigbee]

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.

2 Likes

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:

3 Likes

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

2 Likes

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:

I personally think that this will push Ikea to release an open API sooner. So its good! :smiley:

Thank you @balloob! I’ve added the code into this Github library and will now continue development and integration.

Great! I’ll update my gist to point at your repo.

Spend some time adding support to the lib for moods, groups and changing data, including setting light brightness/state/color.

Also added a Dockerfile so it is easy to test the lib if you have Docker installed:

./script/dev_docker
[… wait till you get into a shell inside Docker container …]
python3 -i -m openikeatradfri <IP> <KEY>

For those who are intressted, I’ve created a set of python scripts around libcoap to get status from the tradfri lights and groups, and you can control the basic functions: power on/off, dim(brightness) and color temperature (only for lightsbulbs)

1 Like

hi there! just bought a trådfri gateway and a few devices, great to see there’s already some people working on this! I am happy to contribute to development and have a long weekend coming up, give me a shout if you have something in mind. I’ll dig into the code and start fiddling around with it otherwise.

oh and thank you for all your work! took my less than 10 mins from 0 to switching lights on and off :smile:

The current state of the Home Assistant platform is that it gets all the devices, can switch off and on (sort of) and gets the dimmer state. Will work on setting dimmer state tonight.

3 Likes