Skip to content

Instantly share code, notes, and snippets.

@sangwonl
Last active March 9, 2017 16:00
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/c8119955aa41b537787b8bac6ab59be1 to your computer and use it in GitHub Desktop.
Save sangwonl/c8119955aa41b537787b8bac6ab59be1 to your computer and use it in GitHub Desktop.
var DashButton = require("node-dash-button");
var hue = require("node-hue-api");
var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require('./client_secret.json');
var dateFormat = require('dateformat');
var HueApi = hue.HueApi;
var lightState = hue.lightState;
var hostname = "172.30.1.52";
var username = "XD6RksCB1ms0tUSIVlgsD6XbyB9KLodto7o71L7X";
var api = new HueApi(hostname, username);
var state = lightState.create();
var doc = new GoogleSpreadsheet('16zZKNMrjXOqkoAsxjmD26HasJL5Eiso-bc2RO7osXsk');
var logToSheet = function(action) {
doc.useServiceAccountAuth(creds, function () {
doc.getInfo(function(err, info) {
var now = dateFormat(new Date(), 'yyyy-mm-dd hh:MM:ss');
var sheet = info.worksheets[0];
sheet.addRow({ seq: sheet.rowCount, time: now, action: action })
});
});
};
var dash = DashButton("88:71:e5:88:78:99", null, null, 'all');
dash.on("detected", function() {
var lightId = 3;
api.lightStatus(lightId)
.then(function(status) {
var newStatus = status.state.on ? state.off() : state.on();
api.setLightState(lightId, newStatus)
.then(function(result) {
logToSheet(newStatus._values.on ? 'ON' : 'OFF');
})
.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