Skip to content

Control and observe your IKEA Trådfri (Tradfri) light devices from Python. Also works with Philips Hue bulbs. Example script available to quickly get started. Sans-io.

License

Notifications You must be signed in to change notification settings

matemaciek/pytradfri

 
 

Repository files navigation

Pytradfri

This is a Python class to communicate with the IKEA Trådfri (Tradfri) ZigBee-based Gateway. The gateway can control IKEA lights and also Philips Hue bulbs. Some of the features include:

  • Get information on the gateway
  • 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)
  • List smart tasks (wake up, on/off and not home) and their attributes
  • Observe lights, groups and other resources and get notified when they change
  • Alter values in smart tasks (some of these features not available in app yet)

Table of contents:

  1. Installation
  2. Stand-alone use (command-line interface)
  3. Implement in your own Python platform
  4. Docker support
  5. Acknowledgements

1. Installation

In order to use the code, you first need to install libcoap(sync), or cython3, tinydtls and aiocoap depending on which functionality you're interested in, as per the following instructions (you might have to use sudo for some commands to work).

For synchronous functionality please install libcoap using this script..

For asynchronous functionality please install tinydtls and the tinydtls branch for aiocoap using this script..

2. 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 KEY

Where the following variables are substituted:

  • IP is the IP-address to your gateway.
  • KEY is written on the back of your IKEA Tradfri Gateway.

Examples of commands in the stand-alone prompt:

List all lights:

lights

Set brightnes 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))

3. Implement in your own Python platform

Please see the files, example_sync.py, or example_async.py.

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

5. Acknowledgements

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

A lot of work was also put in by Paulus Schoutsen (@balloob) who took the initial code concept into this library, further work was done by Lewis Juggins (@lwis) to take the library to 2.0 with support for asyncio.

About

Control and observe your IKEA Trådfri (Tradfri) light devices from Python. Also works with Philips Hue bulbs. Example script available to quickly get started. Sans-io.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.4%
  • Shell 1.6%