smart-nodes 0.3.22 → 0.3.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/delay/delay.js CHANGED
@@ -1,36 +1,38 @@
1
1
  module.exports = function (RED)
2
2
  {
3
+ "use strict";
4
+
3
5
  function DelayNode(config)
4
6
  {
5
7
  const node = this;
6
8
  RED.nodes.createNode(node, config);
7
9
 
8
- const smartContext = require("../persistence.js")(RED);
10
+ const smart_context = require("../persistence.js")(RED);
9
11
  const helper = require("../smart_helper.js");
10
12
 
11
- var nodeSettings = {
13
+ var node_settings = {
12
14
  on_delay_ms: helper.getTimeInMs(config.on_delay, config.on_delay_unit),
13
15
  off_delay_ms: helper.getTimeInMs(config.off_delay, config.off_delay_unit),
14
- lastMessage: null,
16
+ last_message: null,
15
17
  };
16
18
 
17
19
  if (config.save_state)
18
20
  {
19
21
  // load old saved values
20
- nodeSettings = Object.assign(nodeSettings, smartContext.get(node.id));
22
+ node_settings = Object.assign(node_settings, smart_context.get(node.id));
21
23
 
22
- switch (nodeSettings.lastMessage?.payload)
24
+ switch (node_settings.last_message?.payload)
23
25
  {
24
26
  case true:
25
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "Load last state: On" });
27
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "Load last state: On" });
26
28
  break;
27
29
 
28
30
  case false:
29
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "Load last state: Off" });
31
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "Load last state: Off" });
30
32
  break;
31
33
 
32
34
  default:
33
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "No last state available" });
35
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "No last state available" });
34
36
  break;
35
37
  }
36
38
  }
@@ -38,7 +40,7 @@ module.exports = function (RED)
38
40
  {
39
41
  // delete old saved values
40
42
  node.status({});
41
- smartContext.del(node.id);
43
+ smart_context.del(node.id);
42
44
  }
43
45
 
44
46
  // dynamic config
@@ -53,28 +55,28 @@ module.exports = function (RED)
53
55
  switch (msg.topic)
54
56
  {
55
57
  case "set_delay_on":
56
- nodeSettings.on_delay_ms = helper.getTimeInMsFromString(msg.payload);
57
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "New on delay: " + helper.formatMsToStatus(nodeSettings.on_delay_ms) });
58
+ node_settings.on_delay_ms = helper.getTimeInMsFromString(msg.payload);
59
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "New on delay: " + helper.formatMsToStatus(node_settings.on_delay_ms) });
58
60
 
59
61
  if (config.save_state)
60
- smartContext.set(node.id, nodeSettings);
62
+ smart_context.set(node.id, node_settings);
61
63
  break;
62
64
 
63
65
  case "set_delay_off":
64
- nodeSettings.off_delay_ms = helper.getTimeInMsFromString(msg.payload);
65
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "New off delay: " + helper.formatMsToStatus(nodeSettings.on_delay_ms) });
66
+ node_settings.off_delay_ms = helper.getTimeInMsFromString(msg.payload);
67
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "New off delay: " + helper.formatMsToStatus(node_settings.on_delay_ms) });
66
68
 
67
69
  if (config.save_state)
68
- smartContext.set(node.id, nodeSettings);
70
+ smart_context.set(node.id, node_settings);
69
71
  break;
70
72
 
71
73
  case "set_delays":
72
- nodeSettings.on_delay_ms = helper.getTimeInMsFromString(msg.payload);
73
- nodeSettings.off_delay_ms = nodeSettings.on_delay_ms;
74
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "New delays: " + helper.formatMsToStatus(nodeSettings.on_delay_ms) });
74
+ node_settings.on_delay_ms = helper.getTimeInMsFromString(msg.payload);
75
+ node_settings.off_delay_ms = node_settings.on_delay_ms;
76
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "New delays: " + helper.formatMsToStatus(node_settings.on_delay_ms) });
75
77
 
76
78
  if (config.save_state)
77
- smartContext.set(node.id, nodeSettings);
79
+ smart_context.set(node.id, node_settings);
78
80
  break;
79
81
 
80
82
  default:
@@ -94,12 +96,12 @@ module.exports = function (RED)
94
96
 
95
97
  let send = (msg) =>
