This commit is contained in:
Martin Donnelly 2016-11-15 07:56:41 +00:00
parent cd05021a30
commit 7dff251217

View File

@ -15,15 +15,20 @@ var busEmitter = new EventEmitter();
var db_name = 'mqtt'; var db_name = 'mqtt';
//var dbCouch = nano.use(db_name); //var dbCouch = nano.use(db_name);
var globalMode = 'FanOff';
busEmitter.on('send', function (mode) { busEmitter.on('send', function (mode) {
var url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join(''); var url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
if (globalMode !== mode)
{
globalMode = mode;
request(url, function (error, response, body) { request(url, function (error, response, body) {
if (!error && response.statusCode === 200) { if (!error && response.statusCode === 200) {
console.log(body); console.log(body);
} }
}); });
}
}); });
var mqttClient = function () { var mqttClient = function () {
@ -36,7 +41,7 @@ var mqttClient = function () {
temp: 0, temp: 0,
last: 0 last: 0
}; };
var mode = 'FanOff'; var mode = 'FanOff';
var d = new Date(); var d = new Date();
@ -49,7 +54,7 @@ var mqttClient = function () {
// var // var
if (mode === 'FanOff') { if (globalMode === 'FanOff') {
console.log('Fans off, temp should be <= 19.5'); console.log('Fans off, temp should be <= 19.5');
mode = (parseFloat(this.livingRoom.temp) <= 19.5) ? 'FanOn' : 'FanOff'; mode = (parseFloat(this.livingRoom.temp) <= 19.5) ? 'FanOn' : 'FanOff';
} else { } else {
@ -101,9 +106,11 @@ var mqttClient = function () {
logger.debug(json); logger.debug(json);
logger.debug(json.temp); logger.debug(json.temp);
logger.debug('GlobalMode',globalMode);
this.livingRoom.temp = parseFloat(json.temp); this.livingRoom.temp = parseFloat(json.temp);
if (this.livingRoom.temp >= 23) { console.log('lr:',this.livingRoom.temp, this.livingRoom.temp >= 22.6);
if (this.livingRoom.temp >= 22.6) {
console.log('Max temp reached, turn off' ); console.log('Max temp reached, turn off' );
busEmitter.emit('send', 'FanOff'); busEmitter.emit('send', 'FanOff');
} }