Skip to main content

PyPI version

Python package to communicate with IKEA's Trådfri (Tradfri) ZigBee gateway. By using this library you can communicate with the gateway and control IKEA's lights, wall plugs and other peripherals.

In July 2024, IKEA announced they will no longer provide updates to the gateway in favor of their Dirigera hub, which this library does not support. We will continue to update this library with security patches and bug fixes.

This library is strictly typed.

Some of the features include:

  • Gateway:

    • Get information on the gateway, list all devices connected to the gateway, and restart and reset the gateway
  • Any connected device or group:

    • Observe state and get notified when it changes
  • Lights:

    • List all lights, get and control attributes of lights (name, state, color temp, dimmer level etc)
  • Wall plugs:

    • List all wall plungs, and control wall plugs
  • Air purifier

    • List all purifiers, control fan level, and get air quality level
  • Window blind

    • List all blinds, control cover level, and get battery level
  • Smart tasks:

    • 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:

  1. Installation
  2. Verified Device Compatibility
  3. Stand-alone use (command-line interface)
  4. Implement in your own Python platform
  5. Docker support
  6. Known issues
  7. Contributions

Installation

The easiest way of getting started is by running this library in VS Code online, or by installing it locally using the included containerized development environment for VS Code.

For other installation methods, you might have to use superuser privileges (sudo) for some commands to work when installing.

To use the library in a synchronous application, you first need to install libcoap using this script. Use examples/example_sync.py when testing this.

For asynchronous applications you will need to install pytradfri[async], for instance using the requirements file: 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

Device Version
IKEA Gateway (E1526) 1.19.32
TRADFRI bulb E14 WS opal 400lm 1.2.217
TRADFRI bulb E14 WS 470lm 2.3.087
TRADFRI bulb E27 WS opal 980lm 2.3.087
TRADFRI bulb E27 W opal 1000lm 2.3.086
TRADFRI remote control 2.3.014
TRADFRI motion sensor 1.2.214
TRADFRI wall plug 2.0.022
Starkvind air purifier 1.1.001

Stand-alone use (command-line interface)

Screenshot of 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:

lights

Set the brightness of item 1 to 50 in lights list:

api(lights[1].light_control.set_dimmer(50))

Observe a light for changes:

def change_listener(device):
  print(device.name + " is now " + str(device.light_control.lights[0].state))

api(lights[0].observe(change_listener))

Implement in your own Python platform

Please see the example files.

Docker support

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.

Known issues

We are aware of issues some users face with their gateways. Anecdotal evicence suggests sending many requests (spamming) the gateway, or an unreliable network connection can be the culprit. As a first solution, try to limit the number of requests, and move the Gateway closer to the device running pytradfri on the nework. Other than that, there is unfortunately not anything this project can do to support or resolve these issues at this time. As this progresses, we will ensure the project is kept up-to-date.

Contributions

We encourage contributions to this library. Please make sure contributions meet these requirements:

  • Your contribution contains type annotations. This is a strictly typed library: new contributions will not be merged unless they contain type annotations.
  • Your contribution is covered by tests.

Pytradfri - A library from the Open Home Foundation

Release files for pytradfri 14.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytradfri 14.0.0
File Size Uploaded
pytradfri-14.0.0.tar.gz 41.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytradfri 14.0.0
File Interpreter ABI Platform
pytradfri-14.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.0 kB

Release files / pytradfri-14.0.0.tar.gz

Download URL pytradfri-14.0.0.tar.gz
Size 41.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05dca2680b6b47e559c8ab321db595805769ffa6b7170a8d1a3bdf1d3442714f
BLAKE2b-256 checksum
How to use checksums
23cc4cfc2ce3ff3e561d4ba43b15d5a8609a0b3ff75297e64753888cc37703ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / pytradfri-14.0.0-py3-none-any.whl

Download URL pytradfri-14.0.0-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c48411cf864e40219ce0aab555fd7f30cb33530b7895fa264df76dabaab2af9
BLAKE2b-256 checksum
How to use checksums
ba8f3b0b33291ac642ad3700cc7f2ca5d8550ab82c79ca89baf32c20eba8de96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

14.0.0 This release

2 release files

12.0.1

2 release files

12.0.0

2 release files

11.0.0

2 release files

10.0.1

2 release files

10.0.0

2 release files

9.0.1

2 release files

9.0.0

2 release files

8.0.1

2 release files

8.0.0

2 release files

7.2.1

2 release files

7.2.0

2 release files

7.1.1

2 release files

7.1.0

2 release files

7.0.7

2 release files

7.0.6

2 release files

7.0.5

2 release files

7.0.4

2 release files

7.0.3

2 release files

7.0.2

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.4.0

1 release file

6.3.1

1 release file

6.3.0

1 release file

6.1.0

2 release files

6.0.1

1 release file

5.6.1

1 release file

5.6.0

1 release file

5.5.1

1 release file

5.4.2

1 release file

5.4.1

1 release file

5.4.0

1 release file

5.3.1

1 release file

5.3.0

1 release file

5.2.2

1 release file

5.2.1

1 release file

5.2.0

1 release file

5.1.1

1 release file

5.1.0

1 release file

5.0.0

1 release file

4.1.0

1 release file

4.0.5

1 release file

4.0.4

1 release file

4.0.3

1 release file

4.0.2

1 release file

4.0.1

1 release file

4.0.0

1 release file

3.0.4

1 release file

3.0.3

1 release file

3.0.2

1 release file

3.0.1

1 release file

3.0

1 release file

2.2.3

1 release file

2.2.2

1 release file

2.2.1

1 release file

2.2

1 release file

2.1.1

1 release file

2.1

1 release file

2.0

1 release file

1.1

2 release files

1.0

1 release file

0.5

1 release file

0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page