Python package to communicate with the IKEA Trådfri (Tradfri) ZigBee Gateway compatible with ZigBee Light Link products. By using this library you can communicate with the gateway and control IKEA's lights and wall plugs.
Some of the features include:
- Get information on the gateway
- Observe lights, groups and other resources and get notified when they change
- Control wall plugs
- List all devices connected to gateway
- List all lights and get attributes of lights (name, state, color temp, dimmer level etc)
- Change attribute values of lights (name, state, color temp, dimmer level etc)
- Restart and reset the gateway
- List smart tasks (wake up, on/off and not home) and their attributes
- Alter values in smart tasks (some of these features not available in app yet)
Table of contents:
- Verified Device Compatibility
- Stand-alone use (command-line interface)
- Implement in your own Python platform
- Docker support
You might have to use superuser privileges (sudo) for some commands to work when installing.
For asynchronous applications you will need to install
pytradfri[async], for instance using the requirements file:
shell pip install pytradfri[async]. Please note that install might take considerable time on slow devices. Use examples/example_async.py when testing this.
Security best practice is to not store the security code that is printed on the gateway permanently in your application. Please always use the PSK when communicating with the gateway.
Verified Device Compatibility
|IKEA Gateway (E1526)||1.4.15|
|TRADFRI bulb E14 WS opal 400lm||1.2.217|
|TRADFRI bulb E27 WS opal 980lm||1.2.217|
|TRADFRI bulb E27 W opal 1000lm||1.2.214|
|TRADFRI remote control||1.2.214|
|TRADFRI motion sensor||1.2.214|
Stand-alone use (command-line interface)
If you want to test this library stand-alone in a command-line interface:
$ python3 -i -m pytradfri IP
Where IP is substituted by the IP-address to your gateway.
The first time running pytradfri you will be asked to input the 'Security Code' found on the back of your IKEA gateway.
Examples of commands in the stand-alone prompt:
List all lights:
Set the brightness of item 1 to 50 in lights list:
Observe a light for changes:
def change_listener(device): print(device.name + " is now " + str(device.light_control.lights.state)) api(lights.observe(change_listener))
Implement in your own Python platform
Please see the example files.
There is a Docker script available to bootstrap a dev environment. Run
./script/dev_docker and you will build and launch a container that is ready to go for both sync and async. After launching, follow the above instructions to test the library stand-alone.
The working directory of the Docker image is
/usr/src/app. The checked out version of this repo is added there and installed as a Python dependency for easy development and testing. When you want to use the latest stable version from pip, you only have to change to another working directory.
Paulus Schoutsen (@balloob) made a working Python library of the initial code concept. Lewis Juggins (@lwis) added support for asyncio and improved management of dependencies and consistency around return types. Many others have contributed too.