Ashish Datta
Published

Philip Hue Lights + Intel Edison

Controlling Philip Hue Lights with Intel Edison using NodeJS

IntermediateFull instructions provided2,195
Philip Hue Lights + Intel Edison

Things used in this project

Hardware components

Philip Hue Lights
×1

Story

Read more

Code

Hue.js

JavaScript
Using the awesome Node-hue-api (https://github.com/peter-murray/node-hue-api) I created this example using Node Repl to input commands.
var repl  =  require('repl');
var hue = require("node-hue-api"),
    HueApi = hue.HueApi,
    lightState = hue.lightState;
    state = lightState.create();


var displayResult = function(result) {
    console.log(JSON.stringify(result, null, 2));
};

var host = "IP ADDRESS OF HUE BRIDGE",
    username = "MAC ADRRESS OF HUE BRDIGE",
    api = new HueApi(host, username),
    state;

var replServer = repl.start({
	prompt: "Hue > "
});

var on = function() {
	state = lightState.create().on().rgb(0,255,0); 
	api.setLightState(1, state.rgb(0 ,0 , 255 ))
	    .done();
	api.setLightState(2, state.rgb( 0 , 255 , 0 ))
	    .done();
	api.setLightState(3, state.rgb( 255 , 0 ,  0 ))
	    .done(); 
};

var off = function() {
	api.setLightState(1, state.off())
    .done();
    api.setLightState(2, state.off())
    .done();
    api.setLightState(3, state.off())
    .done();
};

var disco = function() {
	setInterval(function() {
		api.setLightState(1, state.rgb(Math.random() * 255 + 1,Math.random() * 255 + 1, Math.random() * 255 + 1))
	    .done();
	    api.setLightState(2, state.rgb(Math.random() * 255 + 1,Math.random() * 255 + 1, Math.random() * 255 + 1))
	    .done();
		api.setLightState(3, state.rgb(Math.random() * 255 + 1,Math.random() * 255 + 1, Math.random() * 255 + 1))
	    .done();    
	}, 2000);
};

var init  = function(){
	api.setLightState(1, state.rgb(0 ,0 , 0))
	    .done();
	api.setLightState(2, state.rgb( 0 , 0 , 0 ))
	    .done();
	api.setLightState(3, state.rgb( 0 , 0 ,  0 ))
	    .done(); 
};

var alert  = function(){
	api.setLightState(1, state.alert(true))
	    .done();
	//api.setLightState(2, state.alert())
	  //  .done();
	//api.setLightState(3, state.alert())
	  //  .done(); 
};

replServer.context.on 		= on;
replServer.context.off 		= off;
replServer.context.disco 	= disco;
replServer.context.init     = init;
replServer.context.alert    = alert;

Credits

Ashish Datta
1 project • 2 followers
makerbaker
Contact

Comments

Please log in or sign up to comment.