• gys4tweakers
  • Registratie: Juli 2023
  • Laatst online: 23-10 19:17
MJ de Bruijn schreef op zondag 18 oktober 2026 @ 10:21:
Sorry dat ik zelf niet op je eerdere vraag heb gereageerd, ik was even medisch off-line.
Is je vraag/probleem nu opgelost?
Gezondheid gaat voor op alles.

Ik ben de programmering aan het omzetten naar mijn situatie. Had de afgelopen week weinig tijd om me verder te verdiepen.
Ik heb de flows solar, tiber en states nu werkend (mogelijk is states nog niet compleet). Mijn installatie is uitgerust met een mppt en het huis zit compleet op de AC-out. Als beginner is het dan best een klus om de code te begrijpen en waarnodig aan te passen.

Op dit moment ben ik bezig met de debug van "Monitor Consumption"en "Monitor MPPT". Hier loop ik tegen de waarschuwing "Unknown Topic: yz1solar_yield_today" resp. "Unknown Topic: yz1solar_Reading". Bij Consumption had ik yield-today geselecteerd, na wijzigen in yield since reset is de foutmelding weg.


Bij monitor MPPT verdwijnt de fout als ik bij yield_today selecteer "only changes"
In global context blijft de array yz1solar.Reading alles op 0 staan. Waar/hoe vul ik de array?

De volgende stap is dan de target flow na te lopen en aan te passen aan mijn situatie.

Onder flow targets zie ik nog een foutmelding voor functions "PriceToBuyValue", "PriceToDirectValue" en PriceToSellValue".

Er is nog werk aan de winkel.

  • gys4tweakers
  • Registratie: Juli 2023
  • Laatst online: 23-10 19:17
De volgende functies leiden tot foutmelding onder Targets, "Calculate Targets":

Get_Functions:
Victron_MESS.Functions.PriceToBuyValue
Victron_MESS.Functions.PriceToDirectValue
Victron_MESS.Functions.PriceToSellValue

Onder "Parameters>SetGlobalFunctions"worden ze niet aangemaakt. Vraag is dan waar en met welke code maak ik deze aan?

Ook de inhoud van overige functies zoals "Only Day Ahead Rule" etc. in flow Targets heb ik nogf leeg. Wat moet er inhoudelijk in deze functies staan?

  • MJ de Bruijn
  • Registratie: November 2016
  • Laatst online: 08:59
Naar aanleiding van de voorgaande vraag is het goed om recente wijzigingen te documenteren.
Ik heb de methode 'SetGlobalFunctions' vervangen door de functie 'MakeLoaders'.
MakeLoaders maakt (nog steeds) globale functies aan maar is ook in staat om (alle) variabelen uit een sectie van de Global geheugenruimte in een functie te laden.

