HueLightController is a Universal Windows Platform (UWP) app sample that explores integrating Windows features with intelligent home automation. Specifically, it shows how you can use Cortana and Bluetooth Low Energy (Bluetooth LE) to create an interactive experience with the Phillips Hue Lights (a Wi-Fi enabled lighting system).
With Cortana integration, users are able to naturally interact with the lights through speech. They can turn the lights off, change their color, or even engage with Cortana in a back-and-forth conversation to adjust a specific light or change all the lights at once.
Additionally, through Bluetooth LE, the app supports a proximity scenario where the lights are automatically turned on/off depending on a user's device relative to a Bluetooth LE beacon.
The HueLightController app demonstrates:
- Using the HttpClient methods and Newtonsoft.json to interact with the Hue lights' RESTful interface.
- Extending Cortana to provide an intuitive voice interface for manipulating the lights.
- Using BLE APIs in the background to watch for a BLE beacon indicating proximity to the lights.
- Showing an extended splash screen for more time while the app connects to the Hue hub and searches for lights.
This sample requires Visual Studio 2015 and the Windows Software Development Kit (SDK) for Windows 10.
Additionally, to be informed of the latest updates to Windows and the development tools, join the Windows Insider Program.
The default project is HueApp and you can Start Debugging (F5) or Start Without Debugging (Ctrl+F5) to try it out. The app will run in the emulator or on physical devices, though functionality related to Cortana and Bluetooth LE is dependent on hardware support. Specific requirements are:
- Phillips Hue lighting system (any version).
- A device running Windows 10 that is connected to the Internet, on the same local network as the Hue lights, and supports Bluetooth LE 4.0 or higher (for Bluetooth LE).
- A second device that supports Bluetooth LE running the Windows 10 Bluetooth advertisement sample to act as the proximity beacon. You can also use a standalone Bluetooth LE device, but you'll need to modify HueLightController's code to receive the correct signal.
If you’re just interested in code snippets for certain API and don’t want to browse or run the full sample, check out the following files for examples of some highlighted features:
- Bridge.cs handles core Hue interactions with the Hue hub, such as registering the app, finding lights, getting light state, and sending HTTP commands to the lights.
- Light.cs represents a Hue light on the network. It contains properties such as on/off, color, brightness, and so on. Changes to these properties will be reflected on the actual light.
- HsbColor.cs converts standard aRGB colors (used in Universal Windows apps) to HSB (used by the Hue lighting system).
- Initalizer.xaml contains the image and layout to use for the extended splash screen.
- Initalizer.xaml.cs manages positioning the extended splash screen, loading all the relevant Hue resouces, and then dismissing the extended splash when finished.
- VoiceCommands.xml defines the structure of voice commands Cortana should recognize as Hue-related so that they can be routed to the HueLightController app. At first, VoiceCommands.xml only specifies the types of phrases Cortana is looking for - the actual words she accepts are added programatically by Initalizer.xaml.cs. For example, VoiceCommands.xml states Cortana is listening for a phrase like "Turn my lights [color]," while Initalizer.xaml.cs modifies VoiceCommands.xml to include the list of valid colors (red, blue, etc).
- Initalizer.xaml.cs prepares Cortana so she's ready to process Hue commands in the background, even if HueLightController isn't running. This includes dynamically modifying VoiceCommands.xml with the list of valid lights and colors.
- Cortana.cs receives voice commands from Cortana in the background, processes the user's request (including requesting clarification from the user, if needed), and then sends the appropriate command to the Hue lights.
- MainPage.xaml.cs enables or disables the Bluetooth LE background proximity background watcher.
- Bluetooth.cs processes Bluetooth LE advertisements and turns the lights on or off depending on the user's proximity to the beacon device.
Cortana interactions
Display an extended splash screen for more time
Bluetooth advertisement sample
Cortana voice command sample
Philips Hue Developer Program