#140 IKEA Tradfri IOT Smart Lighting System Hack


Grüezi YouTubers. Here is the guy with the Swiss accent. With a new episode around sensors and microcontrollers. Lately, IKEA jumped on the IOT bandwagon and
released a new line. It is called TRÅDFRI smart lightning, and
is a direct competitor to Philips hue. Tradfri is Danish and means “wire-free”
This line consists of controllers, lamps, and a gateway. As always, IKEA has an attractive price point
for its devices. The cheapest set is around 20 dollars. Mine has variable color temperature and costed
around 30 dollars. Recently I got these two devices from my local
IKEA store it is a Tradfri LED lamp and a controller. So let’s hack it! including a battery
Dangerous but nicely looking: Actually, you see this as a European E27 I think it’s called
plug here we can screw it in somewhere. So, let’s test if it works and how it works. This is magnetic here and can be taken off. So, we open it up to mount the battery. And here we have the manual even for people
who cannot read. We have to switch the lamp on and press this
button for more than 10 seconds and then it will be paired I assume. So, you guys still have to be able to read
a little bit at least that you can read the five centimeters or two inches. Distance. So, let’s try. One two three four five six seven eight nine
ten. So that’s for sure more than ten seconds. Personally, I think it was already paired
because I bought this as a kit together and it is a nice color, not a cold white, more
a warm white. Ahh, it works! I can switch it on and switch it off. So, we have three functions: On/off; the color
temperature and the intensity. Now of
course this is nice but I want to use this with my MQTT stuff. So we have to hack this one here. So always if you start to hack you take out
the battery, because otherwise you might be able to destroy somehow your device electrically,
and this is not what we want. So, let’s continue on the bench. One thing is interesting here: This is marked
from the supplier not from me. It is some handmade stuff here. This is probably not yet a full production
run, it’s maybe still done with some manual work. Here we see, we have one module which is soldered
to a second module. And we also see here that we have some test
points. Fortunately, I got some help. This is a German magazine and they do some
stuff with IOT and so on and they also hacked this one here So I have some information about
the different pins. I do not need to hack them myself. But it’s in German. I will leave a link in the description. Let’s check if it still works because otherwise
it’s useless. It still works! Fortunately, I did not destroy it completely
when I had to take it apart. I connect now all wires according the “MAKE
Magazine” with the different colors. I was really glad that I had wires with all
these colors. So, we have now a clear separation:
Here we have ground, the test points here all connected and three pins of this module
– so let’s do some measurements. Now everything is connected to the test points
and to some other points here and now we try to find out which one is which. I connect it to the orange and here I have
the oscilloscope, and if I press the on/off button you see signal on the orange wire is
on/off. And it has negative logic. If I press it, it shows zero, if I release
it shows three volts. So, let’s check the next one: Yellow is the
left temperature. We hacked the whole thing. We have now three six eight wires and a we
Wemos board which has a 3.3 volts output. So, we can power also this one and I will
do something like that, I will print probably a round housing that I still can use it manually
and I will put in a Wemos board here. Like that. So, I have now to connect all these wires
to this Wemos board. And this is done with my third hand which
I built once in another video. Let’s do it:
I come back when it’s done. Now everything is connected to this Wemos
and I have already a programming USB cable and now I do not need a battery because I
have this red wire connected to 3.3 volts. So, I get the 3.3 volts from the Wemos chip. Let’s now start with programming. Before I start to program, I have a table
here with all the different pins and commands and colors and functions
The sketch is based on the pubsubclient library and on the work of Markus Ulsaß from Hamburg. I used his work, but changed quite a lot in
the area of pin handling. I also added a function which reads the physical
buttons of the remote control and sends it via MQTT. This can be used to control other devices
than the IKEA lamp. Here we have our definitions. The on/off function listens to command 0,
and an orange wire connects it to pin D7 on the Wemos. The «darker» listens to command 2, and a
brown wire is connected to pin D5 In order to simplify the pin handling later
on, I use an array. This array defines which pin belongs to which
command. So, pin D2 belongs to command 0. This is, why D2 is at the first place in the
array. All other pins follow in the right order. If we go now to setup(), we find the MQTT
specific functions. The only thing I had to add is the definition
of the pins as Input pins. Here you see, that I do not need to define
each pin separately, I just need a for loop. The loop() section consists of three parts:
In function «readbutton», I check, if a physical button is pressed on the remote control. If so, I publish a message with the topic
IKEA/BUTTON and the command which fits this button. For non experienced C++ programmers, I focus
on the The variable msg for a moment. It is defined as an array of 50 characters. This means, that we can stuff up to 50 characters
in this variable. But C++ does not know, how long this string
really is. Only if we place a «zero» character at the
end of our string, C++ can handle it. Our message is just one character long. So, I add a zero character at the second place
in the array. Now, everything should work. Here, I make sure, that I do not send the
same command twice. This part is called every 10 seconds and publishes
a «alive» message to the IKEA/STATUS topic. It can be used to check, if something happened
to our remote control. I could have used a delay () to wait the 10
seconds. But then, the whole sketch would not work,
because we frequently have to check, if a button was pressed or if a message arrived. This is, why we used this statement to write
a «non-blocking» code. The rest of the loop() is MQTT specific. But where do we get our messages with the
commands? There is nothing in the loop! This library uses the concept of «callbacks». Here, we defined a so called «callback function”. This function is always called, if a message
arrives. Let’s have a look at what this function
does: It prints the message in Serial monitor and decodes the command. I use human readable ASCII characters as MQTT
payload. So, we have to convert these commands to a
number from 0 to 5, because our commands are byte variables. This is easily done. If we subtract ascii ‘0’ from our human
readable command, it is converted into a byte variable. Simple. To test our sketch, I use my normal Mosquitto
MQTT broker running on a Raspberry Pi zero. We built it in video #126. I also use the Node Red flows which we built
in video #127 and #128. First, I check, if I get the commands and
if the commands are executed by the remote control. And really, the lamp goes on and off if I
send the command 0. And all other commands also work. Now, I want to check if I can read the buttons. Again, success. So, summarized:
We were able to hack the newest IKEA IOT devices and connect them to a MQTT broker using a
small Wemos module. We were also able to connect it to our home
automation system without buying an expensive gateway. In this process, some of us learned some small
programming tricks with arrays. And we learned, why delay() often has to be
replaced by non-blocking code But was this hack a good idea? Yes and no. If we hack available hardware, we often run
into the same problem: These devices do not give any machine readable feedback about the
current status. In manual mode, this is not necessary, because
you can have a look at them and you see, if they are on or off. But if you want to automate them, your computer
has to know the status of the device. Like with the brightness, you can just issue
too many «darker» commands till you are very sure that the lamp is on the lowest level. Now, you can start to count and you are pretty
sure about what happens. This is completely different with the on and
off function. Here, your computer never knows, if the lamp
is really on or off. And this is not what I call a reliable system. It might work for a long time, but you are
never sure. So, this hack is just a first attempt and
good, if you are still around to correct the status if needed. In a next hack, we have to dig one level deeper
and hack the Zigbee protocol. There, I hope, that we will find absolute
commands to switch the lamp really on or off. So, stay tuned. I hope, this video was useful or at least
interesting for you. If true, then like. Bye