Afbeeldingslocatie: https://tweakers.net/i/JoUx25ICjsHahTfX3MGzRxDYgRg=/800x/filters:strip_exif()/f/image/nRuyEtrNQbxrPO7vtXa0lsPq.png?f=fotoalbum_large
code:
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
[
    {
        "id": "e0dfb9db0c37b271",
        "type": "subflow",
        "name": "Show",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 68,
                "y": 80,
                "wires": [
                    {
                        "id": "274fd352337bfbb9"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 364,
                "y": 64,
                "wires": [
                    {
                        "id": "274fd352337bfbb9",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99",
        "status": {
            "x": 364,
            "y": 112,
            "wires": [
                {
                    "id": "274fd352337bfbb9",
                    "port": 1
                }
            ]
        }
    },
    {
        "id": "274fd352337bfbb9",
        "type": "function",
        "z": "e0dfb9db0c37b271",
        "name": "Show Payload",
        "func": "if ( (global.get( \"MESS.UseDebug\" ) || false) === false )\n{\n  if ( (context.get(\"StateIsClear\") || false) === true )\n    { \n      return [msg, null] \n    }\n  else\n    { \n      context.set(\"StateIsClear\", true);\n      return [msg, {topic:'', payload:{text:''}}] \n    }\n}\n\nconst Now = new Date();\nlet NowTime = (\"0\" + Now.getHours()).slice(-2) + \":\"\n                + (\"0\" + Now.getMinutes()).slice(-2) + \":\"\n                + (\"0\" + Now.getSeconds()).slice(-2) ;\n\ncontext.set(\"StateIsClear\", false)\nlet msgState = { topic:'state', \n             payload:\n             { text: NowTime + \": \" + msg.topic + \": \" + msg.payload,\n               shape: \"dot\",\n               fill: \"grey\"\n             }\n};\n\nnode.send( [msg, msgState] );\n\nnode.done();",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 208,
        "y": 80,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "6e66bd5553496300",
        "type": "function",
        "z": "05f545a17b05a933",
        "name": "MakeLoaders",
        "func": "",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\n\nthis.ProgName = \"MakeLoaders\"\nthis.Prog_ID = \"MakeLoaders\"\n",
        "finalize": "node.warn(this.ProgName + \" Cleanup...\");\n\nglobal.set(\"MESS.LastRun.Deploy\"); // remove\nglobal.set(\"MESS.Loaders\"); // remove\nglobal.set(\"MESS.Functions\"); // remove\nglobal.set(\"MESS.Param\");\n",
        "libs": [],
        "x": 368,
        "y": 864,
        "wires": [
            [
                "168187c5aea578b5",
                "d6a71004f3a95346"
            ]
        ]
    },
    {
        "id": "4334cee68d6cbe3f",
        "type": "function",
        "z": "05f545a17b05a933",
        "name": "Make Consump",
        "func": "",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "this.ProgName = \"Make Consumption Forecast\"\nthis.Prog_ID = \"Consumption_Forecast\"\n",
        "finalize": "node.warn(this.ProgName + \" Cleanup...\");\n\nglobal.set(\"MESS.Consump.Forecast_Wh_QH\"); // remove\n",
        "libs": [],
        "x": 368,
        "y": 1056,
        "wires": [
            [
                "5ba94da504c3e36e",
                "80d29df57812ec2c"
            ]
        ]
    },
    {
        "id": "c497c92850753308",
        "type": "inject",
        "z": "05f545a17b05a933",
        "name": "On Demand",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0.3",
        "topic": "Delete Functions",
        "payload": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
        "payloadType": "jsonata",
        "x": 150,
        "y": 816,
        "wires": [
            [
                "a5615530580775b2"
            ]
        ]
    },
    {
        "id": "a264bda36682d6d8",
        "type": "inject",
        "z": "05f545a17b05a933",
        "name": "At Deploy",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "0.1",
        "topic": "At Deploy",
        "payload": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
        "payloadType": "jsonata",
        "x": 128,
        "y": 672,
        "wires": [
            [
                "1ff901c044cad217",
                "91fc0c6b701d4568"
            ]
        ]
    },
    {
        "id": "aad492f80ec98c5c",
        "type": "cronplus",
        "z": "05f545a17b05a933",
        "name": "at 00:00:00",
        "outputField": "payload",
        "timeZone": "",
        "storeName": "",
        "commandResponseMsgOutput": "output1",
        "defaultLocation": "",
        "defaultLocationType": "default",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "AtMidnight",
                "payloadType": "jsonata",
                "payload": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "expressionType": "cron",
                "expression": "0 0 0 * * * * ",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 138,
        "y": 624,
        "wires": [
            [
                "1ff901c044cad217",
                "91fc0c6b701d4568"
            ]
        ]
    },
    {
        "id": "91fc0c6b701d4568",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Delete Trace",
        "rules": [
            {
                "t": "delete",
                "p": "Trace",
                "pt": "global"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Delete_Trace",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 358,
        "y": 720,
        "wires": [
            [
                "9f2c45a9b996b139",
                "1b802d69f16957bc"
            ]
        ]
    },
    {
        "id": "168187c5aea578b5",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "link out Check Deploy is finished",
        "mode": "link",
        "links": [
            "8d9156004535a8ca"
        ],
        "x": 531,
        "y": 864,
        "wires": []
    },
    {
        "id": "5ba94da504c3e36e",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "link out Check Deploy is finished",
        "mode": "link",
        "links": [
            "8d9156004535a8ca"
        ],
        "x": 531,
        "y": 1056,
        "wires": []
    },
    {
        "id": "9f2c45a9b996b139",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "link out Check Deploy is finished",
        "mode": "link",
        "links": [
            "8d9156004535a8ca"
        ],
        "x": 533,
        "y": 720,
        "wires": []
    },
    {
        "id": "d6a71004f3a95346",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 338,
        "y": 912,
        "wires": [
            [
                "3107422456d50542"
            ]
        ]
    },
    {
        "id": "80d29df57812ec2c",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 338,
        "y": 1104,
        "wires": [
            []
        ]
    },
    {
        "id": "1ff901c044cad217",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 338,
        "y": 672,
        "wires": [
            []
        ]
    },
    {
        "id": "a5615530580775b2",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Delete Loaders/Functions/Consump",
        "rules": [
            {
                "t": "delete",
                "p": "MESS.Deploy.Loaders_Ready",
                "pt": "global"
            },
            {
                "t": "delete",
                "p": "MESS.Loaders",
                "pt": "global"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Loaders_Deleted",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            },
            {
                "t": "delete",
                "p": "MESS.Deploy.Consump_Ready",
                "pt": "global"
            },
            {
                "t": "delete",
                "p": "MESS.Consump",
                "pt": "global"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Consump_Deleted",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            },
            {
                "t": "delete",
                "p": "MESS.Functions",
                "pt": "global"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Functions_Deleted",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 432,
        "y": 816,
        "wires": [
            [
                "6e66bd5553496300",
                "3086d316701879aa"
            ]
        ]
    },
    {
        "id": "1b802d69f16957bc",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Delete MESS.Batt",
        "rules": [
            {
                "t": "delete",
                "p": "MESS.Batt",
                "pt": "global"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Batt_All_Deleted",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 378,
        "y": 768,
        "wires": [
            [
                "a5615530580775b2"
            ]
        ]
    },
    {
        "id": "3107422456d50542",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Set MESS.Param.EntsoeApiKey",
        "rules": [
            {
                "t": "set",
                "p": "MESS.Param.EntsoeApiKey",
                "pt": "global",
                "to": "secret",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 422,
        "y": 960,
        "wires": [
            [
                "dac188ac635c56ae"
            ]
        ]
    },
    {
        "id": "dac188ac635c56ae",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Set MESS.Param.SolcastApiKey",
        "rules": [
            {
                "t": "set",
                "p": "MESS.Param.SolcastApiKey",
                "pt": "global",
                "to": "secret",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 436,
        "y": 1008,
        "wires": [
            [
                "4334cee68d6cbe3f"
            ]
        ]
    },
    {
        "id": "bf41e634f54e5afc",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Check if Deploy has finished",
        "info": "",
        "x": 648,
        "y": 752,
        "wires": []
    },
    {
        "id": "b47bb3bf3f463540",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Check if Deploy has finished",
        "info": "",
        "x": 648,
        "y": 896,
        "wires": []
    },
    {
        "id": "ad7f7ad223aecbd8",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Check if Deploy has finished",
        "info": "",
        "x": 648,
        "y": 1088,
        "wires": []
    },
    {
        "id": "cacffa090232d056",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Check if Deploy has finished",
        "info": "",
        "x": 760,
        "y": 848,
        "wires": []
    },
    {
        "id": "3086d316701879aa",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "link out Check Deploy is finished",
        "mode": "link",
        "links": [
            "8d9156004535a8ca"
        ],
        "x": 641,
        "y": 816,
        "wires": []
    }
]
Afbeeldingslocatie: https://tweakers.net/i/2MhIKmF9Jm2WYPx_D6cZnEH_XxI=/800x/filters:strip_exif()/f/image/g63tEQXhORtyHKVhOdJclMPQ.png?f=fotoalbum_large
code:
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
[
    {
        "id": "e0dfb9db0c37b271",
        "type": "subflow",
        "name": "Show",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 68,
                "y": 80,
                "wires": [
                    {
                        "id": "274fd352337bfbb9"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 364,
                "y": 64,
                "wires": [
                    {
                        "id": "274fd352337bfbb9",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99",
        "status": {
            "x": 364,
            "y": 112,
            "wires": [
                {
                    "id": "274fd352337bfbb9",
                    "port": 1
                }
            ]
        }
    },
    {
        "id": "274fd352337bfbb9",
        "type": "function",
        "z": "e0dfb9db0c37b271",
        "name": "Show Payload",
        "func": "if ( (global.get( \"MESS.UseDebug\" ) || false) === false )\n{\n  if ( (context.get(\"StateIsClear\") || false) === true )\n    { \n      return [msg, null] \n    }\n  else\n    { \n      context.set(\"StateIsClear\", true);\n      return [msg, {topic:'', payload:{text:''}}] \n    }\n}\n\nconst Now = new Date();\nlet NowTime = (\"0\" + Now.getHours()).slice(-2) + \":\"\n                + (\"0\" + Now.getMinutes()).slice(-2) + \":\"\n                + (\"0\" + Now.getSeconds()).slice(-2) ;\n\ncontext.set(\"StateIsClear\", false)\nlet msgState = { topic:'state', \n             payload:\n             { text: NowTime + \": \" + msg.topic + \": \" + msg.payload,\n               shape: \"dot\",\n               fill: \"grey\"\n             }\n};\n\nnode.send( [msg, msgState] );\n\nnode.done();",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 208,
        "y": 80,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "9439121f6be1fcec",
        "type": "subflow",
        "name": "Wait Deploy",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 60,
                "y": 48,
                "wires": [
                    {
                        "id": "0f54e83663e3c00e"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 628,
                "y": 96,
                "wires": [
                    {
                        "id": "4e711671b89ca482",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99",
        "status": {
            "x": 628,
            "y": 144,
            "wires": [
                {
                    "id": "ee1351bac2215a95",
                    "port": 2
                },
                {
                    "id": "4e711671b89ca482",
                    "port": 1
                }
            ]
        }
    },
    {
        "id": "0f54e83663e3c00e",
        "type": "switch",
        "z": "9439121f6be1fcec",
        "name": "Deploy not Ready / Ready",
        "property": "MESS.Deploy.Ready",
        "propertyType": "global",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 226,
        "y": 48,
        "wires": [
            [
                "ee1351bac2215a95"
            ],
            [
                "4e711671b89ca482"
            ]
        ]
    },
    {
        "id": "ee1351bac2215a95",
        "type": "function",
        "z": "9439121f6be1fcec",
        "name": "Push to Queue",
        "func": "let msgQueueName = null;\n\nif (context.get(\"QueueName\") == null)\n{\n  let uniqueSubflowInstanceId =\n    env.get(\"NR_SUBFLOW_INSTANCE_ID\") || node.id;\n  uniqueSubflowInstanceId =\n    uniqueSubflowInstanceId.replace(/[^a-zA-Z0-9]/g, \"\");\n\n  context.set(\"QueueName\", \"$parent.\" + uniqueSubflowInstanceId); \n\n  // clear previous instance\n  flow.set(context.get(\"QueueName\"));\n\n  msgQueueName = {\n    topic: \"QueueName\",\n    payload: context.get(\"QueueName\")\n  }\n} // if QueueName = null\n\nlet Queue = flow.get(context.get(\"QueueName\")) || [];\nQueue.push(msg);\nflow.set(context.get(\"QueueName\"), Queue);\n\nlet msgState = {\n  topic: 'state',\n  payload: {\n    text: msg.topic + \": \" + msg.payload\n      + \"; \" + Queue.length + \" msgs pending\",\n    shape: \"dot\",\n    fill: \"blue\"\n  }\n};\n\nreturn [msg, msgQueueName, msgState];\n",
        "outputs": 3,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 464,
        "y": 48,
        "wires": [
            [],
            [
                "4e711671b89ca482"
            ],
            []
        ]
    },
    {
        "id": "4e711671b89ca482",
        "type": "function",
        "z": "9439121f6be1fcec",
        "name": "Read Queue",
        "func": "let msgState = null;\n\nif (msg.topic == \"QueueName\") \n{\n  context.set(\"QueueName\", msg.payload);\n  return [null, null];\n}\n\nif (typeof context.get(\"QueueDone\") === \"undefined\")\n{\n  context.set(\"QueueDone\", false);\n}\n\nif ( (typeof context.get(\"QueueName\") !== \"undefined\")\n  && (context.get(\"QueueDone\") == false) )\n{\n  let Queue = flow.get(context.get(\"QueueName\")) || [];\n  for (let msgItem of Queue) \n  {\n    msgState = {\n      topic: 'state',\n      payload: {\n        text: msgItem.topic + \": \" + msgItem.payload,\n        shape: \"dot\",\n        fill: \"yellow\"\n      }\n    };\n\n    node.send( [msgItem, msgState] );\n  }\n  \n  // Clear Queue in memory]\n  flow.set(context.get(\"QueueName\"), null);\n\n  context.set(\"QueueDone\", true);\n} // QueueDone is false\n\nmsgState = {\n  topic: 'state',\n  payload: {\n    text: msg.topic + \": \" + msg.payload,\n    shape: \"dot\",\n    fill: \"green\"\n  }\n};\n\nreturn [msg, msgState];\n",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "context.set(\"QueueDone\", false);\n",
        "libs": [],
        "x": 458,
        "y": 112,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "15280dc1293e4200",
        "type": "switch",
        "z": "05f545a17b05a933",
        "name": "Deploy Loaders is null",
        "property": "MESS.Deploy.Loaders_Ready",
        "propertyType": "global",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 372,
        "y": 1248,
        "wires": [
            [
                "ea8e640ce08b8681"
            ],
            [
                "140dcc445642cdb3"
            ]
        ]
    },
    {
        "id": "8d9156004535a8ca",
        "type": "link in",
        "z": "05f545a17b05a933",
        "name": "link in Check Deploy is finished",
        "links": [
            "3c8d72451cf3c95f",
            "168187c5aea578b5",
            "5ba94da504c3e36e",
            "9f2c45a9b996b139",
            "703fe186021ff7c6",
            "3086d316701879aa"
        ],
        "x": 145,
        "y": 1248,
        "wires": [
            [
                "15280dc1293e4200",
                "966bb0807494a4ed"
            ]
        ]
    },
    {
        "id": "966bb0807494a4ed",
        "type": "subflow:9439121f6be1fcec",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 342,
        "y": 1536,
        "wires": [
            [
                "aff4769a148ef413",
                "643ba5457d5077e6"
            ]
        ]
    },
    {
        "id": "140dcc445642cdb3",
        "type": "switch",
        "z": "05f545a17b05a933",
        "name": "Deploy Consump is null",
        "property": "MESS.Deploy.Consump_Ready",
        "propertyType": "global",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 382,
        "y": 1296,
        "wires": [
            [
                "fcf004566952b6e3"
            ],
            [
                "4f26607a1d1ca070"
            ]
        ]
    },
    {
        "id": "ea8e640ce08b8681",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 606,
        "y": 1248,
        "wires": [
            []
        ]
    },
    {
        "id": "fcf004566952b6e3",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 606,
        "y": 1296,
        "wires": [
            []
        ]
    },
    {
        "id": "9b62af08049c44a8",
        "type": "debug",
        "z": "05f545a17b05a933",
        "name": "debug Deploy",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic & \" \" & payload",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 608,
        "y": 1488,
        "wires": []
    },
    {
        "id": "fa1c4030c38b4e37",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "Link Out After Deploy is Ready",
        "mode": "link",
        "links": [
            "8de1257c814a90d9",
            "b4bf75cf2df3ef8b",
            "13fa55fc8b7732fc",
            "ffcd0aab2bf5ae1d",
            "6dc5f7ef3b76a593",
            "5e5f43dab4d29faa",
            "1682f0c29aa6fdc4",
            "6e8fe8fe286dc609"
        ],
        "x": 545,
        "y": 1440,
        "wires": []
    },
    {
        "id": "4f26607a1d1ca070",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Set Deploy Ready",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Deploy Ready",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "MESS.Deploy.Ready",
                "pt": "global",
                "to": "( $moment().format(\"YYYY-MM-DD HH:mm:ss\") )",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 362,
        "y": 1344,
        "wires": [
            [
                "d535b442595fc72d"
            ]
        ]
    },
    {
        "id": "5004a422e89f842c",
        "type": "subflow:e0dfb9db0c37b271",
        "z": "05f545a17b05a933",
        "name": "",
        "x": 322,
        "y": 1440,
        "wires": [
            [
                "fa1c4030c38b4e37",
                "966bb0807494a4ed",
                "9b62af08049c44a8"
            ]
        ]
    },
    {
        "id": "d535b442595fc72d",
        "type": "delay",
        "z": "05f545a17b05a933",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "5",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 352,
        "y": 1392,
        "wires": [
            [
                "5004a422e89f842c"
            ]
        ]
    },
    {
        "id": "2e4c1e080be2a4e5",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Get MESS.Param",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Param",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target",
                "pt": "msg",
                "to": "MESS",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "MESS.Param",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 362,
        "y": 1600,
        "wires": [
            [
                "cbe5c5d426009513"
            ]
        ]
    },
    {
        "id": "cbe5c5d426009513",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "Link Out to HaNodeRed MQTT",
        "mode": "link",
        "links": [
            "8e1c3c8242995023"
        ],
        "x": 545,
        "y": 1600,
        "wires": []
    },
    {
        "id": "041bc434d2acb0a0",
        "type": "change",
        "z": "05f545a17b05a933",
        "name": "Get MESS.Consump.Consump_Forecast_Wh_QH",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Consump_Forecast_Wh_QH",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target",
                "pt": "msg",
                "to": "MESS.Consump",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "MESS.Consump.Consump_Forecast_Wh_QH",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 466,
        "y": 1648,
        "wires": [
            [
                "bad32c2923ff3f07"
            ]
        ]
    },
    {
        "id": "bad32c2923ff3f07",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "Link Out to HaNodeRed MQTT",
        "mode": "link",
        "links": [
            "8e1c3c8242995023"
        ],
        "x": 545,
        "y": 1696,
        "wires": []
    },
    {
        "id": "aff4769a148ef413",
        "type": "link out",
        "z": "05f545a17b05a933",
        "name": "Link Out Call Set EV_Power defaults",
        "mode": "link",
        "links": [
            "5ec002b06846fa84"
        ],
        "x": 545,
        "y": 1536,
        "wires": []
    },
    {
        "id": "643ba5457d5077e6",
        "type": "delay",
        "z": "05f545a17b05a933",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 180,
        "y": 1600,
        "wires": [
            [
                "2e4c1e080be2a4e5",
                "2eb08b8db8bfcb5c"
            ]
        ]
    },
    {
        "id": "2eb08b8db8bfcb5c",
        "type": "delay",
        "z": "05f545a17b05a933",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 180,
        "y": 1648,
        "wires": [
            [
                "041bc434d2acb0a0"
            ]
        ]
    },
    {
        "id": "0ff6339d11d38670",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Set EVPower Defaults",
        "info": "",
        "x": 668,
        "y": 1536,
        "wires": []
    },
    {
        "id": "f7c6b5c1159007df",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Send to Home Assistant",
        "info": "",
        "x": 668,
        "y": 1600,
        "wires": []
    },
    {
        "id": "b096f5563c59c68d",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Send to Home Assistant",
        "info": "",
        "x": 668,
        "y": 1696,
        "wires": []
    },
    {
        "id": "b857cf919fcd231d",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Process States + Solar",
        "info": "",
        "x": 668,
        "y": 1440,
        "wires": []
    },
    {
        "id": "cb1770fd6685d4ac",
        "type": "comment",
        "z": "05f545a17b05a933",
        "name": "Link in Check if Deploy has finished",
        "info": "",
        "x": 188,
        "y": 1216,
        "wires": []
    }
]
De functie 'MakeLoaders' plaats ik in de volgende post.

[ Voor 3% gewijzigd door MJ de Bruijn op 20-10-2026 12:30 ]

Een mens leert van zijn fouten. Ik heb in mijn leven heel veel geleerd.


  • MJ de Bruijn
  • Registratie: November 2016
  • Laatst online: 08:59
Dit is de actuele functie MakeLoaders
Let op: Controleer altijd in de inhoudsopgave of er een meer recentere versie is geplaatst.
code:
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
// @ts-nocheck

// See On Start
// Daarin staat:
// this.ProgName = "MakeLoaders"
// this.Prog_ID = "MakeLoaders"

let DebugStep = "Start";
let NewLine = "\r\n";

global.set("MESS.Deploy.Loaders_Ready"); // remove

try {
  DebugStep = "Trace";

  const Trace = (p_ID, p_Text) => 
  {

    if ( (global.get( "MESS.UseDebug" ) || false) === false ) { return null } ;

    const NewLine = "\n";

    let formattedText = p_Text;

    if (p_Text === "ClearTrace") 
    {
      formattedText = "ClearTrace";
    } 
    else if (Array.isArray(p_Text)) 
    {
      // Toon type, lengte en inhoud van de Array
      formattedText = `Array(${p_Text.length})`;
    }
    else if (typeof p_Text === 'object' && p_Text !== null) 
    {
      // Toon inhoud van het Object
      formattedText = `[Object]: ${JSON.stringify(p_Text)}`;
    } 
    else if (p_Text === null) 
    {
      formattedText = "null";
    } 
    else if (p_Text === undefined) 
    {
      formattedText = "undefined";
    } 
    else 
    {
      formattedText = String(p_Text);
    }

    if (p_ID == null) 
    {
      node.warn("Trace: p_ID is null!");
      return null;
    }

    let curTraceText = global.get("Trace." + p_ID);

    if (curTraceText == null) 
    {
      curTraceText = [""];
    }

    let curTraceTextIndex = curTraceText.length - 1;

    if (formattedText === "ClearTrace") 
    {
      curTraceText = [""];
      curTraceTextIndex = 0;
    } 
    else 
    if ((curTraceText[curTraceTextIndex].length + formattedText.length) > 1000) 
    {
      curTraceText[curTraceTextIndex] += NewLine;
      curTraceTextIndex++;
      curTraceText[curTraceTextIndex] = formattedText;
    } 
    else 
    {
      curTraceText[curTraceTextIndex] += formattedText;
    }

    global.set("Trace." + p_ID, curTraceText);

    return null;
  }
  
  global.set("MESS.Functions.Trace", Trace);

  Trace(Prog_ID, "ClearTrace" + NewLine)
  Trace(Prog_ID, "Loaders.LoadFunctions" + NewLine)
  Trace(Prog_ID, "Trace" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "GetNowTime";

  const GetNowTime = (p_format) =>
  {
      const Now = new Date()
      
      if (p_format == "NowHour")
      {
          // return ("0" + Now.getHours()).slice(-2);
          return Now.getHours();
      }
      else if ( (p_format == "NowQuarter")
              || (p_format == "NowQuarterHour")
              || (p_format == "Now_QH")
              || (p_format == "NowQH")
              )
      {
          return (4 * Now.getHours()
                + Math.floor(Now.getMinutes()/15) );
  
      }
      else if (p_format == "NowMinutes")
      {
          // return ("0" + Now.getMinutes()).slice(-2);
          return Now.getMinutes();
      }
      else if (p_format == "NowInSeconds")
      {
          return Math.floor(Now.getTime() / 1000);
      }
      if ( (p_format == "uu:mm")
        || (p_format == "UU:MM") )
      {
          return ("0" + Now.getHours()).slice(-2)
                  + ":"
                  + ("0" + Now.getMinutes() ).slice(-2);
      }
      else if ( (p_format == "yyyymmdd")
              || (p_format == "YYYYMMDD") )
      {
          return Now.getFullYear()
              + ("0" + (Now.getMonth() + 1)).slice(-2)
              + ("0" + Now.getDate()).slice(-2);
      }
      else if ( (p_format == "yyyy-mm-dd")
              || (p_format == "YYYY-MM-DD") )
      {
          return Now.getFullYear()
              + "-" + ("0" + (Now.getMonth() + 1)).slice(-2)
              + "-" + ("0" + Now.getDate()).slice(-2);
      }
      else if ( (p_format == "uu:mm:ss")
              || (p_format == "UU:MM:SS") )
      {
          return ("0" + Now.getHours()).slice(-2) + ":"
              + ("0" + Now.getMinutes()).slice(-2) + ":"
              + ("0" + Now.getSeconds()).slice(-2) ;
      }
      else
      {
          return Now.getFullYear() + "-"
              + ("0" + (Now.getMonth() + 1)).slice(-2) + "-"
              + ("0" + Now.getDate()).slice(-2) + " "
              + ("0" + Now.getHours()).slice(-2) + ":"
              + ("0" + Now.getMinutes()).slice(-2) + ":"
              + ("0" + Now.getSeconds()).slice(-2) ;
      }
  }
  
  global.set("MESS.Functions.GetNowTime", GetNowTime);
  
  Trace(Prog_ID, "GetNowTime" + NewLine)
  Trace(Prog_ID, "= " + GetNowTime() + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "GetTomorrow";

  const GetTomorrow = (p_format) =>
  {
      let Tomorrow = new Date();
      Tomorrow.setDate(Tomorrow.getDate() + 1);
  
      if (p_format == "yyyymmdd")
      {
          return Tomorrow.getFullYear()
                + ("0" + (Tomorrow.getMonth() + 1)).slice(-2)
                + ("0" + Tomorrow.getDate()).slice(-2) ;
      }
      else
      {
          return Tomorrow.getFullYear() + "-"
                + ("0" + (Tomorrow.getMonth() + 1)).slice(-2) + "-"
                + ("0" + Tomorrow.getDate()).slice(-2) ;
      }
  }
  
  global.set("MESS.Functions.GetTomorrow", GetTomorrow);
  
  Trace(Prog_ID, "GetTomorrow" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "GetYesterday";

  const GetYesterday = (p_format) =>
  {
      let Yesterday = new Date();
      Yesterday.setDate(Yesterday.getDate() - 1);
  
      if (p_format == "yyyymmdd")
      {
          return Yesterday.getFullYear()
                + ("0" + (Yesterday.getMonth() + 1)).slice(-2)
                + ("0" + Yesterday.getDate()).slice(-2) ;
      }
      else
      {
          return Yesterday.getFullYear() + "-"
                + ("0" + (Yesterday.getMonth() + 1)).slice(-2) + "-"
                + ("0" + Yesterday.getDate()).slice(-2) ;
      }
  }
  
  global.set("MESS.Functions.GetYesterday", GetYesterday);
  
  Trace(Prog_ID, "GetYesterday" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "TimestampTo_HH_MM_SS";

  const TimestampTo_HH_MM_SS = (p_date) =>
  {
      const curdate = new Date(null);
  
      curdate.setSeconds(p_date)
  
      return ( ("0" + curdate.getHours()).slice(-2) + ":"
              + ("0" + curdate.getMinutes()).slice(-2) + ":"
              + ("0" + curdate.getSeconds()).slice(-2) 
              );
              
  }
  
  global.set("MESS.Functions.TimestampTo_HH_MM_SS", 
              TimestampTo_HH_MM_SS);
  
  Trace(Prog_ID, "TimestampTo_HH_MM_SS" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "TimestampTo_QH";

  const TimestampTo_QH = (p_date) =>
  {
      try
      {
          var TempDate = new Date(p_date);
  
          return (4 * TempDate.getHours()
                + Math.floor(TempDate.getMinutes()/15) );
      }
      catch (error)
      {
          node.warn("Error TimestampTo_QH: " + error);
          return ("");
      }
  }
  
  global.set("MESS.Functions.TimestampTo_QH", TimestampTo_QH);
  
  Trace(Prog_ID, "TimestampTo_QH" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "QHToText";

  const QHToText = (p_QH) =>
  {
      const QH_Symbol = [":00", ":15", ":30", ":45"];
      
      let curHour = Math.floor(p_QH/4);
      let curQH = p_QH - 4 * curHour;
      let Result = "";
      
      if (curHour < 24) {
          Result += 
            ('0' + curHour.toString()).slice(-2)
            + QH_Symbol[curQH];
      }
      else {
          Result += "+" 
            + ('0' + (curHour-24).toString()).slice(-2)
            + QH_Symbol[curQH];
      }
      
      return Result;
      
  }
  
  global.set("MESS.Functions.QHToText", QHToText);
  
  Trace(Prog_ID, "QHToText" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "Not";

  const Not = (p_Boolean) =>
  {
      return !p_Boolean;
  }
  
  global.set("MESS.Functions.Not", Not);
  
  Trace(Prog_ID, "Not" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "CtToText";

  const CtToText = (C) =>
  {
      let C1= Round(C, 1);
      return Number(C1).toFixed(1) + "ct";
  } // CtToText
  
  global.set("MESS.Functions.CtToText", CtToText);
  
  Trace(Prog_ID, "CtToText" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "HourToText";

  const HourToText = (H) =>
  {
      if (Number(H) <= 23) {
          return Number(H).toString();
      }
      else {
          return "+" + (Number(H)-24).toString();
      }
  } // HourToText
  
  global.set("MESS.Functions.HourToText", HourToText);
  
  Trace(Prog_ID, "HourToText" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "WhToText";

  const WhToText = (p_Wh, dec) =>
  {
      let WhSign = Math.sign(p_Wh);
      let WhAbs = Math.abs(p_Wh);
      if (WhAbs >= 1000) {
          if (dec == null) // 1 decimal
              { return ((WhSign * Round(WhAbs/100)/10)).toFixed(1) + "kWh" }
          else if (dec == 0)
              { return ((WhSign * Round(WhAbs/1000))).toFixed(dec) + "kWh" }
          else if (dec == 1)
              { return ((WhSign * Round(WhAbs/100)/10)).toFixed(dec) + "kWh" }
          else if (dec == 2)
              { return ((WhSign * Round(WhAbs/10)/100)).toFixed(dec) + "kWh" }
              
      }
      else {
          return (WhSign * Round(WhAbs)).toString() + "Wh";
      }
  } // WhToText
  
  global.set("MESS.Functions.WhToText", WhToText);
  
  Trace(Prog_ID, "WhToText" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "kWhToWh";

  const kWhToWh = (x) =>
  {
    return Round(x * 1000);
  } // kWhToWh
  
  global.set("MESS.Functions.kWhToWh", kWhToWh);
  
  Trace(Prog_ID, "kWhToWh" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "BoolToChar";

  const BoolToChar = (p_Bool) =>
  {
    if (p_Bool)
    {
        return "\u2714"; // check
    }
    else if ( !(p_Bool) )
    {
        return "\u2718"; // ballot          
    }
    else
    {
        return "\u2047"; // double ??
    }
  } // BoolToChar

  global.set("MESS.Functions.BoolToChar", BoolToChar);
  
  Trace(Prog_ID, "BoolToChar" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "Max";

  const Max = Math.max;

  global.set("MESS.Functions.Max", Max);
  
  Trace(Prog_ID, "Max" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "Min";

  const Min = Math.min;

  global.set("MESS.Functions.Min", Min);
  
  Trace(Prog_ID, "Min" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "Round";

  const Round = (x, dec) =>
  {
      let curSign = Math.sign(x);
      let x_abs = Math.abs(x);
      
      if (dec == null)
          { return curSign * Math.round(x_abs) }
      else if (dec == 0)
          { return curSign * Math.round(x_abs) }
      else if (dec == 1)
          { return curSign * Math.round(x_abs*10) / 10 }
      else if (dec == 2)
          { return curSign * Math.round(x_abs*100) / 100 }
      else if (dec == 3)
          { return curSign * Math.round(x_abs*1000) / 1000 }
      else if (dec == -1)
          { return curSign * Math.round(x_abs/10) * 10 }
      else if (dec == -2)
          { return curSign * Math.round(x_abs/100) * 100 }
      else if (dec == -3)
          { return curSign * Math.round(x_abs/1000) * 1000 }
      else
          { return curSign * Math.round(x_abs) }
  } // Round
  
  global.set("MESS.Functions.Round", Round);
  
  Trace(Prog_ID, "Round" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
  DebugStep = "PriceToBuyValue";

  const PriceToBuyGross = (Net_Price, CallerName) =>
    { // excl. Conversion loss
        var DebugStep = "Start";
        var NewLine = "\n\r";

    try
      {
        DebugStep = "Test Undefined";
      
        var Result = 0;
        
        // node.warn(typeof Net_Price);
        if (typeof Net_Price == 'undefined')
        {
            node.warn("CallerName: " + CallerName + NewLine
                + "PriceToBuyValue; Net_Price is: " + Net_Price);
        }

        DebugStep = "Calculate Result";

      let BTW_fact = 1 + global.get("MESS.Param.Param_BTW_Perc") / 100;

        Result = 
          Round(
            ( Net_Price
              + global.get("MESS.Param.Param_kWh_Buy_TaxCt")
              + global.get("MESS.Param.Param_kWh_Buy_CostCt") )
            * BTW_fact,
          2 );
      }
      catch (error)
      {
        node.warn("Error in " + "PriceToBuyGross" + ":" + NewLine
        + "CallerName: " + CallerName + NewLine
        + "Step: " + DebugStep + NewLine
        + "Error: " + error)
      }
      return Result;
    }
    
  global.set("MESS.Functions.PriceToBuyGross", PriceToBuyGross);
    
  Trace(Prog_ID, "PriceToBuyGross" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
  DebugStep = "PriceToBuyValue";

  const PriceToBuyValue = (Net_Price, CallerName) => 
  { //incl. conversion loss
    Result = Round(PriceToBuyGross(Net_Price, CallerName)
      / global.get("MESS.Param.Param_Conversion_Loss_Factor"),
             2 );
    return Result;
  }

  global.set("MESS.Functions.PriceToBuyValue", PriceToBuyValue);

  Trace(Prog_ID, "PriceToBuyValue" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "PriceToDirectValue";

  const PriceToDirectValue = (Net_Price, CallerName) =>
  {
    return PriceToBuyGross(Net_Price, CallerName);
  }
  
  global.set("MESS.Functions.PriceToDirectValue", PriceToDirectValue);
  
  Trace(Prog_ID, "PriceToDirectValue" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "PriceToSellGross";

  const PriceToSellGross = (Net_Price, CallerName) =>
  {
    var DebugStep = "Start";
    var NewLine = "\n\r";

    try
    {
      DebugStep = "Test Undefined";
      
      var Result = 0;
      
      // node.warn(typeof Net_Price);
      if (typeof Net_Price == 'undefined')
      {
        node.warn("CallerName: " + CallerName + NewLine
            + "PriceToSellValue; Net_Price is: " + Net_Price);
      }
  
      DebugStep = "Get Globals";
    
      if (!(global.get("MESS.Param.Param_kWh_Buy_TaxCt")) ) {
        node.warn("MESS.Param.Param_kWh_Buy_TaxCt: null");
      }
      if (typeof global.get("MESS.Param.Param_kWh_Sell_TaxCt") === 'undefined')
      {
        node.warn("MESS.Param.Param_kWh_Sell_TaxCt: null");
      }
      if (!(global.get("MESS.Param.Param_kWh_Buy_CostCt")) ) {
        node.warn("MESS.Param.Param_kWh_Buy_CostCt: null");
      }
      if (!(global.get("MESS.Param.Param_kWh_Sell_CostCt")) ) {
        node.warn("MESS.Param.Param_kWh_Sell_CostCt: null");
      }
      if (!(global.get("MESS.Param.Param_BTW_Perc")) ) {
        node.warn("MESS.Param.Param_BTW_Perc: null");
      }
      if (!(global.get("MESS.Param.Param_Conversion_Loss_Factor")) ) {
        node.warn("MESS.Param.Param_Conversion_Loss_Factor: null");
      }

      DebugStep = "Calculate Result";
        
      let BTW_fact = 1 + Number(global.get("MESS.Param.Param_BTW_Perc")) / 100;

      Result = 
        Round( 
          ( Net_Price
            - Number(global.get("MESS.Param.Param_kWh_Sell_CostCt")) 
          ) * BTW_fact,
        2 );
    }
    catch (error)
    {
      node.warn("Error in " + "PriceToSellGross" + ":" + NewLine
        + "CallerName: " + CallerName + NewLine
        + "Step: " + DebugStep + NewLine
        + "Error: " + error)
    }
    return Result;
  }
    
  global.set("MESS.Functions.PriceToSellGross", PriceToSellGross);
    
  Trace(Prog_ID, "PriceToSellGross" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
  DebugStep = "PriceToSellValue";

  const PriceToSellValue = (Net_Price, CallerName) => 
  {
    return Round( PriceToSellGross(Net_Price, CallerName)
      * global.get("MESS.Param.Param_Conversion_Loss_Factor"),
            2 );
  }

  global.set("MESS.Functions.PriceToSellValue", PriceToSellValue);

  Trace(Prog_ID, "PriceToSellValue" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "PosInArrayOfSets";
  
  const PosInArrayOfSets = (p_ArrayOfSets, p_SearchQH) =>
  
  {
      let Result = -1;
      
      for ( let i = 0; i < p_ArrayOfSets.length; i++)
      {
          if ( p_ArrayOfSets[i][0] == p_SearchQH ) 
          {
              Result = i;
              break;
          } // Item was found
      } // for i
      
      return Result;
      
  } // PosInArrayOfSets
  
  global.set("MESS.Functions.PosInArrayOfSets", PosInArrayOfSets);
  
  Trace(Prog_ID, "PosInArrayOfSets" + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "IsInArrayOfSets";
  
  const IsInArrayOfSets = (p_ArrayOfSets, p_SearchQHs) =>
  
  { // See if any of the items within array p_SearchQHs
    // are in array p_ArrayOfSets{hour, value]
      let Result = false;
      
      for (let i = 0; i < p_SearchQHs.length; i++) {
          for ( let j = 0; j < p_ArrayOfSets.length; j++)
          {
              if ( p_ArrayOfSets[j][0] == p_SearchQHs[i] ) 
              {
                  Result = true;
                  break;
              } // Item was found
          } // for j
          if (Result) break;
      } // all items
      
      return Result; // not found
      
  } // IsInArrayOfSets
  
  global.set("MESS.Functions.IsInArrayOfSets", IsInArrayOfSets);
  
  Trace(Prog_ID, "IsInArrayOfSets" + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_PV_Modulate_QH";
  
  const Is_PV_Modulate_QH = (p_QH) =>
  {
    let QH_PV_Modulate = 
      global.get("MESS.DayAhead.QH_PV_Modulate");
    return (IsInArrayOfSets(QH_PV_Modulate, [p_QH]) )
  } // Is_PV_Modulate_QH

  global.set("MESS.Functions.Is_PV_Modulate_QH", Is_PV_Modulate_QH);
  
  Trace(Prog_ID, "Is_PV_Modulate_QH" + NewLine)
  
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_PVOff_QH";

  const Is_PVOff_QH = (p_QH) => {
    let QH_PVOff = global.get("MESS.DayAhead.QH_PVOff");
    return (IsInArrayOfSets(QH_PVOff, [p_QH]))
  } // Is_PVOff_QH

  global.set("MESS.Functions.Is_PVOff_QH", Is_PVOff_QH);

  Trace(Prog_ID, "Is_PVOff_QH" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_Negative_Price";
  
  const Is_Negative_Price = (p_QH) =>
  {
    let QH_Negative = global.get("MESS.DayAhead.QH_Negative");
    return ( IsInArrayOfSets(QH_Negative, [p_QH]) )
  } // Is_Negative_Price

  global.set("MESS.Functions.Is_Negative_Price", Is_Negative_Price);
  
  Trace(Prog_ID, "Is_Negative_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_Zero_Price";
  
  const Is_Zero_Price = (p_QH) =>
  {
    let QH_Zero = global.get("MESS.DayAhead.QH_Zero");
    return ( IsInArrayOfSets(QH_Zero, [p_QH]) )
  } // Is_Zero_Price

  global.set("MESS.Functions.Is_Zero_Price", Is_Zero_Price);
  
  Trace(Prog_ID, "Is_Zero_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_Very_Low_Price";
  
  const Is_Very_Low_Price = (p_QH) =>
  {
    let QH_VeryLow = global.get("MESS.DayAhead.QH_VeryLow");
    return ( IsInArrayOfSets(QH_VeryLow, [p_QH]) )
  } // Is_Very_Low_Price

  global.set("MESS.Functions.Is_Very_Low_Price", Is_Very_Low_Price);
  
  Trace(Prog_ID, "Is_Very_Low_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_Low_Price";
  
  const Is_Low_Price = (p_QH) =>
  {
    let QH_Low = global.get("MESS.DayAhead.QH_Low");
    return ( IsInArrayOfSets(QH_Low, [p_QH]) )
  } // Is_Low_Price

  global.set("MESS.Functions.Is_Low_Price", Is_Low_Price);
  
  Trace(Prog_ID, "Is_Low_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_Normal_Price";
  
  const Is_Normal_Price = (p_QH) =>
  {
    let QH_Normal = global.get("MESS.DayAhead.QH_Normal");
    return ( IsInArrayOfSets(QH_Normal, [p_QH]) )
  } // Is_Normal_Price

  global.set("MESS.Functions.Is_Normal_Price", Is_Normal_Price);
  
  Trace(Prog_ID, "Is_Normal_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Is_High_Price";
  
  const Is_High_Price = (p_QH) =>
  {
    let QH_High = global.get("MESS.DayAhead.QH_High");
    return ( IsInArrayOfSets(QH_High, [p_QH]) )
  } // Is_High_Price

  global.set("MESS.Functions.Is_High_Price", Is_High_Price);
  
  Trace(Prog_ID, "Is_High_Price" + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "ArrayOfSetsGetPriceByHour";
  
  const ArrayOfSetsGetPriceByHour = (p_ArrayOfSets, p_SearchQH) =>
  
  { // Find the price of the specified hour 
    // is in array p_ArrayOfSets{hour, value]
      let Result = null;
      
      for (let i = 0; i < p_ArrayOfSets.length; i++) {
          if ( p_ArrayOfSets[i][0] == p_SearchQH ) 
          {
              Result = p_ArrayOfSets[i][1];
              break;
          } // Item was found
      } // all items
      
      return Result;
      
  } // ArrayOfSetsGetPriceByHour
  
  global.set("MESS.Functions.ArrayOfSetsGetPriceByHour", 
                ArrayOfSetsGetPriceByHour);
  
  Trace(Prog_ID, "ArrayOfSetsGetPriceByHour" + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "SortDef_FirstElement_Asc";
  
  const SortDef_FirstElement_Asc = (Set_1, Set_2) =>
  {
      if ( Set_1[0] === Set_2[0] ) 
          return 0
      else if ( Set_1[0] < Set_2[0] )
          return -1 
      else
          return 1
  }

  global.set("MESS.Functions.SortDef_FirstElement_Asc", 
                SortDef_FirstElement_Asc);
  
  Trace(Prog_ID, DebugStep + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "SortDef_ByPrice_Asc";
  
  const SortDef_ByPrice_Asc = (pair_1, pair_2) =>
  {
      // each param a, b contains [ hour, price ]
      // So, argument [0] is hour, argument [1] is price
      if ( ( (pair_1[0] <= 95) && (pair_2[0] <= 95) )
        || ( (pair_1[0] > 95)  && (pair_2[0] > 95)  )
          ) // same day
      {
        if (pair_1[1] < pair_2[1])
          { return -1 }
        else 
          { return 1 }
          
      } 
      else if ( (pair_1[0] <= 95) && (pair_2[0] > 95) )
          { return -1 } 
      else 
          { return 1 } 
      
  } // SortDef_ByPrice_Asc
  
  global.set("MESS.Functions.SortDef_ByPrice_Asc", 
                SortDef_ByPrice_Asc);
  
  Trace(Prog_ID, DebugStep + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "SortDef_ByPrice_Desc";
  
  const SortDef_ByPrice_Desc = (pair_1, pair_2) =>
  {
      // each param a, b contains [ hour, price ]
      // So, argument [0] is hour, argument [1] is price
      if ( ( (pair_1[0] <= 95) && (pair_2[0] <= 95) )
        || ( (pair_1[0] > 95)  && (pair_2[0] > 95)  )
          ) // same day
      {
        if (pair_2[1] < pair_1[1])
        { return -1 }
        else { return 1 }
          
      } 
      else if ( (pair_1[0] <= 95) && (pair_2[0] > 95) )
      { return -1 } 
      else { return 1 } 
      
  } // SortDef_ByPrice_Desc
  
  global.set("MESS.Functions.SortDef_ByPrice_Desc", 
                SortDef_ByPrice_Desc);
  
  Trace(Prog_ID, DebugStep + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  DebugStep = "SortDef_OnlyByPrice_Desc";
  
  const SortDef_OnlyByPrice_Desc = (pair_1, pair_2) =>
  {
      // each param pair_1, pair_2 contains [ hour, price ]
      // So, argument [0] is hour, argument [1] is price
      if (pair_1[1] < pair_2[1])
      { return -1 }
      else
      { return 1 }
  
  } // SortDef_OnlyByPrice_Desc
  
  global.set("MESS.Functions.SortDef_OnlyByPrice_Desc", 
                SortDef_OnlyByPrice_Desc);
  
  Trace(Prog_ID, DebugStep + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "QH_Array_To_Text";
  
  const QH_Array_To_Text = (p_ArrayName, p_Array) => 
  {
      let ResultText = "";
      let lastElement = -2;
      let delimiter = "";
      let NextElement = -2;
  
      if (p_Array && p_Array.length > 0) 
      {
          for (let i = 0; i < p_Array.length; i++) 
          {
              NextElement = -2;
              let curElement;
              
              if (Number.isInteger(p_Array[i])) 
              {
                  curElement = p_Array[i];
                  if (i < p_Array.length - 1) 
                      { NextElement = p_Array[i+1] }
              } 
              else 
              {
                  curElement = p_Array[i][0];
                  if (i < p_Array.length - 1) 
                      { NextElement = p_Array[i+1][0] }
              }
  
              if (curElement == lastElement + 1) 
              {
                  delimiter = "..";
                  lastElement = curElement;
              } 
              else 
              {
                  ResultText += delimiter + QHToText(curElement);
                  delimiter = ', ';
                  lastElement = curElement;
                  continue;
              }
  
              if ( ( curElement != NextElement - 1 )
              ||  ( i == p_Array.length - 1) )
              {
                  ResultText += delimiter + QHToText(curElement);
                  delimiter = ', ';
                  lastElement = curElement;
              }
          }
      }
      return p_ArrayName + ": [" + ResultText + "]";
  }

  global.set("MESS.Functions.QH_Array_To_Text", 
                QH_Array_To_Text);
  
  Trace(Prog_ID, DebugStep + NewLine)

// - - - - - - - - - - - - - - - - - - - - - - - - - 
  
  DebugStep = "Quarter_Remain_Factor";
  
  const Quarter_Remain_Factor = () =>
  {
      const Now = new Date()
      const NowMinutes = Now.getMinutes();
      return (15 - (NowMinutes % 15)) / 15;
  } // Quarter_Remain_Factor
  
  global.set("MESS.Functions.Quarter_Remain_Factor", 
                Quarter_Remain_Factor);
  
  Trace(Prog_ID, "Quarter_Remain_Factor" + NewLine)
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Loaders.Functions";
          
  const LoadFunctions = (targetScope, p_Restart = true) => 
  {
  
    targetScope.NewLine = "\r\n";
  
    const allFuncs = global.get("MESS.Functions");
  
    if (allFuncs) {
      Object.keys(allFuncs).forEach(name =>
      {
        targetScope[name] = allFuncs[name];
      });
      
          let hasRunBefore = false;
          if (targetScope.context 
              && typeof targetScope.context.get === "function") {
              hasRunBefore = !!targetScope.context.get("LoadFunctions");
              targetScope.context.set("LoadFunctions", true);
          }         
      
      
      if ( p_Restart || !hasRunBefore )
      {
          targetScope.Trace(targetScope.Prog_ID, "ClearTrace");
          targetScope.Trace(targetScope.Prog_ID, targetScope.ProgName + NewLine);
          targetScope.Trace(targetScope.Prog_ID, "LoadFunctions \u2714" + NewLine);
      }

      return true;
      
    }
    
    return false;
    
  };
  
  global.set("MESS.Loaders.LoadFunctions", LoadFunctions);
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -        
      
  DebugStep = "Loaders.LoadConstants";
          
  Trace(Prog_ID, NewLine + "Loaders.LoadConstants" + NewLine)
  
  const LoadConstants = (targetScope, p_Restart = true) => 
  {
      // Gebruik de lijst die aan de functie zelf hangt
      const list = LoadConstants.ConstantList;
      
      Object.keys(list).forEach(key => {
          Object.defineProperty(targetScope, key, {
              get: function() { 
                  return list[key]; 
              },
              configurable: true,
              enumerable: true
          });
      });

      let hasRunBefore = false;
      
      if (targetScope.context 
          && typeof targetScope.context.get === "function") 
      {

          hasRunBefore = !!targetScope.context.get("LoadConstants");
      if ( !hasRunBefore )
          {
              firstRunTime = GetNowTime();
              targetScope.context.set("firstRunTime", firstRunTime);
          }
  
          targetScope.context.set("LoadConstants", true);

      if ( p_Restart || !hasRunBefore )
      {
        Trace(targetScope.Prog_ID, "LoadConstants \u2714" + NewLine);
        Trace(targetScope.Prog_ID, "FirstRun:" + NewLine
          + targetScope.context.get("firstRunTime") + NewLine);
        Trace(targetScope.Prog_ID, "NowDateTime:" + NewLine
          + targetScope.NowDateTime + NewLine);
      }
      }        

      return true;
      
  };
  
  // CRUCIAAL: Hang de lijst aan de functie ZODAT de trace erbij kan

  LoadConstants.ConstantList = {
    "NewLine": "\r\n",
      "SigmaChar": "\u2211",
      "DeltaChar": "\u0394",
      "CheckChar": "\u2714",
      "FailChar": "\u2718",
      "QuestionChar": "\u2047",
      "ThereforeChar": "\u2234",
    
    
    get NowDateTime() { return GetNowTime(); },
    get NowTime() { return GetNowTime("UU:MM:SS"); },
    get NowHour() { return GetNowTime("NowHour"); },
    get NowQH() { return GetNowTime("NowQH"); },
    get NowQHAsText() { return QHToText(GetNowTime("NowQH")); },
    get NowMinutes() { return GetNowTime("NowMinutes"); },
    get Yesterday() { return GetYesterday("YYYYMMDD"); },
    get Nowyyyymmdd() { return GetNowTime("yyyymmdd"); },
    get Tomorrowyyyymmdd() { return GetTomorrow("yyyymmdd"); },
    get StartInSeconds() { return GetNowTime("NowInSeconds"); }
  };
  
  global.set("MESS.Loaders.LoadConstants", LoadConstants);

  Object.keys(LoadConstants.ConstantList).forEach(key => 
  {
      Trace(Prog_ID, "  " + key + NewLine);
  });
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Loaders.LoadParams";
          
  Trace(Prog_ID, NewLine + "Loaders.LoadParams" + NewLine)
  
  const LoadParams = (targetScope) => {
      // Gebruik de lijst die aan de functie zelf hangt
      const list = LoadParams.ParamList;
      
      Object.keys(list).forEach(key => {
        // Defines the variables safely and instantly on 'this' without eval()
        Object.defineProperty(targetScope, key, {
          value: list[key],
          writable: true,
          configurable: true,
          enumerable: true
        });
      });

      Trace(targetScope.Prog_ID, "LoadParam \u2714" + NewLine);
      
      return true;
      
  };
  
  LoadParams.ParamList = {
  "Param_Batt_Capacity_Wh": 15360, // (3 x 5.12 x 1000)
  "Param_Batt_Max_Current_A": 100, //(100A ivm bus-bar)
  "Param_Batt_Max_Charge_W": 5100,
  "Param_Batt_Max_Discharge_W": 5200,
  "Param_SoC_Full_Perc": 98,
  "Param_Grid_Setpoint_Limit_W": 10000,
  "Param_Solar_Charge_Perc": 100,
  "Param_Energy_to_Sell_Buffer_Wh": 500,
  "Param_NegativePriceThresholdCt": -0.2,
  "Param_ZeroPriceThresholdCt": 0.1,
  "Param_VeryLowPriceThresholdCt": 2,
  "Param_Sell_Price_Difference_LimitCt": 6,
  "Param_Buy_Price_Difference_LimitCt": 8,
  "Param_kWh_Buy_CostCt": 2.48, // (Tibber 2026: 2.48 / 1.21 = 2.05)
  "Param_kWh_Sell_CostCt": 2.48, // (Tibber 2026: 2.48 / 1.21 = 2.05)
  "Param_kWh_Buy_TaxCt": 9.16, // (2026: 11.08 / 1.21 = 9.16)
  "Param_kWh_Sell_TaxCt": 9.16, // (2026: 11.08 / 1.21 = 9.16)
  // "Param_kWh_Sell_TaxCt": 0, // (2026: 11.08 / 1.21 = 9.16)
  "Param_BTW_Perc": 21,
  // "Param_PV_Modulate_Price_Ct": -11.64,
  // "Param_PV_Turn_Off_Price_Ct": -16,
  "Param_PV_Modulate_Price_Ct": 2.48,
  "Param_PV_Turn_Off_Price_Ct": -2.48,
  "Param_Conversion_Loss_Factor": 0.9,
  "Param_SolarEdge_Production_Limit_W": 6060,
  "Param_Finish_Grid_Charge_Seconds": 300,
  "Param_Max_Allowed_Grid_Amp": 25,
  "Solar_Latitude": 52.01016,
  "Solar_Longitude": 4.43628,
  "Solar_Group": ["East", "South", "West"],
  "Solar_Declination": [50, 30, 50],
  "Solar_Azimuth": [-109, -20, 67],
  "Solar_Power": [6, 3.3, 3.9]
  };
  
  global.set("MESS.Loaders.LoadParams", LoadParams);

  Trace(Prog_ID, "LoadParam \u2714" + NewLine);
  
  Object.keys(LoadParams.ParamList).forEach((key) => 
  {
      let value = LoadParams.ParamList[key];   
      global.set("MESS.Param." + key, value);
      Trace(Prog_ID, "  " + key + ": " + value + NewLine);
  });
  
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Loaders.LoadSection";

  Trace(Prog_ID, NewLine + "Loaders.LoadSection" + NewLine)

  const LoadSection = (targetScope, sectionName) => {
      const sectionData = global.get("MESS." + sectionName) || {};

      Object.keys(sectionData).forEach(key => {
        Object.defineProperty(targetScope, key, {
          value: sectionData[key],
          writable: true,
          configurable: true,
          enumerable: true
        });
      });

      Trace(targetScope.Prog_ID, "LoadSection " + sectionName + " \u2714" + NewLine);

      return true;
  };
  
  // Sla de loader op in de globale context
  global.set("MESS.Loaders.LoadSection", LoadSection);

  Trace(Prog_ID, "Loaders.LoadSection" + NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  Trace(Prog_ID, "Done: " + GetNowTime("uu:mm:ss") +  NewLine)

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  DebugStep = "Finish";
  
  global.set("MESS.Deploy.Loaders_Ready", GetNowTime());

  msg.topic = Prog_ID;
  
  node.status( 
    { fill:"green", 
      shape:"dot",
      text: "@ " + GetNowTime()
    } );

}
catch (error)
{
  node.warn("Error in " + ProgName + ":" + NewLine
  + "Step: " + DebugStep + NewLine
  + "Error: " + error)

  node.status( {
      fill: "red",
      shape: "dot",
      text: error
    });
}

return msg;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
In andere functies worden de functies, parameters en Global-variabelen alsvolgt opgevraagd:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  DebugStep = "Loaders";

  LoadFunctions = global.get("MESS.Loaders.LoadFunctions");
  if (LoadFunctions) LoadFunctions(this);

  LoadConstants = global.get("MESS.Loaders.LoadConstants");
  if (LoadConstants) LoadConstants(this);

  LoadParams = global.get("MESS.Loaders.LoadParams");
  if (LoadParams) LoadParams(this);

  LoadSection = global.get("MESS.Loaders.LoadSection");
  if (LoadSection) LoadSection(this, "Solar")
  if (LoadSection) LoadSection(this, "DayAhead")
  if (LoadSection) LoadSection(this, "SolarEdge")
Omdat de diverse functies na laden worden geactiveerd kan het zijn dat benodigde variabelen in Global nog niet beschikbaar zijn. Daarom volgen na de Loaders controles of de variabelen beschikbaar zijn.

Voorbeelden:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (typeof kWh_Price_Ct === "undefined") 
{
  node.status({
    fill: "red",
    shape: "ring",
    text: "Waiting for kWh_Price_Ct..."
  });

  Trace(Prog_ID, "Waiting for kWh_Price_Ct" + NewLine);

  return null;
}

if (typeof Solar_Forecast_All === "undefined") 
{
  node.status({
    fill: "red",
    shape: "ring",
    text: "Waiting for Solar/Solar_Forecast_All..."
  });
  Trace(Prog_ID, "Waiting for Solar_Forecast_All" + NewLine);

  return null;
}
De via LoadSection opgehaalde gegevens zijn in de functie via hun naam direct als variabele beschikbaar.
Let op: Als een variabele naam in twee Global.MESS secties identiek voorkomt kan dit tot fouten leiden.

[ Voor 106% gewijzigd door MJ de Bruijn op 21-10-2026 11:33 ]

Een mens leert van zijn fouten. Ik heb in mijn leven heel veel geleerd.


  • gys4tweakers
  • Registratie: Juli 2023
  • Laatst online: 23-10 19:17
MJ de Bruijn schreef op dinsdag 20 oktober 2026 @ 12:16:

De via LoadSection opgehaalde gegevens zijn in de functie via hun naam direct als variabele beschikbaar.


Dit is wel een heel interessante.
Klopt het dat de benamingen gewijzigd zijn en dat daarnaast de "get functions" regels in diverse programmeringen vervallen?
Heb jij misschien een overzicht of kun jij dit maken van de diverse benamingen uit "SetGlobalFunctions" en de nieuwe naam in "MakeLoaders"?
Pagina: 1 2 Laatste