MadMonkey87 / InnerCore.Api.HueSync

A simple library to communicate with the Philips Hue Sync Box
MIT License
6 stars 1 forks source link

InnerCore.Api.HueSync Build Status NuGet .NET Standard

Open source library for communication with the Philips Hue Sync Box. This library allows you to perform the same actions as you could do with the official app and even more!

Update: the api now has been made available official by signify! See https://developers.meethue.com/develop/hue-entertainment/hue-hdmi-sync-box-api/ (login required).

Requirements

Usage

First you need to know the ip address of your hue sync box. The following code will search for devices in your network:

var discoveryResults = await DiscoveryService.Discover(TimeSpan.FromSeconds(3));

After that you can use the retrieved ip address to instanciate the actual client:

var client = new HueSyncBoxClient(discoveryResults.First().IpAddress);

If you want to test the connection you might fetch some basic details of your device (no authorization needed so far):

var device = await  client.GetDeviceAsync();

Next you'll need to register on the sync box in order to retrieve an access token for further request. Start the process by calling

accessToken = await client.RegisterAsync("Demo", Environment.MachineName);

This will return null initially. Now you'll need to press and hold the button on the box (~3 sec) until the led flashes green. After that you have 5 seconds to repeat the call above to retrieve the access token.

Note 1: simply call the RegisterAsync method every few seconds until you get a token

Note 2: if the led turns red after a quick green flash: relax, all good!

Keep the access token save as you can use it later on! Instead of registering you can simply call HueSyncBoxClient.Initialize() with your token instead.

As the client is now authorized you can retrieve all details of your device (check the descriptions in the code for more details):

var state = await client.GetStateAsync();

You also can perform some actions on the sync box. They are splitted into the following:

Execution commands

These commands allow you to change the current state, i.e enable/disable syncing, change the input, mode or intensity. You can send them one by one but you also can combine them:

var command = new ExecutionCommand()
    .SetMode(Mode.Game)
    .SetIntensity(Intensity.Intense)
    .SetSyncActive(true)
    .SetBrightness(200)
    .SetHdmiSource(HdmiSource.Input2);
await client.PerformExecutionCommandAsync(command);

Behavior command

These are equivalent to settings and just like execution commands, they also can get combined:

var command = new BehaviorCommand()
    .SetArcBypass(true)
    .SetCecPowerSave(false);
client.PerformBehaviorCommandAsync(command);

Device commands

These commands directly affect the device, like rebooting it or checking for firmware updates:

await client.PerformDeviceCommandAsync(DeviceAction.Restart);

Findings

The api reveals a few features that the official app does not yet provide but that are already available trough the api:

License

InnerCore.Api.HueSync is licensed under MIT. Refer to license.txt for more information.

Contributions

Contributions are welcome. Fork this repository and send a pull request if you have something useful to add.