Giter VIP home page Giter VIP logo

huetroappservices's Introduction

Huetro App Services [PREVIEW]

With Huetro 7.1, other Windows 10 apps can leverage the power of Huetro to integrate Hue lighting effects into their own apps. With the App Service other apps can send simple LightCommands through Huetro to control Philips Hue lights. You only need a couple lines of code and Huetro will do all the heavy lifting (e.g. authentication, distributing lightcommands!).

How to use?

Clone the HuetroAppServiceClient sample app to get started.

Some basic usage examples:

Opening the AppService connection

Before you can send LightCommands to Huetro, a connection need to be opened. you can communicate with the Philips Hue Bridge, you need to find the bridge and register your application:

  AppServiceConnection huetroService = new AppServiceConnection();
  huetroService.AppServiceName = "com.huetro.appservice";
  huetroService.PackageFamilyName = "27078NielsLaute.HuetroforHue_91se88q2mhfz2";
  
  await huetroService.OpenAsync();

List current lights

To control the lights, you need to send a specific commands with a list of lightbulb IDs that you want to target. To do this, Huetro recommends to show the user a list of light bulbs that can be selected.

To do this, the following command can be used to get the list of connected lights of the Bridge that is currently selected in Huetro.

ValueSet Message = new ValueSet();
Message.Add("Command", "GetLights");
AppServiceResponse response = await huetroService.SendMessageAsync(Message);

This will return a ValueSet where each Key is the light ID and the Value is the name of the light (to display to the user).

Sending light commands

Once you have a list of selected IDs you can start sending requests. Please note that you do not send more than ~10 light commands per seconds, to not overload the Hue Bridge.

To send light commands, we'll have to use the same ValueSet objects to communicate. However, for the commands we'll use the excellent Q42.HueApi LightCommands that provide a nice typed way to set up commands.

Turning on a blue light:

//Turn the light on and set the color to Blue
new LightCommand().TurnOn().SetColor(new RGBColor(0, 0, 255));

Set color or brightness

//Turn light red
new LightCommand().SetColor(new RGBColor("ff0000"));
	
//Turn the light to full Brightness (0-255)
new LightCommand() { Brightness = 255 }

Turn off (with a transition time of 3 seconds)

new LightCommand() { On = false, TransitionTime = new TimeSpan(0, 0, 3));

Once you have this LightCommand we need to serialize it (since AppService communication only allows for strings) and we can then send the command to Huetro:

ValueSet Message = new ValueSet();
Message.Add("Command", "SendLightCommand");
Message.Add("LightCommand", JsonConvert.SerializeObject(new LightCommand().TurnOn(), Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
Message.Add("LightIDs", JsonConvert.SerializeObject(new List<string>() { "1", "2" }, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
AppServiceResponse response = await huetroService.SendMessageAsync(Message);

Succes! Lights 1 and 2 should now turn on.

Open Source Project Credits

Q42.HueApi

  • Q42.HueApi (Light commands)
  • Newtonsoft.Json (Object serialization)

huetroappservices's People

Contributors

niels9001 avatar

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.