Coder Social home page Coder Social logo

anp27 / pytradfri Goto Github PK

View Code? Open in Web Editor NEW

This project forked from home-assistant-libs/pytradfri

0.0 1.0 0.0 346 KB

IKEA Trådfri/Tradfri API. Control and observe your lights from Python. Examples available. On pypi. Sans-io.

License: MIT License

Python 99.20% Shell 0.80%

pytradfri's Introduction

Coverage Status PyPI version

NB: Latest Gateway version tested and working - 1.3.14.

Python class to communicate with the IKEA Trådfri (Tradfri) ZigBee-based Gateway. Using this library you can, by communicating with the gateway, control IKEA lights (including the RGB ones). Some of the features include:

  • Get information on the gateway
  • Observe lights, groups and other resources and get notified when they change
  • 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 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. Stand-alone use (command-line interface)
  3. Implement in your own Python platform
  4. Docker support
  5. Acknowledgements

1. Installation

You might have to use 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 example_sync.py when testing this.

For asynchronous applications you will need to install DTLSSocket, for instance using the requirements file: shell pip install -r requirements.txt . Please note that install might take considerable time on slow devices. Use 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.

2. 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 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 example files.

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 and 3.0 with more effective management of dependencies and consistency around return types. Lennart Buhl @r41d and Maciej Sokołowski @matemaciek made sure the library is supporting RGB bulbs.

pytradfri's People

Contributors

balloob avatar lwis avatar matemaciek avatar lakitna avatar landrash avatar rubenbe avatar orende avatar demianhiemstra avatar schliflo avatar jurriaan avatar r41d avatar novapax avatar bachp avatar chrysn avatar cosmix avatar spektren avatar rudyvan avatar tazle avatar viernullvier avatar

Watchers

Adam Pledger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.