You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bigkevmcd edited this page Oct 16, 2012
·
1 revision
It's simple to use the cron module for Node.js to turn on and off lights...
It'd be nice to calculate sunrise/sunset and do this, either at midnight, set up cron jobs for the day ahead, or run every minute and determine whether or not the sun has set.
I suspect with a Dawn/Dusk detector, it'd be trivially possible to just handle the message appropriately.
var rfxcom = require('rfxcom'),
cronJob = require('cron').CronJob,
rfxtrx = new rfxcom.RfxCom('/dev/ttyUSB0', {debug: true}),
lightwave = new rfxcom.LightwaveRf(rfxtrx);
var GARAGE_LIGHT = "0xFAC271/1";
var turnLightsOn = function () {
lightwave.switchOn(GARAGE_LIGHT);
console.log("Light turned on");
};
var turnLightsOff = function () {
lightwave.switchOff(GARAGE_LIGHT);
console.log("Light turned on");
};
var job = new cronJob('00 00 07 * * *', turnLightsOff, null, true);
var job = new cronJob('00 00 19 * * *', turnLightsOn, null, true);
rfxtrx.initialise(function (error) {
if (error) {
throw new Error("Unable to initialise the rfx device");
};
});