This commit is contained in:
Martin Donnelly 2016-11-13 21:21:11 +00:00
parent 02b91e2d61
commit da91c44814

View File

@ -24,14 +24,36 @@ var mqttClient = function() {
temp: 0,
last: 0
};
var mode = 'FanOff';
var d = new Date();
this.lastMsg = d.getTime();
this.fanTimer = function() {
'use strict';
var now = new Date;
var mod = 300000 - (now.getTime() % 300000);
var mod = 900000 - (now.getTime() % 900000);
// var
if (mode === 'FanOff') {
console.log('Fans off, temp should be <= 19.5');
mode = (parseFloat(this.livingRoom.temp) <= 19.5) ? 'FanOn' : 'FanOff';
} else {
console.log('Fans on, temp should not be less than 21.5');
mode = (parseFloat(this.livingRoom.temp) <= 21.5) ? 'FanOn' : 'FanOff';
}
var n = new Date();
n = n.getTime() - this.lastMsg;
console.log('Last msg',n);
if (n >= 600000) {
console.error('No message received for over 10 minutes');
mode = 'FanOff';
}
var mode = (this.livingRoom.temp > 22.0) ? 'FanOn' : 'FanOff';
var url = ['https://maker.ifttt.com/trigger/',mode,'/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
@ -74,7 +96,9 @@ var mqttClient = function() {
logger.debug(json);
logger.debug(json.temp);
this.livingRoom.temp = json.temp;
this.livingRoom.temp = parseFloat(json.temp);
var d = new Date();
this.lastMsg = d.getTime();
}.bind(this));