Last active
March 9, 2017 16:00
-
-
Save sangwonl/c8119955aa41b537787b8bac6ab59be1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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