Control your Philips Hue lights using Google Chrome built in voice recognition

Probably some of you already know about Chrome’s hidden voice recognition APIs which are actually quite good. If you happen to have also Philips Hue lights, with a few lines of code you could create voice controlled lights for your home, and personalize the commands.

Before you start, you might want to take a look at Philips Hue Developer Program and understand how you could send commands to Hue bridge.

If you feel confident enough, let’s get started. Download or clone the code repository from here: HueVoiceControll

Installation

– Place the source code on server, capable to render HTML and Java Script files, that is accessible by browser and is on the same network where your Hue bridge is connected.
– Make sure that you replace ‘user_id’ in hue_controller.js file with the one from your Hue hub. and replace hardcoded bridge IP with yours.
link to discover Philips Hue ip

var hue_controller = function() {};
var user_id = "mfdfLQ6rceWkt0NEedzTChMhASkXD0i6aMXKJIfM";

hue_controller.prototype = {

bridgeURL: "http://10.0.1.4/api/" + user_id,

 

Test It

– Make sure that the computer from where you are going to open Google Chrome and the web server where you added the code are on the same network with Philips Hue bridge.
– Open Google Chrome and navigate to the url of the index.html file
– Bring up the console and try saying “Turn the lights on”
– If everything is set up correctly you will see something like this:

and as you see after a bit of guessing, Chrome comes with the right command. It maps what you define in the command mapping object with what it’s voice recognition discovered.
If you set up the Hue bridge ip correctly, you will see the lights dimming to a dark.

Personalize voice commands

– open ‘main.js‘  and look at the following code snipped in the beginning

var availableCommands = {
  lightson: ['lights', 'on'],
  lightson2: ['turn', 'on', 'the', 'lights', 'light'],
  lightson3: ['lights', 'please'],
  lightsoff: ['lights', 'off'],
  lightsoff2:['turn', 'off', 'the', 'lights'],
  lightsoff3:['shut', 'down', 'the', 'lights'],

  lesslight: [ 'apply', 'less', 'light', 'lights'],
  lesslight1: [ 'dim', 'lights', 'light', 'the'],

  morelight: [ 'apply', 'more', 'light', 'lights'],
=
};

 

It’s basically an object with key = command + next subsequent # (to make it unique) and array of the matching words (words sequence doesn’t matter, but it has to match all words)

commandName# : [ voiceCommand1,voiceCommand2,voiceCommand3]

As you see you can send different commands to Hue bridge and assign different voice command combinations. For example you could add

lightson2: ['turn', 'on', 'the', 'lights', 'light'],
lightson3: ['lights', 'please'],
lightson4: ['let', 'there', 'be', 'light'],

 

and test it by saying “Let there be light”

You could even name your bridge and add the name on each command to make sure that it will not accidentally react on your voice.

If you still reading you probably either manage to make it work, or still have some questions. If so, don’t hesitate to post comments or ask me questions.

For a full list of all Hue API’s you could visit Philips Hue API as a registered user and add extra functionality to your code.

Leave a Reply