Ikea Illuminati
Charly's Column – libcoap
Charly did a spot of shopping in a furniture store and came out with a smart lighting system that he has now automated with a Linux PC: Read on for further enlightenment.
Trådlös is the Swedish word for "wireless" and thus throws light on the name of the TrÂdfri smart lighting system. In the simplest case, you combine a lamp with an actuator: A remote control, a dimmer, and a motion detector are offered.
If you also want to use an Android or Apple smartphone to control the light source's brightness – and in many cases also modulate the light temperature from cold to warm white – you need a gateway, which is a small control box that connects to your Ethernet network and sends commands to the lighting systems. ZigBee Light Link [1] acts as the protocol in this case, but customers also can use compatible lamps with E14, E27, and GU10 sockets and LED panels that can be hung on the wall or built in to furniture.
That's all quite nice, but, of course, I do not want to control everything with an app. Instead, I want the lighting system to adapt dynamically to the ambient light, such as gradually becoming brighter at the onset of dusk. The Linux PC that evaluates the data from my photovoltaic system knows when it turns dark (otherwise, a simple brightness sensor will do the trick), and it is precisely this Linux PC to which I want to pass the Ikea gateway commands so that it can pass them on to the lights.
I do so with libcoap [2], a C implementation of the machine-to-machine Constrained Application Protocol (CoAP). The installation requires the commands in Listing 1. Doing this gave me the coap-client
program, which I used to pass the parameters to the gateway that controls the lights.
Listing 1
Installing libcoap
sudo apt-get install libtool autoconf automake buid-essential git clone --recursive https://github.com/obgm/libcoap.git cd libcoap git checkout dtls git submodule update --init --recursive ./autogen.sh
Wrapped for Pleasure!
Because the syntax of the program is pretty horrific, I used a Python wrapper [3] that makes working with libcoap pure pleasure. The entry
sudo pip install tqdm git clone https://github.com/sandyjmacdonald/ikea-smartlight cd ikea-smartlight
installs it. I then dropped a file with the IP address of the gateway and its security code, which you will find on a label glued underneath the housing, into the current directory:
[tradfri] hubip = 10.0.0.42 securityid = laskuhgoACBUWHG
I now have access to simple control and status commands. Figure 1 is the output from tradfri-status.py
, showing that it has discovered two light sources that are combined into a group. Each lamp and the group have an ID that I can use for control purposes. For example, to switch all lights in the present group 133164 to 75 percent brightness, I just need the following command:
tradfri-groups.py -g 133164 -a brightness -v75
By December 13, the Swedish St. Lucia celebration, I will definitely have programmed a suitable candle simulation for my living room.
Charly Kühnast
Charly Kühnast manages Unix systems in the data center in the Lower Rhine region of Germany. His responsibilities include ensuring the security and availability of firewalls and the DMZ.
Infos
- ZigBee Light Link: http://www.zigbee.org/zigbee-for-developers/applicationstandards/zigbee-light-link/
- libcoap: https://libcoap.net
- Ikea-smartlight wrapper: https://github.com/sandyjmacdonald/ikea-smartlight
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.