Giter Club home page Giter Club logo

csharptradfrilibrary's Introduction

C# Tradfri Library

This is a .NET Standard (2.0) library 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).

Build Status GitHub last commit NuGet downloads

This library is still in development, latest version:

NuGet downloads

Latest Gateway version tested and working - 1.10.43.

  • Get information on the gateway
  • Observe lights, groups and other resources
  • Get notified when lights, groups and other resources 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 (currently only turn them on/off)
  • Restart and reset gateway

1. Usage

Download the nuget package v1.0.0.x+. You will need the following values:

  • gatewayName is your nickname to your gateway, currently this doesn't have an effect. It is here if you have access to multiple gateways so you can easily differentiate them.
  • gatewayIp is the IP-address to your gateway.
  • appName your name for your application. Be creative but wise with characters.
  • appSecret Instead of reusing key written on the back of your IKEA Tradfri Gateway you have to acquire new secret key specific for your application and then you should use appName and appSecret to connect. TradfriUI has an example on this, but it still does not implement encryption for the appSecret.

2. Example

From Gateway version 1.8.25 you can't use original PSK to connect to gateway anymore. You can only use it to create an application secret for your application which you can later reuse with it.

    // recommended
    // This line should only be called ONCE!!! per applicationName -> you define applicationName as you want
    // Gateway generates one appSecret key per applicationName
    TradfriAuth appSecret = controller.GenerateAppSecret("GatewaySecret", "ApplicationName");

    // You should now save programatically appSecret.PSK value (appsettings) and reuse it
    // when connecting to your gateway every other time
    controller.ConnectAppKey(appSecret.PSK, "ApplicationName");

    GatewayController gatewayController = controller.GatewayController;
    var devices = await gatewayController.GetDeviceObjects();

    DeviceController deviceController = controller.DeviceController;
    await deviceController.SetLight(devices[0], true);
    await deviceController.SetColor(devices[0], TradfriColors.SaturatedRed);

    // same works for `controller.GroupController`

3. Acknowledgements

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

4. Authors

5. Old library

Old library is still available as nuget (latest version: 0.3.0.22) and won't be updated anymore. You can still read it's ReadMe if you are using it but we recommend to migrate to newer library as soon as you can.

6. Changelog

You can check the changelog here.

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.