#devices #ikea #manage #light #time #api #trådfri

bin+lib dirigera

Manage your IKEA Trådfri devices with Rust

2 unstable releases

0.2.0 Feb 22, 2024
0.1.0 Dec 3, 2023

#1 in #ikea

MIT license

41KB
772 lines

dirigera - Manage your IKEA devices

This crate is under development and can change at any time! Do not use just yet!

[!NOTE]
I only have a few IKEA devices so most of the endpoints I've been trying has been for lights. I also don't use scenes extensively but tried to set up and configure all available ones to research the API. If you have any other devices and want to contribute to the code that would be much appreciated!

Setup

To communicate with the Dirigera device you need to know its IP address and obtain a token. I can't help you find the IP but usually you can see this by looking at your routers device list.

Once you figured that out, run the generate-token binary to generate a file named config.toml that will store the device's IP address and the obtained token.

cargo run --bin generate-token --features binary <your-ip-address>

When you have a valid configuration file you can use the default trait for the Hub to generate an instance that will call the configured IP address with the configured token.

let hub = dirigera::hub::Hub::default();

NOTE Since the configuration file depends on toml support for this is hidden behind a feature flag called config. To skip using toml simply use the new constructor and pass IP and token.

Configuration file

If you want to create the configuration file manually, this is what it looks like:

ip-address = 192.168.1.101
token = "abc123..."

Usage

See examples for examples on how to use this crate.

Manual testing

Just use the token you got and your favourite HTTP client.

 http --verify=no \
  "https://[ip]:8443/v1/devices" \
  "Authorization: Bearer $TOKEN"

Acknowledgement

  • Leggin/dirigera for the inspiration and most of the information of the API, including token generation.

Dependencies

~13–26MB
~484K SLoC