Tidied heating control
Added bedroom light recipe
This commit is contained in:
parent
cdd55ccc18
commit
fbb7d8aaa9
@ -7,7 +7,7 @@ const Wemo = require('./wemo-controller');
|
||||
const HS100 = require('./hs100-controller');
|
||||
const Hive = require('./hive-controller');
|
||||
const MqttController = require('./mqtt-controller');
|
||||
const { BedroomRecipe } = require('./recipes');
|
||||
const { BedroomRecipe, BedroomLightMorning } = require('./recipes');
|
||||
|
||||
logger.level = 'debug';
|
||||
|
||||
@ -35,7 +35,7 @@ Aida.prototype.init = function() {
|
||||
this.lights = new Lights();
|
||||
this.wemo = new Wemo();
|
||||
this.hs100 = new HS100();
|
||||
// this.hive = new Hive();
|
||||
// this.hive = new Hive();
|
||||
this.mqtt = new MqttController();
|
||||
|
||||
this.lights.on('found', (d) => {
|
||||
@ -65,6 +65,7 @@ Aida.prototype.init = function() {
|
||||
// this.hive.update();
|
||||
|
||||
this.BedroomRecipe = new BedroomRecipe({ 'mqtt':this.mqtt, 'wemo':this.wemo });
|
||||
this.BedroomLightMorning = new BedroomLightMorning({ 'lights': this.lights });
|
||||
};
|
||||
|
||||
module.exports = Aida;
|
||||
|
@ -7,8 +7,10 @@ logger.level = 'debug';
|
||||
|
||||
const LightController = function() {
|
||||
const _this = this;
|
||||
const devices = [];
|
||||
client.on('light-new', light => {
|
||||
_this.emit('found', light);
|
||||
devices.push(light);
|
||||
logger.debug('New light found.');
|
||||
logger.debug(`ID: ${ light.id}`);
|
||||
logger.debug(`IP: ${ light.address }:${ light.port}`);
|
||||
@ -21,6 +23,7 @@ const LightController = function() {
|
||||
logger.debug('Power:', (info.power === 1) ? 'on' : 'off');
|
||||
logger.debug('Color:', info.color);
|
||||
logger.debug('info', info);
|
||||
// _this.emit(info.label.replace(' ',''), )
|
||||
});
|
||||
|
||||
light.getHardwareVersion((err, info) => {
|
||||
@ -41,11 +44,14 @@ const LightController = function() {
|
||||
});
|
||||
|
||||
client.on('light-offline', light => {
|
||||
logger.debug(`Light: ${light.id} has gone offline`);
|
||||
logger.debug(`Light: ${light.label} has gone offline`);
|
||||
_this.emit(light.label.replace(' ', ''), light.status);
|
||||
});
|
||||
|
||||
client.on('light-online', light => {
|
||||
logger.debug(`Light: ${light.id} has come online`);
|
||||
logger.debug(`Light: ${light.label} has come online`);
|
||||
logger.debug(light.label.replace(' ', ''), light.status);
|
||||
_this.emit(light.label.replace(' ', ''), { 'status':light.status, 'id':light.id });
|
||||
});
|
||||
|
||||
client.on('message', msg => {
|
||||
@ -69,6 +75,15 @@ const LightController = function() {
|
||||
logger.info(`Event Listener: ${ listener}`);
|
||||
});
|
||||
|
||||
this.on('setColour', (data) => {
|
||||
for(const light of devices) {
|
||||
if (light.id === data.id) {
|
||||
logger.info('Setting color of ', light.label);
|
||||
light.color(data.color.hue, data.color.saturation, data.color.brightness, data.color.kelvin);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ const BedroomRecipe = function(devices) {
|
||||
|
||||
this.fanTimer = function() {
|
||||
let n;
|
||||
|
||||
let mode = 'FanOff';
|
||||
const onTime = 900000;
|
||||
const now = new Date;
|
||||
const mod = onTime - (now.getTime() % onTime);
|
||||
@ -34,39 +34,32 @@ const BedroomRecipe = function(devices) {
|
||||
const curRange = (nowMS < 25200000) ? this.ranges.night : this.ranges.day;
|
||||
|
||||
if (this.globalMode === 'FanOff') {
|
||||
logger.info(`Fans off, temp should be <= ${curRange.low}`);
|
||||
logger.info(`Fans off, temp (${this.bedroom.temp}) should be <= ${curRange.low}`);
|
||||
mode = (parseFloat(this.bedroom.temp) <= curRange.low) ? 'FanOn' : 'FanOff';
|
||||
}
|
||||
else {
|
||||
logger.info(`Fans on, temp should not be less than ${curRange.high}`);
|
||||
logger.info(`Fans on, temp (${this.bedroom.temp}) should not be less than ${curRange.high}`);
|
||||
mode = (parseFloat(this.bedroom.temp) <= curRange.high) ? 'FanOn' : 'FanOff';
|
||||
}
|
||||
|
||||
if ((this.globalMode !== 'FanOff' || mode !== 'FanOff') && ((day >= 1 && day <= 5) && (nowMS >= daytimeLimits.low && nowMS <= daytimeLimits.high))) {
|
||||
logger.info('Week day');
|
||||
logger.info('Week day, during the day');
|
||||
mode = 'FanOff';
|
||||
}
|
||||
|
||||
n = now.getTime() - this.lastMsg;
|
||||
logger.info('Last msg', n);
|
||||
|
||||
if (n >= 600000) {
|
||||
/* if (n >= 600000) {
|
||||
logger.error('No message received for over 10 minutes');
|
||||
mode = 'FanOff';
|
||||
logger.warn('Setting quit for 15 seconds.');
|
||||
setTimeout(() => {
|
||||
throw new error('Ejecting for restart');
|
||||
}, 15000);
|
||||
}
|
||||
}*/
|
||||
|
||||
logger.info('LR temp:', this.bedroom.temp);
|
||||
// const data = { 'id': 'temperature', 'data': { 'mode': this.globalMode, 'temp': this.bedroom.temp } };
|
||||
|
||||
logger.debug('Mode', mode);
|
||||
if (this.bedroom.temp !== 0) {
|
||||
logger.debug('trying to turn fann off');
|
||||
if (this.bedroom.temp !== 0)
|
||||
_this.wemo.emit('wemo', mode);
|
||||
}
|
||||
|
||||
setTimeout(this.fanTimer.bind(this), mod + 500);
|
||||
};
|
||||
@ -77,7 +70,7 @@ const BedroomRecipe = function(devices) {
|
||||
const curRange = (nowMS < 25200000) ? this.ranges.night : this.ranges.day;
|
||||
|
||||
this.bedroom.temp = parseFloat(temp);
|
||||
logger.info(this.bedroom.temp, this.bedroom.temp >= curRange.max);
|
||||
// logger.info(this.bedroom.temp, this.bedroom.temp >= curRange.max);
|
||||
|
||||
if (this.bedroom.temp >= curRange.max) {
|
||||
logger.warn('Max temp reached, turn off');
|
||||
@ -92,7 +85,30 @@ const BedroomRecipe = function(devices) {
|
||||
setTimeout(this.fanTimer.bind(this), 10000);
|
||||
};
|
||||
|
||||
const BedroomLightMorning = function(devices) {
|
||||
const _this = this;
|
||||
this.lights = devices.lights;
|
||||
|
||||
this.lights.on('Bedroom', (d) => {
|
||||
const now = new Date;
|
||||
const nowMS = (now.getHours() * 3600000) + (now.getMinutes() * 60000);
|
||||
const dimLight = (nowMS < 28800000);
|
||||
|
||||
const device = {
|
||||
'id': d.id,
|
||||
'color' : { 'hue': 0, 'saturation': 0, 'brightness': 25, 'kelvin': 3200 }
|
||||
};
|
||||
|
||||
if (dimLight && d.status === 'on') {
|
||||
logger.info('Too bright, dim it..');
|
||||
_this.lights.emit('setColour', device);
|
||||
}
|
||||
});
|
||||
// Bedroom on
|
||||
};
|
||||
|
||||
util.inherits(BedroomRecipe, em);
|
||||
util.inherits(BedroomLightMorning, em);
|
||||
|
||||
module.exports = { BedroomRecipe };
|
||||
module.exports = { BedroomRecipe, BedroomLightMorning };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user