100 thoughts on “#140 IKEA Tradfri IOT Smart Lighting System Hack

  1. I expected the system to be called trådlös in stead of trådfri, IKEA being Swedish 😉

  2. nice Video, ty for the Upload!
    I generally enjoy them. have a nice day and see you soon 😀 greatings from austria

  3. Andreas use a guitar pick to open electonic boxes mate. Very enjoyable. Hopefully they will be available in Australia soon.

  4. Great project / video!
    I always like projects that extend or change the original intended functionality of "common" devices

  5. Why don't just use yeelight and homeassistant or tasker instead?

  6. Trådlös is getting real interesting with this MQTT capability and using the Homey, an Alexa-like systems with on board WiFi, IR, BT, NFC, RF-868 and 433, Zigbee 2.4 and Zwave 868.
    https://www.athom.com/en/

  7. This is great video. I am part of a makers space in Chicago and your themes from Lora to MQTT are feeding our creativity. Is the code on github yet? I followed the links but could not find the code. Again, thank you for speaking about such timely subjects!

  8. Disappointed they aren't available in RGBW, or I would consider them. Hue and Lifx provide this and they are missing a trick in not.

  9. With my Samsung smartthings i could send you some raw data of the commands used in zigbeen when turning on and off. and also the handshake most of the lamps use when pairing.

    Samsung smartthings is a great device as you are able to program your own Device handlers and as such include any zigbee device into it by yourself 🙂

  10. hahahaha… next time you are in Copenhagen I teach you to say trÅdfri if you give a beer 😀 trÅd … not trad 😀 😀 Thanks for at super video!!!

  11. Could one take a compatible module that can transmit to your system, add a photo sensor and assign values based on light intensity / resistance and place it next to the light to transmit a general idea as to what it senses? At least it would be something that could be polled by an automation system to provide status but as to sensing wether the light is actually on or off one might have to add a small cut tent sensor to the live phase of the socket and calibrate a micro voltage value to show if light is on or off taking into account that the lamp will always draw some micro amps on standby/off. This could also be used for showing intensity level of the lamp based on how much current is drawn for each step of the lamps brightness. You would be basically creating a smart socket that provides info to your system.

  12. I am impressed, very interesting video as usual. I agree, IKEA har attractive pricing so why not… Now i have to visit IKEA in Haparanda 🙂

  13. @Andreas Spiess, you can look here for more information.
    https://www.youtube.com/watch?v=bNS_fINyaQE
    So based on coap-client, you can make a MQTT gateway.

    (Trådfri is Swedish, and å is not "a", it is pronounced more like "o" in
    english low and fri pronounces like english "free".) 🙂

  14. a remote for a remote… i thought you will find out how they communicate (zigbee, bt, wlan,…) and hijack it. do you think this will be possible? i'ld buy many such lamps if this works.

  15. Interesting hack! Since the light controller is powered by a coin cell battery, what's the current draw on the added wireless module?

  16. Great hack Andreas! I hope that we'll get two way communication working in the future… that would make the system really great for that price. Thumbs up for your work!

  17. IKEA iot devices? I didn't get the "i" for internet…only after your hack the light became part of internet. it appear to be just a cheap radio module… have I missed something?
    nonetheless nice hack

  18. Is it correct to call the delay() function 'blocking'? Obviously, the execution of the user code is stopped, but the background operations (the wifi stuff) are not blocked , but given all the processor time instead. I would argue that this is more than just a semantic issue, as delayMicroseconds() actually is blocking, i.e., the user code will not yield and give any execution time to other tasks.

  19. Thank you for another great video, especially the description of the code!I think this is not an Ikea IOT product since there is no internet involved."Trådfri" is not a Danish word, here it is called "trådløs"

  20. Thank you for the video. How long does the battery last with adding wemos to the circuit?

  21. The name is Swedish and not Danish.
    Trådfri is the name and is a play on the word wireless and that would translate directly into Trådlös but since that's a common name they've translated it incorrectly to Trådfri that would be the translation of wire less.

  22. Just to be clear, wire-less in Danish is Trådløs. Trådfri is just Ikea drinking too much apple juice

  23. Lightning, great, so does it mean they can only flash, or can you also use them for illumination?

  24. if you want to excercise on your swedish accent, Å is better replaced with an O, not A.
    Ä can be replaced with E, and it sounds like the A in the english word "bad".
    Ö is harder to have a reference to… someone else might have an example.

  25. Hi
    This is teardown of IKEA Tradfri lamp: https://www.allaboutcircuits.com/news/teardown-tuesday-ikea-wireless-lamp/
    Maybe it will usefull for you.

  26. Hallo Andreas,

    wollte mal fragen ob dein Account bei Aliexpress auch schon mal bockiert wurde?

    Mir ist das leider kürzlich passiert und ich kann nicht ganz nachvollziehen, wieso Sie das gemacht haben. Muss wohl mit einem Dispute zu tun haben…

    Gruss

    Stefan

  27. Andreas, surely if you can observe the variable step count ie from darkest to lightest setting, from warmest to coolest colour setting. If these settings are non-volatile, you simply create a copy set of registers to hold the current setting. If the settings are volatile, add a "reset registers" function to equal the starting values within a hacked IoT device. A "Master Reset" becomes significant to cover a possible building-wide power outage.

    This I think offers the simplest 'hack' to include an instant response to a reset light fixture ie if there has been a local power outage? Here there is no conceptual problem of 'losing control' as it is just another event command under the control of the end-user. Without a "Reset" command, yes, then it is time consuming to synchronise the components correctly with many opportunities for confusing outcomes!

    Again Andreas, many thanks to you for your excellent trailblazing style and sense of direction. Thought provoking like Swiss mountain air I think!

  28. Love your videos Andreas! By fate, luck or pure coincidence you seem to be passionate about the same things I am obsessed with, and at the same time too. Except you are the master and I am the student. It feels as though your lessons were customized specially for me! Keep them coming! Love your work! Can't wait for the next video!!

  29. Main issue with this system: you cannot control a lamp from more than one remote. This makes it unsuitable to use in a corridor or any setup that needs two remotes, for example, switch on lamp at room entrance and switch off from you bedside table.
    A hack that could fix this limitation would be really useful for a practical (not nerdy) use of this system at home.

  30. Hey, nice video! Just a tip for your title, It's "lighting" not "lightning". I actually thought the video had something to do with der Blitz before I watched it!

  31. Nice hack!
    Why don't you use a current sensing coil/transformer to check if the lamp is on or off?

  32. Trådfri is Swedish and basically means Wireless, "IKEA SWEDISH COMPANY." Though it is not written in the standard way Trådlös which is used as a more common phrase. 😉

  33. Wait…. You know Ikea is Swedish, and you think "trådfri" is Danish? Did you forget your brain somewhere?

  34. One tip if you haven't looked into it is to use Trådfri with the Home Assistant platform (free, open source) which will allow you to do everything much more easily and which is able to monitor the lamps 🙂

  35. TRÅDFRI is not danish, it's swedish! All IKEA stuff have swedish names…

  36. did you see the node red interface to Tradfri? https://github.com/nidayand/node-red-contrib-tradfri

  37. these videos are great to watch before bed very fascinating but not too much activity (in a good way)

  38. The idea for a relatively word-free manual came from Ingvar himself who was born dyslexic. His dyslexia is also the reason why each product is given a unique name.

  39. Trådfri is swedish for wire free and I also like how you can feel that the LEDs have a ''warm'' white with your hand.

  40. it also works without anytthing extra or hacking using the SmartThings hub 🙂

  41. I really hope IKEA will bring some competition into this market. Currently you simply can't get around Phillips Hue since they already have a really good ecosystem. Since IKEA is known for a pretty good quality at a really attractive pricing I hope they'll continue to develop their Smart lighting line. If they continue to add products to their IoT portfolio like RGB bulps, mountable switches and dimmers they'll grow to a serious competitor. If they don't, maybe at least the pricing of Hue bulps will drop 🙂

  42. Your videos are always very well made, informative beyond the basic hack concept. Thank you!

  43. Im trying to do a own lamp with the IKEA chip, i have tried to read the signal from the chip inside the lamp, its the same as the controller in your video and i used the pinout from the german Make site..

    Do you think its possible to make such a projekt?

  44. use a light resistor to sense back based on the same idea. Use a second pair for feedback

  45. E27 is not "European", in it E stands for Edison, and 27 is a diameter in mm. There were many lamps and inventors at that time (circa 1900), but Edison was one of the first who had commercial success, and so the base and the socket used eventually became a standard. It appeared in U.S.A. first, with E26 being most used, although it's in fact 1 inch, which is very close to 26 mm. It and sprawled to Europe, where E27 is used to distinguish from USA's E26 (and different voltage of course), but they are so similar as the difference in diameter is only 1 mm.

  46. Minor error in line starting with `snprintf(msg, 75, ` — as the msg is 50 characters long, this could theoretically lead to overwrite. It's better to write it as `snprintf(msg, sizeof(msg), ` as in this case you don't have to remember the size of your array.

  47. Trådfri is Swedish and means wireless. (IKEA is a swedish company, wish explain all the strange product names)

  48. Dear Andreas, Greetings from London. In the status mater, a light sensor at the room where the lamp will be installed, may be a good idea? Cheers.

  49. Ikea always uses Swedish words, with a few exceptions (mostly Norwegian place names). I don't think trådfri is a word in common usage in Swedish, but both words of the compounded word are Swedish. Both tråd and fri.

  50. The manual is not for "people who cannot read" but rather "multilingual" 🙂

  51. ".. it is a Tradfri LED lamp and a controller.. so.. LETS HACK IT!" — hahaha.. I love that attitude 😛

  52. The manual is mostly pictures so they don't have to print one for every country/language, not for people who can't read (like 45). I love your videos.

    Is there anyway to link the lights to a hub (I have a wink hub, but IKEA's hub would be fine) without buying a remote just for pairing?

  53. I am still baffled that there is no wall mounted lightswitch-replacement for these smart bulbs. How are you expected to use the system? Tape over the old on/off powerswitch on the wall and stick the ikea remote to the wall? That can't be a solution.

    So I plan to open up the ikea remote and hook it up to a Feller light switch (which is disconnected from the mains power), so when I press the regular light switch it closes the circuit of the ikea remote and switches the lights. The ikea remote can then be mounted inside the wall, behind the old switch. A 230v-to-3V step down regulator should replace the coin cell battery of the remove, making this system maintenance free.

  54. You don't need to use a Dremel to open the remote. I made a video that shows how to open it non-destructively:
    https://www.youtube.com/watch?v=NMupi1FeAB8

  55. Tråd=thread or another word for cord (kabel, sladd in swedish). Fri is free or less . Trådfri is ikea-swenglish for cordless.
    You can translate from swedish to english in two words. tråd fri = thread free.
    Thanks Andreas for all your good work.
    And btw. To be a little bit swedish you have to pronounce IKEA in swedish. [ee-kay-ya as one word eekaya]

  56. Very good job done. I hope you will make custon design Zigbee like this. I wonder to learn more about Zigbee device.

  57. From their own IKEA website:
    -Can I develop the TRÅDFRI system by getting access to the systems API?

    Not in the first release. But IKEA is working towards an open system.

    -What protocol do the IKEA smart lighting products use?

    IKEA smart lighting products use the ZigBee Light Link, which is an open standards protocol aimed at remote control. The lights create a mesh network with each other, enabling each light to pass on messages to the next. IKEA Smart Lighting products are compatible with other products according to the ZigBee Alliance. You can find more information at: zigbee.org

  58. use hass io to integrade with the gateway, 40eur exta, but worth it

  59. But doesn't Tradfri also have a hub which works on a more common standard and can even be used with Hue?

  60. Hi, could you please post the ESP_IKEA_GATEWAY_MAKE_ASP final code as reported in your video? Thank great job!

  61. Since when is Tradfri Danish? Ikea comes from Sweden and it's for sure Swedish! xD

Leave a Reply

Your email address will not be published. Required fields are marked *