Skip to content

Instantly share code, notes, and snippets.

@radnip
Created September 17, 2015 06:55
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 radnip/2c1d31f1ee2d2aae63f9 to your computer and use it in GitHub Desktop.
Save radnip/2c1d31f1ee2d2aae63f9 to your computer and use it in GitHub Desktop.
var cylon = require('cylon');
cylon.api({ host: '0.0.0.0', port: '8080' });
cylon.robot({
connections: {
audio: { adaptor: 'audio' },
hue: { adaptor: 'hue', host: '10.43.1.188', username: '1234567890f' },
sfcon: {
adaptor: 'force',
sfuser: 'sf@username.net',
sfpass: 'SFPasswordAndSecurityToken',
orgCreds: {
clientId: 'XXX9CVKiXR7Ri5ph7vqYjcek68_WRdVBAAmr91oLd2Upqr4YxxstOq1h07s8hqVlaa3K280.Lna5VsTyNRT0',
clientSecret: '4545856990747985903',
redirectUri: 'http://localhost:3000/oauth/_callback'
}
}
},
devices: {
audio: { driver: 'audio' },
bulb: { driver: 'hue-light', lightId: 7, connection: 'hue'},
salesforce: { driver: 'force', connection: 'sfcon'}
},
work: function(my) {
cylon.Logger.info("Starting SF Receiver");
my.audio.on('playing', function(song){
console.log('Were playing!');
});
my.salesforce.subscribe('HueMsgOutbound', function(err, data) {
cylon.Logger.info("SF Msg Recieved: "+data);
var name = data.sobject.Name,
lamp_Id = data.sobject.Hue_Lamp_Id__c
cylon.Logger.info('Salesforce err:', err);
cylon.Logger.info("Hue Lamp: Action: #{ "+data.sobject.Hue_State__c+" }, RGB: #{ "+data.sobject.Hue_RGB_Red__c+" },#{ "+data.sobject.Hue_RGB_Green__c+" },#{ "+data.sobject.Hue_RGB_Blue__c+" }, ");
if (data.sobject.Hue_State__c == 'on'){
cylon.Logger.info("Turning On");
my.bulb.turnOn();
my.bulb.rgb( data.sobject.Hue_RGB_Red__c, data.sobject.Hue_RGB_Green__c, data.sobject.Hue_RGB_Blue__c);
my.audio.play('./temp/th.mp3');
}else if (data.sobject.Hue_State__c == 'alert'){
cylon.Logger.info("Alerting!");
my.bulb.alert();
my.audio.play('./temp/th.mp3');
}else if (data.sobject.Hue_State__c == 'off'){
cylon.Logger.info("Turning Off");
my.bulb.turnOff();
}else{
my.bulb.toggle();
my.audio.play('./temp/th.mp3');
}
});
}
});
cylon.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment