NetHue 0.0.11
See the version list below for details.
dotnet add package NetHue --version 0.0.11
NuGet\Install-Package NetHue -Version 0.0.11
<PackageReference Include="NetHue" Version="0.0.11" />
paket add NetHue --version 0.0.11
#r "nuget: NetHue, 0.0.11"
// Install NetHue as a Cake Addin #addin nuget:?package=NetHue&version=0.0.11 // Install NetHue as a Cake Tool #tool nuget:?package=NetHue&version=0.0.11
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
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
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.
- Follow the according steps to find the IP of your HueBridge, and create a client key for access to your Hue Bridge's API - Setup Instructions
- 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" }
- And thats it! Use this created file to create a
HueConfiguration
object by manually parsing the IP and Application Key, or just useHueConfiguration.FromJson("config.json")
. All of the controllers for this package take aHueConfiguration
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.