Created
August 6, 2014 18:43
-
-
Save shervinshaikh/5ff494c107938ffe2340 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 skynet = require('skynet'); | |
var Firebase = require('firebase'); | |
var myRootRef = new Firebase('https://zapier-shervin.firebaseio.com/glass'); | |
var conn = skynet.createConnection({ | |
"uuid": "adcf9640-f71a-11e3-a289-c9c410d2a47e", | |
"token": "0c4liaas7dum78pviw7ovh5pvc4k7qfr", | |
"protocol": "websocket" | |
}); | |
conn.on('ready', function(data){ | |
console.log('Ready'); | |
conn.status(function (data) { | |
// console.log(data); | |
}); | |
var first = true; | |
myRootRef.endAt().limit(1).on('child_added', function(snapshot) { | |
if(first){ | |
first = false; | |
return; | |
} | |
var dat = snapshot.val(); | |
var s = dat['item']['text']; | |
s = s.toLowerCase(); | |
console.log(s); | |
if(s.indexOf("on") > -1){ | |
console.log("turning lights on!"); | |
conn.message({ | |
"devices": "adcf9640-f71a-11e3-a289-c9c410d2a47e", | |
"payload": { | |
"typ": "hue", | |
"dat": { | |
"on": true | |
} | |
} | |
}); | |
} else if (s.indexOf("off") > -1){ | |
console.log("turning lights off!"); | |
conn.message({ | |
"devices": "adcf9640-f71a-11e3-a289-c9c410d2a47e", | |
"payload": { | |
"typ": "hue", | |
"dat": { | |
"on": false | |
} | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment