I wrote about playing with Ikea Trådfri before, but, Ikea pushed an update back in October that changed the process. Basically you need to get a personal/device key first, instead of just using the security code on the gateway.

You can send a discovery request, and get back all the valid end-points, without getting a psk;
coap-client -m get -u "Client_identity" -k "your_security_code" "coaps://192.168.0.20/.well-known/core"

But for most things you need that psk. Send the request;
coap-client -m post -u "Client_identity" -k "your_security_code" -e '{"9090":"your_device_id"}' "coaps://192.168.0.20:5684/15011/9063"
And it will reply with your psk, like;
{"9091":"abc1D2eFghiJKLMn","9029":"1.3.0014"}

Now if you want to query the list of devices;
coap-client -m get -u "your_device_id" -k "your_psk" "coaps://192.168.0.20:5684/15001"

To query the state of a device/bulb;
coap-client -m get -u "your_device_id" -k "your_psk" "coaps://192.168.0.20:5684/15001/65540"

There are more settings in "3311" now.

"5850" controls on/off and takes 0 or 1.
"5851" controls brightness, and takes values between 0 and 255.
"5709" and "5710" seem to work together to control the colour temperature.
"5706" is clearly a colour hex code.
"9003" is a mystery.

"5717" and "5711" are specific to the white bulbs.
"5707" and "5708" are specific to the white/colour bulbs.

Yes, I picked up a colour bulb. You can set a colour like;
coap-client -m put -u "your_device_id" -k "your_psk" -e '{ "3311" : [{ "5706":"d6e44b" }] }' "coaps://192.168.0.20:5684/15001/65540"

I indexed the colour options; there are 9 reachable from the remote, and 20 from the app colour picker (11 in addition to the remotes 9). But. It seems like only certain colour hex codes are valid. Setting an invalid one returns the bulb to base colour (neutral yellow, which is known as 'Everyday').

Shades of white;
"5707":2681,  "5708":4360,  "5709":21109, "5710":21738, "5706":"dcf0f8"
"5707":5989,  "5708":12964, "5709":22584, "5710":23272, "5706":"eaf6fb"
"5707":5800,  "5708":24394, "5709":25022, "5710":24884, "5706":"f5faf6"
"5707":5129,  "5708":40781, "5709":29713, "5710":26431, "5706":"f2eccf"
"5707":5427,  "5708":42596, "5709":30015, "5710":26870, "5706":"f1e0b5"

Valid colours;
"5707":5309,  "5708":52400, "5709":32886, "5710":27217, "5706":"efd275"
"5707":4980,  "5708":62974, "5709":35848, "5710":26214, "5706":"ebb63e"
"5707":4137,  "5708":65279, "5709":38011, "5710":24904, "5706":"e78834"
"5707":1662,  "5708":53420, "5709":38011, "5710":22938, "5706":"e57345"
"5707":1490,  "5708":61206, "5709":40632, "5710":22282, "5706":"da5d41"
"5707":0,     "5708":65279, "5709":42926, "5710":21299, "5706":"dc4b31"
"5707":62148, "5708":49198, "5709":32768, "5710":18350, "5706":"e491af"
"5707":62007, "5708":41158, "5709":29491, "5710":18350, "5706":"e8bedd"
"5707":59789, "5708":65279, "5709":32768, "5710":15729, "5706":"d9337c"
"5707":55784, "5708":44554, "5709":22282, "5710":12452, "5706":"c984bb"
"5707":53953, "5708":65279, "5709":20316, "5710":8520,  "5706":"8f2686"
"5707":47822, "5708":65279, "5709":11469, "5710":3277,  "5706":"4a418a"
"5707":47324, "5708":51774, "5709":13107, "5710":6554,  "5706":"6c83ba"
"5707":11383, "5708":65279, "5709":26870, "5710":33423, "5706":"a9d62b"
"5707":8572,  "5708":55985, "5709":29491, "5710":30802, "5706":"d6e44b"

