ranged temperatures

This commit is contained in:
Martin Donnelly 2017-01-15 00:03:24 +00:00
parent d8df0bd5db
commit 42bf60c1c7

View File

@ -28,6 +28,10 @@ const mqttClient = function(events) {
last: 0,
data: []
};
this.ranges = {
day: {low: 19.5, high: 22.5, max: 22.7},
night: {low: 17.5, high: 19.5, max: 19.7}
};
this.first = false;
this.maxLength = 540;
@ -92,13 +96,14 @@ const mqttClient = function(events) {
const day = now.getDay();
const daytimeLimits = {low: 27900000, high: 63000000};
const nowMS = (now.getHours() * 3600000) + (now.getMinutes() * 60000);
const curRange = (nowMS < 25200000) ? this.ranges.night : this.ranges.day;
if (globalMode === 'FanOff') {
logger.info('Fans off, temp should be <= 19.5');
mode = (parseFloat(this.livingRoom.temp) <= 19.5) ? 'FanOn' : 'FanOff';
logger.info(`Fans off, temp should be <= ${curRange.low}`);
mode = (parseFloat(this.livingRoom.temp) <= curRange.low) ? 'FanOn' : 'FanOff';
} else {
logger.info('Fans on, temp should not be less than 22.5');
mode = (parseFloat(this.livingRoom.temp) <= 22.5) ? 'FanOn' : 'FanOff';
logger.info(`Fans on, temp should not be less than ${curRange.high}`);
mode = (parseFloat(this.livingRoom.temp) <= curRange.high) ? 'FanOn' : 'FanOff';
}
if ((globalMode !== 'FanOff' || mode !== 'FanOff') && ((day >= 1 && day <= 5) && (nowMS >= daytimeLimits.low && nowMS <= daytimeLimits.high))) {
@ -122,14 +127,13 @@ const mqttClient = function(events) {
logger.info('LR temp:', this.livingRoom.temp);
const data = {id: 'temperature', data: {mode: globalMode, temp: this.livingRoom.temp}};
if (this.livingRoom.temp !== 0)
{
if (this.livingRoom.temp !== 0) {
events.emit('sendIFTTT', mode);
events.emit('sendSocket', data);
events.emit('sendSocket', data);
}
setTimeout(this.fanTimer.bind(this), mod + 10);
setTimeout(this.fanTimer.bind(this), mod + 500);
};
this.lighting = 'lights';
@ -156,15 +160,17 @@ const mqttClient = function(events) {
this.client.subscribe('livingroomTemp');
this.client.on('message', function(topic, message) {
const now = new Date;
const nowMS = (now.getHours() * 3600000) + (now.getMinutes() * 60000);
const curRange = (nowMS < 25200000) ? this.ranges.night : this.ranges.day;
const json = JSON.parse(message.toString());
logger.debug(json);
logger.debug(json.temp);
this.livingRoom.temp = parseFloat(json.temp);
logger.info('lr:', this.livingRoom.temp, this.livingRoom.temp >= 22.6);
logger.info('lr:', this.livingRoom.temp, this.livingRoom.temp >= curRange.max);
if (this.livingRoom.temp >= 22.7) {
if (this.livingRoom.temp >= curRange.max) {
logger.warn('Max temp reached, turn off');
events.emit('sendIFTTT', 'FanOff');
}