Skip to main content

IKEA Trådfri/Tradfri API. Control and observe your lights from Python.

Project description

Coverage Status PyPI version Reviewed by Hound

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:

  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. Acknowledgements

Installation

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.8.25
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
TRADFRI wall plug 2.0.022

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.

Acknowledgements

This is an implementation based on analysis I found here by vidarlo.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytradfri-7.0.4.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

pytradfri-7.0.4-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file pytradfri-7.0.4.tar.gz.

File metadata

  • Download URL: pytradfri-7.0.4.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

File hashes

Hashes for pytradfri-7.0.4.tar.gz
Algorithm Hash digest
SHA256 bef941f479ef1151bf266d158aa6978c709d03943ccd35ecc4f2c006a47c0824
MD5 12847d0ab8a4594527b6e35a7905d6c5
BLAKE2b-256 a07c378c2b37153c5f14e49b1546e9c022879b36360a51f16b7464b3221025f5

See more details on using hashes here.

File details

Details for the file pytradfri-7.0.4-py3-none-any.whl.

File metadata

  • Download URL: pytradfri-7.0.4-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

File hashes

Hashes for pytradfri-7.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 db4f0e0a5d8f7dd80ae50290cd8706b8fc5d95671b72040f93a722142c3c7b3b
MD5 889f4be924d3bdc94dea93e06d5fa60f
BLAKE2b-256 64529f61ad605eb56a2c848232d79473073df1e6ac14ce5a56a45a79ba5dd880

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page