96
98
  {
97
- let delayMs = 0;
99
+ let delay_ms = 0;
98
100
 
99
101
  if (msg.payload)
100
- delayMs = nodeSettings.on_delay_ms;
102
+ delay_ms = node_settings.on_delay_ms;
101
103
  else
102
- delayMs = nodeSettings.off_delay_ms;
104
+ delay_ms = node_settings.off_delay_ms;
103
105
 
104
106
  if (delay_only_on_change)
105
107
  {
@@ -110,9 +112,9 @@ module.exports = function (RED)
110
112
  return;
111
113
 
112
114
  // payload changed back to last value => stop current delay
113
- if (nodeSettings.lastMessage?.payload == msg.payload)
115
+ if (node_settings.last_message?.payload == msg.payload)
114
116
  {
115
- node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Stopped delayed message" });
117
+ node.status({ fill: "yellow", shape: "dot", text: helper.getCurrentTimeForStatus() + ": " + "Stopped delayed message" });
116
118
  clearTimeout(timeout);
117
119
  timeout = null;
118
120
 
@@ -120,7 +122,7 @@ module.exports = function (RED)
120
122
  }
121
123
  }
122
124
  // payload hasn't changed
123
- else if (nodeSettings.lastMessage?.payload == msg.payload)
125
+ else if (node_settings.last_message?.payload == msg.payload)
124
126
  {
125
127
  return;
126
128
  }
@@ -135,39 +137,39 @@ module.exports = function (RED)
135
137
  }
136
138
 
137
139
  // No delay if 0 or smaller
138
- if (delayMs <= 0)
140
+ if (delay_ms <= 0)
139
141
  {
140
- node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + +msg.topic + "' msg.payload = '" + msg.payload + "'" });
141
- nodeSettings.lastMessage = msg
142
+ node.status({ fill: "yellow", shape: "dot", text: helper.getCurrentTimeForStatus() + ": " + "Sended msg.topic = '" + +msg.topic + "' msg.payload = '" + msg.payload + "'" });
143
+ node_settings.last_message = msg
142
144
 
143
145
  if (config.save_state)
144
- smartContext.set(node.id, nodeSettings);
146
+ smart_context.set(node.id, node_settings);
145
147
 
146
148
  node.send(msg);
147
149
  return;
148
150
  }
149
151
 
150
152
  // start new timeout
151
- node.status({ fill: "yellow", shape: "ring", text: (new Date()).toLocaleString() + ": " + "Forward msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "' in " + helper.formatMsToStatus(delayMs, "at") });
153
+ node.status({ fill: "yellow", shape: "ring", text: helper.getCurrentTimeForStatus() + ": " + "Forward msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "' in " + helper.formatMsToStatus(delay_ms, "at") });
152
154
  timeout = setTimeout(() =>
153
155
  {
154
156
  timeout = null;
155
- node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "'" });
156
- nodeSettings.lastMessage = msg
157
+ node.status({ fill: "yellow", shape: "dot", text: helper.getCurrentTimeForStatus() + ": " + "Sended msg.topic = '" + msg.topic + "' msg.payload = '" + msg.payload + "'" });
158
+ node_settings.last_message = msg
157
159
 
158
160
  if (config.save_state)
159
- smartContext.set(node.id, nodeSettings);
161
+ smart_context.set(node.id, node_settings);
160
162
 
161
163
  node.send(msg);
162
- }, delayMs);
164
+ }, delay_ms);
163
165
  }
164
166
 
165
- if (config.save_state && config.resend_on_start && nodeSettings.lastMessage != null)
167
+ if (config.save_state && config.resend_on_start && node_settings.last_message != null)
166
168
  {
167
169
  setTimeout(() =>
168
170
  {
169
- node.status({ fill: "yellow", shape: "dot", text: (new Date()).toLocaleString() + ": " + "Sended msg.topic = '" + nodeSettings.lastMessage.topic + "' msg.payload = '" + nodeSettings.lastMessage.payload + "'" });
170
- node.send(nodeSettings.lastMessage);
171
+ node.status({ fill: "yellow", shape: "dot", text: helper.getCurrentTimeForStatus() + ": " + "Sended msg.topic = '" + node_settings.last_message.topic + "' msg.payload = '" + node_settings.last_message.payload + "'" });
172
+ node.send(node_settings.last_message);
171
173
  }, 10000);
172
174
  }
173
175
  }
