FluentHue 1.0.0

dotnet add package FluentHue --version 1.0.0
                    
NuGet\Install-Package FluentHue -Version 1.0.0
                    
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="FluentHue" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentHue" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FluentHue" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentHue --version 1.0.0
                    
#r "nuget: FluentHue, 1.0.0"
                    
#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.
#:package FluentHue@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentHue&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FluentHue&version=1.0.0
                    
Install as a Cake Tool

FluentHue (WIP)

Fluent interface for making REST API calls to a Philips Hue Bridge. Almost all functionality has both synchronous and asynchronous support. This is a work in progress and the following functionality is currently supported.

  • Set, toggle, and retrieve the current state of a light which currently includes whether the light is on or off, the light's brightness, and the light's color (if supported).
  • Rename a light.
  • Initiate the Hue bridge to search for new lights with or without looking for specific serial numbers.

Additional features will continue to be added but if you are looking for something specific please email me or create a new issue.

More information regarding the Philips Hue bridge REST API can be found here.

Select Hue Bridge

For cases when you only have one Hue bridge on your local network you can just select the first Hue bridge found using the bridge's broker server discover process.

var bridge = HueBridgeLocator.SelectFirst();
var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);

Otherwise you can select the bridge using its private IP address. In this case no HTTP calls need to be made so there is no asynchronous option. If you know the private IP address is not going to change or would prefer to setup your local network so it doesn't change you could also directly select the bridge using its private IP address so additional HTTP requests do not need to be made to discover the bridge.

var bridge = HueBridgeLocator.SelectWithLocalIp("192.168.1.2");

Authentication

In order to communicate with the Hue bridge you will have to first create a user. This can be done following the instructions here. Eventually we may add support for creating users.

Once you have the username you can specify which user to use when communicating with the Hue birdge using the WithUser method. In this case no HTTP calls need to be made so there is no asynchronous option.

var bridge = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df");

Interacting with Lights

To select which light you wish to interact with you can either retrieve all lights that the bridge knows about or select one with a specific name.

Retrieving All Lights

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var lights = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .GetAllLightsAsync()
    .ConfigureAwait(false);
var lights = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .GetAllLights();

Retrieving a Specific Light

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var light = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom");

Retrieve Current State of Light

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var state = await light.GetCurrentStateAsync().ConfigureAwait(false);
var state = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom")
    .GetCurrentState();

Toggle Light On/Off

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var state = await light.GetCurrentStateAsync().ConfigureAwait(false);
state.ToggleAsync().ConfigureAwait(false);
var state = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom")
    .GetCurrentState()
    .Toggle();

Specifically Set Light On/Off

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var state = await light.GetCurrentStateAsync().ConfigureAwait(false);
state.SetStateAsync(isOn: true).ConfigureAwait(false);
var state = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom")
    .GetCurrentState()
    .SetState(isOn: false);

Setting the Brightness of a Light

Brightness is set on a scale of 1 - 254 with 254 being the brightest state of the light possible.

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var state = await light.GetCurrentStateAsync().ConfigureAwait(false);
state.SetBrightnessAsync(150).ConfigureAwait(false);
var state = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom")
    .GetCurrentState()
    .SetBrightness(150);

Setting the Color of a Light

Color is specified using the CIE 1931 color space where X and Y are floating point values between 0 and 1.

var bridge = await HueBridgeLocator.SelectFirstAsync().ConfigureAwait(false);
var light = await bridge
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLightAsync("Bedroom")
    .ConfigureAwait(false);
var state = await light.GetCurrentStateAsync().ConfigureAwait(false);
state.SetColorAsync(x: 0.25, y: 0.5).ConfigureAwait(false);
var state = HueBridgeLocator.SelectFirst()
    .WithUser("1028d66426293e821ecfd9ef1a0731df")
    .SelectLight("Bedroom")
    .GetCurrentState()
    .SetColor(x: 0.25, y: 0.5);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.0 610 3/2/2020