NetHue 0.0.13

dotnet add package NetHue --version 0.0.13
NuGet\Install-Package NetHue -Version 0.0.13
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetHue" Version="0.0.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetHue --version 0.0.13
#r "nuget: NetHue, 0.0.13"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetHue as a Cake Addin
#addin nuget:?package=NetHue&version=0.0.13

// Install NetHue as a Cake Tool
#tool nuget:?package=NetHue&version=0.0.13

NetHue

A C# package for managment of Phillips Hue devices.

  • Based off of the Hue Clip API V2
  • Implementation is currently geared towards basic interaction with the API, such as getting lights, updating the colors of lights, setting scenes, etc.
  • Programmatic creation of scenes, rooms, and so on is currently on hold.
    • The Hue App provides a UI for working with these visual functionalities, consider the current state of this project as an "add on" for interacting with the API programmatically.

License

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Base Concepts

  • Controllers: Handle fetching information about your Hue ecosystem from the configured HueBridge. A controller will (soon to be) exist for each endpoint in the Hue Clip API V2, allowing for programmatic access to Hue resources.
  • Models: Store the information returned from the API. Some fields are renamed due to what I can tell to be as odd choices of names.
  • Repositories: As a user of the package, there should be no direct interation with the repository(s) defined in this package. Handles basic HTTP calls to a Hue bridge.

Getting Set-Up

Package was designed to be as easy to get started with as possible.

  1. Use the HueBridgeDiscovery class to find the IP of Hue bridges connected to your local network. This returns a dictionary or IPs mapped to the name of the HueBridge:
    var bridges = HueBridgeDiscovery.GetHueBridges();
    
  2. according steps to find the IP of your HueBridge, and create a client key for access to your Hue Bridge's API - Setup Instructions
  3. Once you have these values, you're almost there! Create a JSON file titled whatever you like, we will call it: config.json. This file will contain the information you just fetched about your Hue bridge in the following schema:
    {
        "ip": "YOUR_BRIDGE_IP",
        "appKey": "YOUR_SECRET_APPKEY"
    }
    
  4. And thats it! Use this created file to create a HueConfiguration object by manually parsing the IP and Application Key, or just use HueConfiguration.FromJson("config.json"). All of the controllers for this package take a HueConfiguration object as a constructor parameter, or you can provide the path to this file and they'll handle the parsing themselves.
NOTE: Support for HTTPS certificate validation is still a TODO, will be present in first minor release

Basic Examples

  • Example of getting all the lights connected to your Hue bridge & setting them to a random color:

    var controller = new HueLightController("config.json");
    var lights = await controller.GetLights();
    
    foreach (var light in lights)
    {
        await controller.UpdateLightState
        (
            light, 
            new HueLightStateBuilder()
                .Color(RgbColor.Random(light.CieColorGamut));
        )
    }
    
  • Example getting all the lights of a room configured on your Hue bridge:

    var config = new HueConfiguration("config.json");
    var lightController = new HueLightController(config);
    var roomController = new HueRoomController(config);
    
    var room = (await roomController.GetRooms()).First();
    var lights = await lightController.GetLights(room);
    
  • Example setting a scene:

    var controller = new HueSceneController("config.json");
    var scene = (await controller.GetScenes()).First();
    
    await controller.SetScene(scene);
    
  • Example changing the current brightness of a scene:

    var controller = new HueSceneController("config.json");
    var scene = (await controller.GetScenes()).First();
    
    // Set scene to 50 percent brightness.
    await controller.SetSceneBrightness(scene, 50);
    
  • Example changing the brightness of the lights of a zone/room:

    var config = new HueConfiguration("config.json");
    var roomController = new HueRoomController(config);
    var lightController = new HueLightController(config);
    var room = (await roomController.GetRooms()).First();
    
    // Set scene to 50 percent brightness.
    await controller.SetSceneBrightness(scene, 50);
    
  • Example resource state management:

    // This is a slightly more "advanced" example, geared towards 
    // demonstrating how we can keep our models up to date when other
    // applications interact with them (e.g. the mobile Hue app)
    
    var config = new HueConfiguration("config.json");
    var eventRepository = new HueEventRepository(config);
    
    // Currently supported "managable" resources are lights, and scenes. Let's keep track of them :)
    var sceneController = new HueSceneController(config);
    var lightController = new HueLightController(config);
    
    var scenes = await sceneController.GetScenes();
    var lights = await lightController.GetLights();
    
    // Create a hue resource manager with these resources
    var resourceManager = new HueResourceManager()
        .Manage(scenes)
        .Manage(lights);
    
    // Start an event stream, this will run in the background of your application 
    // and keep the HueResource models you fetched up to date
    // If your application has a cancellation token, supply it here for a smooth shut down!
    // Parameter is optional though, and not supplied in this example. 
    eventRepository.StartEventStream(resourceManager); 
    
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.13 233 11/3/2023
0.0.12 108 9/20/2023
0.0.11 102 9/20/2023
0.0.10 80 9/19/2023
0.0.9 115 9/18/2023
0.0.8 96 9/16/2023
0.0.7 177 9/16/2023
0.0.6 126 9/16/2023
0.0.5 106 9/15/2023
0.0.4 128 9/13/2023
0.0.3 112 9/13/2023
0.0.2 115 9/13/2023
0.0.1 119 9/11/2023