@@ -0,0 +1,480 @@
1
+ [
2
+ {
3
+ "id": "e83d01afd93457a2",
4
+ "type": "tab",
5
+ "label": "Heating Curve",
6
+ "disabled": false,
7
+ "info": "",
8
+ "env": []
9
+ },
10
+ {
11
+ "id": "4240b41f17726057",
12
+ "type": "smart_heating-curve",
13
+ "z": "e83d01afd93457a2",
14
+ "name": "",
15
+ "room_setpoint": 20,
16
+ "slope": "1.5",
17
+ "offset": 0,
18
+ "flow_max": 75,
19
+ "flow_min": 20,
20
+ "x": 540,
21
+ "y": 320,
22
+ "wires": [
23
+ [
24
+ "1d3503b689f7c936"
25
+ ]
26
+ ]
27
+ },
28
+ {
29
+ "id": "b0bafbe0e8f0fbfe",
30
+ "type": "inject",
31
+ "z": "e83d01afd93457a2",
32
+ "name": "",
33
+ "props": [
34
+ {
35
+ "p": "topic",
36
+ "vt": "str"
37
+ },
38
+ {
39
+ "p": "payload"
40
+ }
41
+ ],
42
+ "repeat": "",
43
+ "crontab": "",
44
+ "once": false,
45
+ "onceDelay": 0.1,
46
+ "topic": "room_setpoint",
47
+ "payload": "19",
48
+ "payloadType": "num",
49
+ "x": 180,
50
+ "y": 60,
51
+ "wires": [
52
+ [
53
+ "4240b41f17726057"
54
+ ]
55
+ ]
56
+ },
57
+ {
58
+ "id": "ae08b6f104a665d7",
59
+ "type": "inject",
60
+ "z": "e83d01afd93457a2",
61
+ "name": "",
62
+ "props": [
63
+ {
64
+ "p": "topic",
65
+ "vt": "str"
66
+ },
67
+ {
68
+ "p": "payload"
69
+ }
70
+ ],
71
+ "repeat": "",
72
+ "crontab": "",
73
+ "once": false,
74
+ "onceDelay": 0.1,
75
+ "topic": "room_setpoint",
76
+ "payload": "20",
77
+ "payloadType": "num",
78
+ "x": 180,
79
+ "y": 100,
80
+ "wires": [
81
+ [
82
+ "4240b41f17726057"
83
+ ]
84
+ ]
85
+ },
86
+ {
87
+ "id": "b045eb8ab1e8c1b4",
88
+ "type": "inject",
89
+ "z": "e83d01afd93457a2",
90
+ "name": "",
91
+ "props": [
92
+ {
93
+ "p": "topic",
94
+ "vt": "str"
95
+ },
96
+ {
97
+ "p": "payload"
98
+ }
99
+ ],
100
+ "repeat": "",
101
+ "crontab": "",
102
+ "once": false,
103
+ "onceDelay": 0.1,
104
+ "topic": "room_setpoint",
105
+ "payload": "21",
106
+ "payloadType": "num",
107
+ "x": 180,
108
+ "y": 140,
109
+ "wires": [
110
+ [
111
+ "4240b41f17726057"
112
+ ]
113
+ ]
114
+ },
115
+ {
116
+ "id": "59422c25d03f624b",
117
+ "type": "inject",
118
+ "z": "e83d01afd93457a2",
119
+ "name": "",
120
+ "props": [
121
+ {
122
+ "p": "topic",
123
+ "vt": "str"
124
+ },
125
+ {
126
+ "p": "payload"
127
+ }
128
+ ],
129
+ "repeat": "",
130
+ "crontab": "",
131
+ "once": false,
132
+ "onceDelay": 0.1,
133
+ "topic": "flow_min",
134
+ "payload": "15",
135
+ "payloadType": "num",
136
+ "x": 190,
137
+ "y": 200,
138
+ "wires": [
139
+ [
140
+ "4240b41f17726057"
141
+ ]
142
+ ]
143
+ },
144
+ {
145
+ "id": "2ea958b1bb71d0f6",
146
+ "type": "inject",
147
+ "z": "e83d01afd93457a2",
148
+ "name": "",
149
+ "props": [
150
+ {
151
+ "p": "topic",
152
+ "vt": "str"
153
+ },
154
+ {
155
+ "p": "payload"
156
+ }
157
+ ],
158
+ "repeat": "",
159
+ "crontab": "",
160
+ "once": false,
161
+ "onceDelay": 0.1,
162
+ "topic": "flow_min",
163
+ "payload": "25",
164
+ "payloadType": "num",
165
+ "x": 190,
166
+ "y": 240,
167
+ "wires": [
168
+ [
169
+ "4240b41f17726057"
170
+ ]
171
+ ]
172
+ },
173
+ {
174
+ "id": "3a5f482dacf066d2",
175
+ "type": "inject",
176
+ "z": "e83d01afd93457a2",
177
+ "name": "",
178
+ "props": [
179
+ {
180
+ "p": "topic",
181
+ "vt": "str"
182
+ },
183
+ {
184
+ "p": "payload"
185
+ }
186
+ ],
187
+ "repeat": "",
188
+ "crontab": "",
189
+ "once": false,
190
+ "onceDelay": 0.1,
191
+ "topic": "flow_max",
192
+ "payload": "70",
193
+ "payloadType": "num",
194
+ "x": 190,
195
+ "y": 300,
196
+ "wires": [
197
+ [
198
+ "4240b41f17726057"
199
+ ]
200
+ ]
201
+ },
202
+ {
203
+ "id": "5a63aece647b1bfa",
204
+ "type": "inject",
205
+ "z": "e83d01afd93457a2",
206
+ "name": "",
207
+ "props": [
208
+ {
209
+ "p": "topic",
210
+ "vt": "str"
211
+ },
212
+ {
213
+ "p": "payload"
214
+ }
215
+ ],
216
+ "repeat": "",
217
+ "crontab": "",
218
+ "once": false,
219
+ "onceDelay": 0.1,
220
+ "topic": "flow_min",
221
+ "payload": "80",
222
+ "payloadType": "num",
223
+ "x": 190,
224
+ "y": 340,
225
+ "wires": [
226
+ [
227
+ "4240b41f17726057"
228
+ ]
229
+ ]
230
+ },
231
+ {
232
+ "id": "430d979427a82b32",
233
+ "type": "inject",
234
+ "z": "e83d01afd93457a2",
235
+ "name": "",
236
+ "props": [
237
+ {
238
+ "p": "topic",
239
+ "vt": "str"
240
+ },
241
+ {
242
+ "p": "payload"
243
+ }
244
+ ],
245
+ "repeat": "",
246
+ "crontab": "",
247
+ "once": false,
248
+ "onceDelay": 0.1,
249
+ "topic": "temperature_outside",
250
+ "payload": "0",
251
+ "payloadType": "num",
252
+ "x": 160,
253
+ "y": 520,
254
+ "wires": [
255
+ [
256
+ "4240b41f17726057"
257
+ ]
258
+ ]
259
+ },
260
+ {
261
+ "id": "6d8f1e8f39b5a26a",
262
+ "type": "inject",
263
+ "z": "e83d01afd93457a2",
264
+ "name": "",
265
+ "props": [
266
+ {
267
+ "p": "topic",
268
+ "vt": "str"
269
+ },
270
+ {
271
+ "p": "payload"
272
+ }
273
+ ],
274
+ "repeat": "",
275
+ "crontab": "",
276
+ "once": false,
277
+ "onceDelay": 0.1,
278
+ "topic": "temperature_outside",
279
+ "payload": "5",
280
+ "payloadType": "num",
281
+ "x": 160,
282
+ "y": 560,
283
+ "wires": [
284
+ [
285
+ "4240b41f17726057"
286
+ ]
287
+ ]
288
+ },
289
+ {
290
+ "id": "6211d7924737710d",
291
+ "type": "inject",
292
+ "z": "e83d01afd93457a2",
293
+ "name": "",
294
+ "props": [
295
+ {
296
+ "p": "topic",
297
+ "vt": "str"
298
+ },
299
+ {
300
+ "p": "payload"
301
+ }
302
+ ],
303
+ "repeat": "",
304
+ "crontab": "",
305
+ "once": false,
306
+ "onceDelay": 0.1,
307
+ "topic": "temperature_outside",
308
+ "payload": "10",
309
+ "payloadType": "num",
310
+ "x": 160,
311
+ "y": 600,
312
+ "wires": [
313
+ [
314
+ "4240b41f17726057"
315
+ ]
316
+ ]
317
+ },
318
+ {
319
+ "id": "937290f7edf9d7b7",
320
+ "type": "inject",
321
+ "z": "e83d01afd93457a2",
322
+ "name": "",
323
+ "props": [
324
+ {
325
+ "p": "topic",
326
+ "vt": "str"
327
+ },
328
+ {
329
+ "p": "payload"
330
+ }
331
+ ],
332
+ "repeat": "",
333
+ "crontab": "",
334
+ "once": false,
335
+ "onceDelay": 0.1,
336
+ "topic": "temperature_outside",
337
+ "payload": "15",
338
+ "payloadType": "num",
339
+ "x": 160,
340
+ "y": 640,
341
+ "wires": [
342
+ [
343
+ "4240b41f17726057"
344
+ ]
345
+ ]
346
+ },
347
+ {
348
+ "id": "8ec790db01a17e49",
349
+ "type": "inject",
350
+ "z": "e83d01afd93457a2",
351
+ "name": "",
352
+ "props": [
353
+ {
354
+ "p": "topic",
355
+ "vt": "str"
356
+ },
357
+ {
358
+ "p": "payload"
359
+ }
360
+ ],
361
+ "repeat": "",
362
+ "crontab": "",
363
+ "once": false,
364
+ "onceDelay": 0.1,
365
+ "topic": "temperature_outside",
366
+ "payload": "20",
367
+ "payloadType": "num",
368
+ "x": 160,
369
+ "y": 680,
370
+ "wires": [
371
+ [
372
+ "4240b41f17726057"
373
+ ]
374
+ ]
375
+ },
376
+ {
377
+ "id": "6e24d282f30b51ed",
378
+ "type": "inject",
379
+ "z": "e83d01afd93457a2",
380
+ "name": "",
381
+ "props": [
382
+ {
383
+ "p": "topic",
384
+ "vt": "str"
385
+ },
386
+ {
387
+ "p": "payload"
388
+ }
389
+ ],
390
+ "repeat": "",
391
+ "crontab": "",
392
+ "once": false,
393
+ "onceDelay": 0.1,
394
+ "topic": "temperature_outside",
395
+ "payload": "-5",
396
+ "payloadType": "num",
397
+ "x": 160,
398
+ "y": 480,
399
+ "wires": [
400
+ [
401
+ "4240b41f17726057"
402
+ ]
403
+ ]
404
+ },
405
+ {
406
+ "id": "166efeaeb4d3ae6d",
407
+ "type": "inject",
408
+ "z": "e83d01afd93457a2",
409
+ "name": "",
410
+ "props": [
411
+ {
412
+ "p": "topic",
413
+ "vt": "str"
414
+ },
415
+ {
416
+ "p": "payload"
417
+ }
418
+ ],
419
+ "repeat": "",
420
+ "crontab": "",
421
+ "once": false,
422
+ "onceDelay": 0.1,
423
+ "topic": "temperature_outside",
424
+ "payload": "-10",
425
+ "payloadType": "num",
426
+ "x": 150,
427
+ "y": 440,
428
+ "wires": [
429
+ [
430
+ "4240b41f17726057"
431
+ ]
432
+ ]
433
+ },
434
+ {
435
+ "id": "12aaf6cdbbf9dfe8",
436
+ "type": "inject",
437
+ "z": "e83d01afd93457a2",
438
+ "name": "",
439
+ "props": [
440
+ {
441
+ "p": "topic",
442
+ "vt": "str"
443
+ },
444
+ {
445
+ "p": "payload"
446
+ }
447
+ ],
448
+ "repeat": "",
449
+ "crontab": "",
450
+ "once": false,
451
+ "onceDelay": 0.1,
452
+ "topic": "temperature_outside",
453
+ "payload": "-15",
454
+ "payloadType": "num",
455
+ "x": 150,
456
+ "y": 400,
457
+ "wires": [
458
+ [
459
+ "4240b41f17726057"
460
+ ]
461
+ ]
462
+ },
463
+ {
464
+ "id": "1d3503b689f7c936",
465
+ "type": "debug",
466
+ "z": "e83d01afd93457a2",
467
+ "name": "debug 66",
468
+ "active": true,
469
+ "tosidebar": true,
470
+ "console": false,
471
+ "tostatus": false,
472
+ "complete": "true",
473
+ "targetType": "full",
474
+ "statusVal": "",
475
+ "statusType": "auto",
476
+ "x": 800,
477
+ "y": 320,
478
+ "wires": []
479
+ }
480
+ ]
Binary file