Skip to content

Instantly share code, notes, and snippets.

@sangwonl
Created March 8, 2017 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sangwonl/946d13965f3ba135bb63d612d1c2d297 to your computer and use it in GitHub Desktop.
Save sangwonl/946d13965f3ba135bb63d612d1c2d297 to your computer and use it in GitHub Desktop.
var DashButton = require("node-dash-button");
var hue = require("node-hue-api");
var HueApi = hue.HueApi;
var lightState = hue.lightState;
var hostname = "172.31.2.12";
var username = "dWAksDC1ms0uTSIVlgsD3XbyP4KLodto7o31L7X";
var api = new HueApi(hostname, username);
var state = lightState.create();
var dash = DashButton("88:71:e3:88:28:69", null, null, 'all');
dash.on("detected", function (){
var bedroomId = 1;
api.lightStatus(bedroomId)
.then(function(status) {
var newStatus = status.state.on ? state.off() : state.on();
api.setLightState(bedroomId, newStatus)
.then(function(result) { console.log(result); })
.fail(function(error) { console.log(error); })
.done();
}).done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment