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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
| var topic = msg.topic;
var state = global.get(topic+'_state',"file")||0; // Get state of the agenda item.
var F_RTC_on_off_active = global.get('F_RTC.on_off_active',"file");
if (msg.force == 1 && msg.payload == 1) {
var HP_state = global.get('TOP0_Heatpump_State',"file"); // get the current state of the heatpump. Is it on or off.
if (HP_state == 0) {
if (F_RTC_on_off_active == 1) { global.set('F_RTC.on_off_active',0,"file"); }
let msg1={}; msg1 = { payload: 1, topic: "override" }; node.send([msg1,null])
}
let msg2={}; msg2 = { payload: 1, topic: "DHW" };
node.send([null,msg2])
}
if (msg.force == 1 && msg.payload == 0) {
let msg2={}; msg2 = { payload: 0, topic: "DHW" };
node.send([null,msg2])
}
if (state == 0) // Is it disabled?
{return null} // output null to all pins and exit. else to continue.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
else { // if not, continue...
var day_check =global.get(topic+'_day',"file"); // get schedule variables.
var hour_check =global.get(topic+'_hour',"file"); // get schedule variables.
var minutes_check =global.get(topic+'_minutes',"file"); // get schedule variables.
var solar_block_scheduler =global.get('solar_block_scheduler',"file");
var F_SOLAR =global.get('F_SOLAR',"file");
var F_stored_next_operating_mode = global.get('F_stored_next_operating_mode',"file");
var block_it = false;
if (solar_block_scheduler == true && F_SOLAR.function_active_state == 1)
{
block_it = true;
}
// Check the programmed day compared current day.
if (day_check.includes(msg.payload[0])) {day_check = { payload: 1, topic: "DayOfTheWeek"};}
else {day_check = { payload: 0, topic: "DayOfTheWeek"};}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Check the programmed hour compared current hour.
if (msg.payload[1] == hour_check) {hour_check = { payload: 1, topic: "Hour"};}
else {hour_check = { payload: 0, topic: "Hour"};}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Check the programmed minutes compared current minutes.
if (msg.payload[2] == minutes_check) {minutes_check = { payload: 1, topic: "Minutes"};}
else {minutes_check = { payload: 0, topic: "Minutes"};}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
if (day_check.payload == 1 && hour_check.payload == 1 && minutes_check.payload == 1) // If all of the conditions are met (day + hour + minutes), then....
{
var CurrentTime = new Date().getTime();
let msg1 = {}, msg2 = {}, msg3 = {}, msg4 = {}, msg5 = {}, msg6 = {}, msg7 = {}, msg8={};
msg1.payload = 99; msg2.payload = 99; msg3.payload = 99; msg4.payload = 99; msg5.payload = 99; msg6.payload = 99; msg7.payload = 99;
//
//
//
////////////////////////////////////////////////////////////////
// Override the current powerstate of heat pump? //////////////
//
var override = global.get(topic+'_override',"file"); // get the current override state.
var NightReductionRoomSetpoint_state = global.get('NightReductionRoomSetpoint.state',"file");
////////////////////////////////////////////////////////////////
var CurrentDHW = global.get('TOP10_DHW_Temp');
// ########## CONDITIONS #######################################
var condition = global.get(msg.topic+'_condition',"file");
if (condition !== undefined){
for (const value of condition)
{
var Schedule_conditions_condition_xx = global.get('Schedule_conditions.'+value,"file");
if (Schedule_conditions_condition_xx === undefined) {Schedule_conditions_condition_xx = {} }
if (Schedule_conditions_condition_xx.value === undefined || Schedule_conditions_condition_xx.value === null) { Schedule_conditions_condition_xx.value = 100000;}
if (condition !== undefined) { var msg99={}; msg99.topic = 'Scheduler condition';}
// DHW_temperature
if (Schedule_conditions_condition_xx.type == 'DHW_temperature') {
if (Schedule_conditions_condition_xx.value !== undefined && CurrentDHW > Schedule_conditions_condition_xx.value) { msg99.payload = 'DHW temperature: ' + CurrentDHW + '. Condition: ' + Schedule_conditions_condition_xx.value + '°C. Scheduled action blocked' ; node.send([null,null,null,null,null,null,null,null,msg99]) ; return null }
//msg99.payload = 'Pass';
node.send([null,null,null,null,null,null,null,null,msg99])
}
// ELAPSED_TIME (time since last sterelization is less than)
if (Schedule_conditions_condition_xx.type == 'ELAPSED_TIME') {
let last_run = global.get('Schedule_conditions.DHW_last_at_60C',"file");
let CurrentTime = new Date().getTime();
if ( Schedule_conditions_condition_xx.value !== undefined && (CurrentTime - last_run) < Schedule_conditions_condition_xx.value*60*60*1000 && last_run !== undefined) { msg99.payload = 'Time since last above 60°C: ' + ((CurrentTime - last_run) / 3600000).toFixed(2) + ' hours. Condition: ' + Schedule_conditions_condition_xx.value + ' hours. Scheduled action blocked' ; node.send([null,null,null,null,null,null,null,null,msg99]) ; return null }
//msg99.payload = 'Pass';
node.send([null,null,null,null,null,null,null,null,msg99])
}
// ELAPSED_TIME2 (time since DHW temp was on target temperature is less than)
if (Schedule_conditions_condition_xx.type == 'ELAPSED_TIME2') {
let last_run = global.get('Schedule_conditions.DHW_last_at_target_temperature',"file");
let CurrentTime = new Date().getTime();
if ( Schedule_conditions_condition_xx.value !== undefined && (CurrentTime - last_run) < Schedule_conditions_condition_xx.value*60*60*1000 && last_run !== undefined) { msg99.payload = 'Time since last at DHW target: ' + ((CurrentTime - last_run) / 3600000).toFixed(2) + ' hours. Condition: ' + Schedule_conditions_condition_xx.value + ' hours. Scheduled action blocked' ; node.send([null,null,null,null,null,null,null,null,msg99]) ; return null }
//msg99.payload = 'Pass';
node.send([null,null,null,null,null,null,null,null,msg99])
}
// ELAPSED_TIME3 (time since previous trigger of this scheduled action is less than)
if (Schedule_conditions_condition_xx.type == 'ELAPSED_TIME3') {
let last_run = global.get(msg.topic+'_last_run',"file");
let CurrentTime = new Date().getTime();
if ( Schedule_conditions_condition_xx.value !== undefined && (CurrentTime - last_run) < Schedule_conditions_condition_xx.value*60*60*1000 && last_run !== undefined) { msg99.payload = 'Time since last run: ' + ((CurrentTime - last_run) / 3600000).toFixed(2) + ' hours. Condition: ' + Schedule_conditions_condition_xx.value + ' hours. Scheduled action blocked' ; node.send([null,null,null,null,null,null,null,null,msg99]) ; return null }
//msg99.payload = 'Pass';
node.send([null,null,null,null,null,null,null,null,msg99])
}
}
}
// #############################################################
if ((override == 1 && HP_state == 0) || msg.force == 1) // check if the override state is enabled, AND currently heatpump state is off
{
msg1 = { payload: 1, topic: "override" };
}
////////////////////////////////////////////////////////////////
//
//
//
var CurrentHEAT = global.get('TOP5_Main_Inlet_Temp');
//
//
var action = global.get(topic+'_action',"file"); // get the action
////////////////////////////////////////////////////////////////
if (action == "HP_turn_on" && HP_state == 0) // check the action
{
msg1 = { source: "flow", payload: 1, topic: "Turn ON HeatPump" }; // Operation Mode action? >> to Operation MOde output pin 1
}
if (action == "HP_turn_off" && HP_state == 1 && block_it === false) // check the action
{
msg1 = { source: "flow", payload: 0, topic: "Turn OFF HeatPump" }; // Operation Mode action? >> to Operation MOde output pin 1
}
////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////
if (action == "DHW") // check the action if DHW (=Force DHW)
{
msg2 = { payload: 1, topic: "DHW" }; // DHW action? >> to DHW output pin 2
}
////////////////////////////////////////////////////////////////
//
//
//
//
////////////////////////////////////////////////////////////////
if (action == "Sterilization" && block_it === false) // check the action
{
msg3 = { payload: 1, topic: "Sterilization" }; // Sterilization action? >> to Sterilization output pin 3
}
////////////////////////////////////////////////////////////////
//
//
//
//
//
////////////////////////////////////////////////////////////////
if (action == "QM_0") // check the action
{
msg4 = { payload: 0, topic: "Set QuietMode to" }; // QuietMode action? >> to Quiet MOde output pin 4
msg4.source = "scheduler"
}
if (action == "QM_1") // check the action
{
msg4 = { payload: 1, topic: "Set QuietMode to" }; // QuietMode action? >> to Quiet MOde output pin 4
msg4.source = "scheduler"
}
if (action == "QM_2") // check the action
{
msg4 = { payload: 2, topic: "Set QuietMode to" }; // QuietMode action? >> to Quiet MOde output pin 4
msg4.source = "scheduler"
}
if (action == "QM_3") // check the action
{
msg4 = { payload: 3, topic: "Set QuietMode to" }; // QuietMode action? >> to Quiet MOde output pin 4
msg4.source = "scheduler"
}
////////////////////////////////////////////////////////////////
//
//
// Scheduler - Operation Mode
//
////////////////////////////////////////////////////////////////
// Operating mode (0=Heat only, 1=Cool only, 2=Auto(Heat), 3=DHW only, 4=Heat+DHW, 5=Cool+DHW, 6=Auto(Heat)+DHW, 7=Auto(Cool), 8=Auto(Cool)+DHW)
// Operating mode (0=Heat only, 2=Auto(Heat), 4=Heat+DHW, 5=Cool+DHW, 6=Auto(Heat)+DHW, 7=Auto(Cool), 8=Auto(Cool)+DHW)
if (action == "OperationMode0") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 0, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',0,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 0, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
if (global.get('Force_DHW_active',"file") == 1) {global.set('Force_DHW_active',0,"file");}
}
if (action == "OperationMode1") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 1, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',1,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 1, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
if (global.get('Force_DHW_active',"file") == 1) {global.set('Force_DHW_active',0,"file");}
}
if (action == "OperationMode2") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 2, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',2,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 2, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };
global.set('F_RTC.on_off_active',0,"file");
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
if (global.get('Force_DHW_active',"file") == 1) {global.set('Force_DHW_active',0,"file");}
}
if (action == "OperationMode3") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 3, topic: "Scheduler - Set Operation Mode (DHW temp: " + CurrentDHW + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',3,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 3, topic: "Scheduler - Set Operation Mode (DHW temp: " + CurrentDHW + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
}
if (action == "OperationMode4") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 4, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',4,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 4, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
}
if (action == "OperationMode5") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 5, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',5,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 5, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
}
if (action == "OperationMode6") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 6, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',6,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 6, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
}
if (action == "OperationMode7") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 7, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',7,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 7, topic: "Scheduler - Set Operation Mode (Tinlet: " + CurrentHEAT + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
if (global.get('Force_DHW_active',"file") == 1) {global.set('Force_DHW_active',0,"file");}
}
if (action == "OperationMode8") // check the action
{
if (F_stored_next_operating_mode === undefined) {msg5 = { payload: 8, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)" };} // Operation Mode action? >> to Operation MOde output pin 5
if (F_SOLAR.function_active_state == 1) {global.set('F_stored_next_operating_mode',8,"file");}
if (F_RTC_on_off_active == 1) {
global.set('F_stored_next_operating_mode',undefined,"file");
msg5 = { payload: 8, topic: "Scheduler - Set Operation Mode (Tinlet/DHW temp: " + CurrentHEAT + "/" + CurrentDHW + "°C)"};
if (override == 1) {global.set('F_RTC.on_off_active',0,"file");}
}
}
////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////
if (action == "NightReductionWaterTempOn") // check the action
{
var correction = global.get("NightReductionWaterTemp.correction","file"); // get the nightreduction correction.
global.set("NightReductionWaterTemp.current_value",correction,"file");
global.set("NightReductionWaterTemp.state",1,"file");
msg6 = { payload: correction, topic: "Nightreduction" };
}
if (action == "NightReductionWaterTempOff") // check the action
{
global.set("NightReductionWaterTemp.current_value",0,"file");
global.set("NightReductionWaterTemp.state",0,"file");
msg6 = { payload: 0, topic: "Nightreduction" };
}
////////////////////////////////////////////////////////////////
if (action == "NightReductionRoomSetpointOn") // check the action
{
if (NightReductionRoomSetpoint_state === undefined || NightReductionRoomSetpoint_state == 0) //only when not set
{
global.set("NightReductionRoomSetpoint.state", 1, "file");
msg7 = { payload: 1, topic: "NightReductionRoomSetpoint.state" };
}
}
if (action == "NightReductionRoomSetpointOff") // check the action
{
if (NightReductionRoomSetpoint_state === undefined) { NightReductionRoomSetpoint_state = 0; }
if (NightReductionRoomSetpoint_state == 1) //only change when set
{
global.set("NightReductionRoomSetpoint.state",0,"file");
msg7 = { payload: 0, topic: "NightReductionRoomSetpoint.state" };
}
}
////////////////////////////////////////////////////////////////
//
//
//
//
if (action == "Water setpoint (heat shift)") // check the action
{
msg8.payload = global.get(msg.topic+'_setpoint',"file")
msg8.topic = action;
node.send([null,null,null,null,null,null,null,msg8]);
}
if (action == "Water setpoint (direct)") // check the action
{
msg8.payload = global.get(msg.topic+'_setpoint',"file")
msg8.topic = action;
node.send([null,null,null,null,null,null,null,msg8]);
}
if (action == "Room setpoint RTC") // check the action
{
msg8.payload = global.get(msg.topic+'_setpoint',"file")
msg8.topic = action;
node.send([null,null,null,null,null,null,null,msg8]);
}
if (action == "DHW setpoint") // check the action
{
msg8.payload = global.get(msg.topic+'_setpoint',"file")
msg8.topic = action;
node.send([null,null,null,null,null,null,null,msg8]);
}
global.set(topic+'_last_run',CurrentTime,"file");
return [msg1, msg2, msg3, msg4, msg5, msg6, msg7];
}
else
{
return [null, null, null, null, null, null, null];
}
} |