-
Notifications
You must be signed in to change notification settings - Fork 16
/
fan.js
executable file
·106 lines (102 loc) · 4.64 KB
/
fan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module.exports = function(RED) {
function nibeFan(config) {
RED.nodes.createNode(this,config);
const server = RED.nodes.getNode(config.server);
const startUp = () => {
let system = config.system.replace('s','S');
this.status({ fill: 'yellow', shape: 'dot', text: `System ${system}` });
const arr = [
/*{topic:"bs1_flow",source:"nibe"},
{topic:"fan_speed",source:"nibe"},
{topic:"alarm",source:"nibe"},
{topic:"vented",source:"nibe"},
{topic:"cpr_set",source:"nibe"},
{topic:"cpr_act",source:"nibe"}*/
];
let conf = server.nibe.getConfig();
if(conf.fan===undefined) {
conf.fan = {};
server.nibe.setConfig(conf);
}
/*
if(conf.home.inside_sensors===undefined) {
conf.home.inside_sensors = [];
server.nibe.setConfig(conf);
}
if(conf.fan.sensor===undefined || conf.fan.sensor=="Ingen") {
} else {
let index = conf.home.inside_sensors.findIndex(i => i.name == conf.fan.sensor);
if(index!==-1) {
var co2Sensor = Object.assign({}, conf.home.inside_sensors[index]);
arr.push(co2Sensor);
}
}*/
server.initiatePlugin(arr,'fan',config.system).then(data => {
this.status({ fill: 'green', shape: 'dot', text: `System ${system}` });
this.send({enabled:true});
},(reject => {
this.status({ fill: 'red', shape: 'dot', text: `System ${system}` });
this.send({enabled:false});
}));
}
this.on('input', function(msg) {
let conf = server.nibe.getConfig();
if(msg.topic=="update") {
server.runFan();
return;
}
if(msg.payload!==undefined && msg.topic!==undefined && msg.topic!=="") {
let req = msg.topic.split('/');
if(conf[req[0]]===undefined) conf[req[0]] = {};
if(conf[req[0]][req[1]]!==msg.payload) {
conf[req[0]][req[1]] = msg.payload;
server.nibe.setConfig(conf);
}
startUp();
}
});
if(server.nibe.core!==undefined && server.nibe.core.connected!==undefined && server.nibe.core.connected===true) {
startUp();
} else {
server.nibeData.on('ready', (data) => {
startUp();
})
}
server.nibeData.on(this.id, (data) => {
if(data.changed===true) {
config.system = data.system;
if(server.nibe.core!==undefined && server.nibe.core.connected!==undefined && server.nibe.core.connected===true) {
startUp();
}
}
})
server.nibeData.on('pluginFan', (data) => {
let co2 = data.co2Sensor;
let low_co2_limit = data.low_co2_limit;
let high_co2_limit = data.high_co2_limit;
if(co2!==undefined && co2.data!==undefined && co2.data.data>0) {
//this.send({topic:"CO2",payload:co2.data.data});
}
if(low_co2_limit!==undefined) {
//this.send({topic:"CO2 Gränsvärde för sänkt flöde.",payload:low_co2_limit});
}
if(high_co2_limit!==undefined) {
//this.send({topic:"CO2 Gränsvärde för ökat flöde.",payload:high_co2_limit});
}
if(data.filter_eff!==undefined) {
this.send({topic:"Filtereffektivitet",payload:data.filter_eff});
}
this.send({topic:"Fläkthastighet",payload:data['fan_speed'].data});
this.send({topic:"Luftflöde",payload:data['bs1_flow'].data});
this.send({topic:"Luftflöde Börvärde",payload:data.setpoint});
this.send({topic:"Kompressorfrekvens",payload:data['cpr_act'].data});
this.send({topic:"Förångartemperatur",payload:data['evaporator'].raw_data});
})
this.on('close', function() {
let system = config.system.replace('s','S');
server.nibeData.removeAllListeners();
this.status({ fill: 'yellow', shape: 'dot', text: `System ${system}` });
});
}
RED.nodes.registerType("nibe-fan",nibeFan);
}