-
Notifications
You must be signed in to change notification settings - Fork 16
/
hotwater.js
executable file
·82 lines (78 loc) · 3.46 KB
/
hotwater.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
module.exports = function(RED) {
function nibeHotwater(config) {
RED.nodes.createNode(this,config);
const server = RED.nodes.getNode(config.server);
const startUp = () => {
const arr = [
//{topic:"bt6",source:"nibe"},
//{topic:"bt7",source:"nibe"},
];
let conf = server.nibe.getConfig();
if(conf.price===undefined) {
conf.price = {};
server.nibe.setConfig(conf);
}
server.initiatePlugin(arr,'hotwater').then(result => {
this.status({ fill: 'green', shape: 'dot', text: `` });
this.send({enabled:true});
},(reject => {
this.status({ fill: 'red', shape: 'dot', text: `` });
this.send({enabled:false});
}));
}
if(server.nibe.core!==undefined && server.nibe.core.connected!==undefined && server.nibe.core.connected===true) {
startUp();
} else {
server.nibeData.on('ready', (data) => {
startUp();
})
}
this.on('input', function(msg) {
let conf = server.nibe.getConfig();
if(msg.topic=="update") {
server.hotwaterPlugin();
return;
}
if(msg.payload!==undefined && msg.topic!==undefined && msg.topic!=="") {
let req = msg.topic.split('/');
if(conf[req[0]][req[1]+'_'+config.system]!==msg.payload) {
conf[req[0]][req[1]+'_'+config.system] = msg.payload;
server.nibe.setConfig(conf);
startUp();
}
}
});
server.nibeData.on(this.id, (data) => {
if(data.changed===true) {
if(server.nibe.core!==undefined && server.nibe.core.connected!==undefined && server.nibe.core.connected===true) {
startUp();
}
}
})
server.nibeData.on('pluginHotwaterAutoLuxury', (value) => {
if(value.bt7!==undefined && value.bt7.data>-3276) {
this.send({topic:"BT7 Topp",payload:value.bt7.data})
this.send({topic:"BT6 Laddning",payload:value.bt6.data})
if(value.hwTriggerTemp!==undefined) this.send({topic:"Startvärde",payload:value.hwTriggerTemp})
if(value.hwTargetValue!==undefined) {
this.send({topic:"Stoppvärde",payload:value.hwTargetValue});
} else {
this.send({topic:"Stoppvärde",payload:value.bt6.data});
}
}
})
server.nibeData.on('pluginHotwaterPriority', (value) => {
if(value.bt7!==undefined && value.bt7.data>-3276) {
this.send([null,{topic:"BT7 Topp",payload:value.bt7.data}])
this.send([null,{topic:"BT6 Laddning",payload:value.bt6.data}])
this.send([null,{topic:"Startvärde",payload:value.hwStartTemp.data}])
this.send([null,{topic:"Stoppvärde",payload:value.hwStopTemp.data}])
}
})
this.on('close', function() {
server.nibeData.removeAllListeners();
this.status({ fill: 'yellow', shape: 'dot', text: `` });
});
}
RED.nodes.registerType("nibe-hotwater",nibeHotwater);
}