And there's no option to fade from one colour to the next, nor a colour cycle option. I can script changing colour values, but the valid ones are so distinct that the change is too jarring. The investigation continues.
The Ikea Trådfri lights look very interesting. While not cheap, they are much more affordable than other wireless 'smart' lighting. They don't do RGB colours (yet), but you can control the colour temperature; ordinary neutral soft yellow, a warm orange, or a bright white. You can also dim the lights, and of course, turn them on and off. They don't do too much, but what they do they do well, and there don't appear to be any major security holes. But most interestingly, they use ZigBee, and seem to be built on top of a lot of open source stuff. Which means, there are already tools to play with them.

First thing you're going to need to do is get some Trådfri lights. They do have a starter kit, but I wanted the smaller E14 bulbs so I built my own (for not much extra). You'll need the Gateway hub, a control device (remote control definitely works, I don't know about using the dimming set, or motion sensor instead), at least one bulb, and have a lamp/socket to put it in.



Supplies; gateway, remote control, two E14 bulbs, and two lamp shades
Photo by [personal profile] chebe



The Gateway has a companion app to set everything up. You pair the app (your phone) to the Gateway, then you pair the Remote Control to the Gateway. Then you add the bulbs (pairing through the Remote Control) one by one. The app lets you arrange the bulbs into separate groups, or lump them all into one if you prefer. Once all that is done, it's time to build your own control interface.

Mostly I followed this excellent tutorial from the lovely Pimoroni crew.

sudo apt-get install build-essential autoconf automake libtool
(Or on Fedora;
sudo dnf install build autoconf automake libtool)

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


You're going to need the Gateway IP address. You can log into the router, or scan the network. The Pimoroni tutorial found their's at 192.168.0.10. I found mine at 192.168.0.20, so it probably jumps in steps of 10 until it finds an empty slot.
There is a Security Code on the base of your Gateway, you'll need to make a note of it.

The endpoint protocol is coaps:// and the port is :5684, followed by 15001 to control bulbs individually, or 15004 to control as a group.

A good way to start is by sending info requests to both endpoints;
coap-client -m get -u "Client_identity" -k "your_security_code" "coaps://192.168.0.20:5684/15001"
You'll get back an array of devices;
[65536,65537,65538]
It's a bit predictable. The first number is your remote control, the next two are bulbs, in the order you paired them.

coap-client -m get -u "Client_identity" -k "your_security_code" "coaps://192.168.0.20:5684/15004"
Also gives you back an array, but with the group ids, which seem much less predictable. (You can also find the group ids in the app.)

You can append the ids to the requests to get more information about each. Helpfully, there is an English description (i.e. "TRADFRI remote control", "TRADFRI bulb...", etc) returned in each.

The bulbs have a field "3311" with detailed state information. You can set parts of this to control the lights with -m put commands, e.g.;
coap-client -m put -u "Client_identity" -k "your_security_code" -e '{ "3311": [{ "5850": 0 }] }' "coaps://192.168.0.20:5684/15001/65537"
"5850" controls on/off and takes 0 or 1.
"5851" controls brightness, and takes values between 0 and 255.
"5709" and "5710" seem to work together to control the colour temperature. Valid values can be found by using the Remote Control, and then querying the state. The three main ones seem to be;
-e '{ "3311": [{ "5709":24933, "5710":24691 }] }' for bright white,
-e '{ "3311": [{ "5709":33137, "5710":27211 }] }' for warm orange,
-e '{ "3311": [{ "5709":30138, "5710":26909 }] }' for neutral yellow.


But this is all from the terminal. There is a nice python wrapper (with come convenience calls) if you want to start calling it from python, which is helpful if you want to start using python libraries for interfacing with hardware on your Raspberry Pi Zero W. But you'll find all of that in the tutorial.

There's also so much beautiful info in the thread that started all this. Have fun!



Ikea Trådfri lights controlled from Raspberry Pi Zero W
Photo by [personal profile] chebe



*EDIT* As of October 2017 Ikea pushed a new version that requires getting a pre-shared-key to control the lights, I've posted about it here. */EDIT*

Profile

chebe: (Default)
chebe

Syndicate

RSS Atom

June 2025

M T W T F S S
      1
23 45678
9101112131415
1617 1819202122
2324 2526272829
30      

Expand Cut Tags

No cut tags

Style Credit