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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
| var DHW_automation_state = global.get('DHW_automation_state',"file");
var DHW_threshold_upper = global.get('DHW_threshold_upper',"file");
var TOP9_DHW_Target_Temp = global.get('TOP9_DHW_Target_Temp',"file");
if (msg.payload >= 60 ) { // legionella temperature. Above 60 I assume legionella in the tank will be killed. If this T is reached, this moment in time will be logged.
let CurrentTime = new Date().getTime();
global.set('Schedule_conditions.DHW_last_at_60C',CurrentTime,"file")
}
if (msg.payload >= TOP9_DHW_Target_Temp ) {
let CurrentTime = new Date().getTime();
global.set('Schedule_conditions.DHW_last_at_target_temperature',CurrentTime,"file")
}
///////////////////
var Sterilization_active = global.get('Sterilization_active', "file");
var Force_DHW_active = global.get('Force_DHW_active', "file");
if (DHW_automation_state === 0 || DHW_automation_state === undefined) {return null;}
if (DHW_threshold_upper === undefined) { return null; }
//if (msg.payload > DHW_threshold_upper) { return null; }
if (global.get('TOP20_ThreeWay_Valve_State') == 1) { return null; }
if (Sterilization_active === 1 || Force_DHW_active === 1) { return null; }
var compressor_frequency = global.get('compressor_frequency', "file");
var msg99 = {}; msg99.topic = 'Auto-start-DHW function';
var DHW_automation_active = global.get('DHW_automation_active', "file")
if (DHW_automation_active === undefined) { DHW_automation_active = 0; }
////////////////////////////////////////////////////////////////////
if (msg.topic === 'External') {
msg99.topic = 'External';
var HP_state = global.get('TOP0_Heatpump_State', "file"); if (HP_state === undefined) { return null; }
// if heatpump is off, turn it on.
if (HP_state === 0) {
let msg2 = {}; msg2.payload = 1; msg2.source = 'DHW-function'; // turn on pump
global.set('F_RTC.automation_active', 0, "file"); // set RTC turn on/off function to inactive.
msg99.payload = 'Heatpump is off. Turning on for Auto-start-DHW function';
node.send([null, msg99, msg2])
}
// store current operating mode
if (global.get('F_stored_next_operating_mode', "file") === undefined) { global.set('F_stored_next_operating_mode', (global.get('TOP4_Operating_Mode_State', "file")), "file"); }
// send new operating
let msg1 = {}; msg1.payload = 3; msg1.delay = 0; // DHW Only
msg99.payload = 'Start DHW-run';
msg99.delay = 0;
global.set('DHW_automation_active', 1, "file");
return [msg1, msg99, null];
}
////////////////////////////////////////////////////////////////////
//case auto-start DHW temperature triggered, but not yet active
if (DHW_automation_active === 0 && msg.payload <= global.get('DHW_threshold_lower', "file")) {
if (compressor_frequency >= 1 && global.get('TOP20_ThreeWay_Valve_State') == 1) { return null; } // if DHW is already active and compressor is running: exit.
var HP_state = global.get('TOP0_Heatpump_State', "file"); if (HP_state === undefined) { return null; }
// if heatpump is off, turn it on.
if (HP_state === 0) {
var msg2 = {}; msg2.payload = 1; msg2.source = 'DHW-function'; // turn on pump
global.set('F_RTC.automation_active', 0, "file"); // set RTC turn on/off function to inactive.
msg99.payload = 'Heatpump is off. Turning on for Auto-start-DHW function';
node.send([null, msg99, msg2])
}
// store current operating mode
if (global.get('F_stored_next_operating_mode', "file") === undefined) {
global.set('F_stored_next_operating_mode', global.get('TOP4_Operating_Mode_State', "file"), "file");
}
// send new operation mode
var msg1 = {}; msg1.payload = 3; msg1.delay = 5; // DHW Only
msg99.payload = 'DHW temperature: ' + msg.payload + '°C. Lower threshold: ' + global.get('DHW_threshold_lower', "file") + '°C. Starting DHW run.';
msg99.delay = 0;
global.set('DHW_automation_active', 1, "file");
return [msg1, msg99, null];
}
///////////////////////////////////////////////////////////
//case auto-start DHW temperature triggered and active, potentially DHW setpoint reached and revert to original Operating Mode
if (DHW_automation_active === 1) {
if (msg.payload >= TOP9_DHW_Target_Temp && compressor_frequency === 0) {
var delay = 1 * 60 * 1000; // 15 minutes delay
if (global.get('F_stored_next_operating_mode', "file") !== undefined) {
let msg1 = {};
msg1.delay = delay;
msg1.payload = global.get('F_stored_next_operating_mode', "file");
msg99.payload = 'Operating mode reverted to ' + global.get('F_stored_next_operating_mode', "file");
msg99.delay = delay;
global.set('F_stored_next_operating_mode', undefined, "file");
node.send([msg1, msg99, null]);
}
msg99.payload = 'DHW temperature: ' + msg.payload + '°C reached. End Auto-start-DHW. Reverting operating mode in ' + delay / 1000 / 60 + ' minute.';
msg99.delay = 0;
global.set('DHW_automation_active', 0, "file");
return [null, msg99, null];
}
}
////////////////////////////////////////////////////////////////////
//case auto-start DHW temperature triggered, activation failed due to Heishamon offline
if (DHW_automation_active === 1 && msg.payload <= global.get('DHW_threshold_lower', "file")) {
if (compressor_frequency >= 1 && global.get('TOP20_ThreeWay_Valve_State') == 1) { return null; } // if DHW is already active and compressor is running: exit.
var HP_state = global.get('TOP0_Heatpump_State', "file"); if (HP_state === undefined) { return null; }
// if heatpump is off, turn it on.
if (HP_state === 0) {
let msg2 = {}; msg2.payload = 1; msg2.source = 'DHW-function'; // turn on pump
global.set('F_RTC.automation_active', 0, "file"); // set RTC turn on/off function to inactive.
msg99.payload = 'Heatpump is off. Turning on for Auto-start-DHW function';
node.send([null, msg99, msg2])
}
// store current operating mode
if (global.get('F_stored_next_operating_mode', "file") === undefined) {
global.set('F_stored_next_operating_mode', global.get('TOP4_Operating_Mode_State', "file"), "file");
}
// send new operation mode
let msg1 = {}; msg1.payload = 3; msg1.delay = 5; // DHW Only
msg99.payload = 'DHW temperature: ' + msg.payload + '°C. Lower threshold: ' + global.get('DHW_threshold_lower', "file") + '°C. Starting DHW run. Previous attempt failed, Heishamon offline?';
msg99.delay = 0;
global.set('DHW_automation_active', 1, "file");
return [msg1, msg99, null];
} |