-
Notifications
You must be signed in to change notification settings - Fork 0
/
Updated SOC Logic Winter and Summer
658 lines (658 loc) · 20.4 KB
/
Updated SOC Logic Winter and Summer
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
[
{
"id": "9c8d5dd92d377ae7",
"type": "change",
"z": "9170653ac436c1aa",
"name": "",
"rules": [
{
"t": "set",
"p": "soc",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 390,
"y": 60,
"wires": [
[]
]
},
{
"id": "de417502891bb773",
"type": "change",
"z": "9170653ac436c1aa",
"name": "",
"rules": [
{
"t": "set",
"p": "setpoint",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 400,
"y": 20,
"wires": [
[]
]
},
{
"id": "c2b63f42dafb3a2c",
"type": "inject",
"z": "9170653ac436c1aa",
"name": "Battery Maintenance",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "*/1 20-23 * * *",
"once": false,
"onceDelay": "",
"topic": "",
"payload": "payload",
"payloadType": "msg",
"x": 180,
"y": 160,
"wires": [
[
"c451bfe044854b5d",
"3b7c772a6bf98a2f"
]
]
},
{
"id": "8fe1fa924d62aa4c",
"type": "victron-output-ess",
"z": "9170653ac436c1aa",
"service": "com.victronenergy.settings",
"path": "/Settings/CGwacs/AcPowerSetPoint",
"serviceObj": {
"service": "com.victronenergy.settings",
"name": "Venus settings"
},
"pathObj": {
"path": "/Settings/CGwacs/AcPowerSetPoint",
"type": "integer",
"name": "Grid set-point (W)",
"writable": true
},
"initial": "",
"name": "",
"onlyChanges": false,
"x": 540,
"y": 420,
"wires": []
},
{
"id": "2d95a991de2b7e0b",
"type": "victron-output-settings",
"z": "9170653ac436c1aa",
"service": "com.victronenergy.settings",
"path": "/Settings/SystemSetup/MaxChargeCurrent",
"serviceObj": {
"service": "com.victronenergy.settings",
"name": "Venus settings"
},
"pathObj": {
"path": "/Settings/SystemSetup/MaxChargeCurrent",
"type": "float",
"name": "DVCC system max charge current (A DC)",
"writable": true
},
"name": "",
"onlyChanges": false,
"x": 610,
"y": 480,
"wires": []
},
{
"id": "a7b035271bc15404",
"type": "victron-input-battery",
"z": "9170653ac436c1aa",
"service": "com.victronenergy.battery/512",
"path": "/Soc",
"serviceObj": {
"service": "com.victronenergy.battery/512",
"name": "Pylontech battery"
},
"pathObj": {
"path": "/Soc",
"type": "float",
"name": "State of charge (%)"
},
"name": "",
"onlyChanges": true,
"x": 170,
"y": 100,
"wires": [
[
"9c8d5dd92d377ae7"
]
]
},
{
"id": "8e12cbf0a01bb1f8",
"type": "victron-input-ess",
"z": "9170653ac436c1aa",
"service": "com.victronenergy.settings",
"path": "/Settings/CGwacs/AcPowerSetPoint",
"serviceObj": {
"service": "com.victronenergy.settings",
"name": "Venus settings"
},
"pathObj": {
"path": "/Settings/CGwacs/AcPowerSetPoint",
"type": "integer",
"name": "Grid set-point (W)"
},
"name": "",
"onlyChanges": true,
"x": 160,
"y": 40,
"wires": [
[
"de417502891bb773"
]
]
},
{
"id": "2439ebfd5043fba6",
"type": "pushover",
"z": "9170653ac436c1aa",
"name": "",
"device": "",
"title": "Battery Maintenance Discharge Finished",
"priority": "0",
"sound": "falling",
"url": "",
"url_title": "",
"html": false,
"x": 720,
"y": 340,
"wires": []
},
{
"id": "46cdf9e331b954e7",
"type": "pushover",
"z": "9170653ac436c1aa",
"name": "",
"device": "",
"title": "Battery Maintenance Discharge Start Stage 1",
"priority": "0",
"sound": "falling",
"url": "",
"url_title": "",
"html": false,
"x": 890,
"y": 120,
"wires": []
},
{
"id": "4b0f56724399bf55",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-1800",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 100,
"wires": [
[
"9df6deac9419600a"
]
]
},
{
"id": "9df6deac9419600a",
"type": "delay",
"z": "9170653ac436c1aa",
"name": "Delay Message",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "day",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 600,
"y": 160,
"wires": [
[
"46cdf9e331b954e7"
]
]
},
{
"id": "87daf83456aa8845",
"type": "inject",
"z": "9170653ac436c1aa",
"name": "Fail Safe Grid Setpoint",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "29 23 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "-60",
"payloadType": "num",
"x": 170,
"y": 260,
"wires": [
[
"653bd1c7a254f51c",
"ce60512c0589e51f"
]
]
},
{
"id": "a83960f2c22de712",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-6000",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 300,
"wires": [
[
"6919d157fda0296c"
]
]
},
{
"id": "6919d157fda0296c",
"type": "delay",
"z": "9170653ac436c1aa",
"name": "Delay Message",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "day",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 600,
"y": 240,
"wires": [
[
"fa81d688fb1e502f"
]
]
},
{
"id": "fa81d688fb1e502f",
"type": "pushover",
"z": "9170653ac436c1aa",
"name": "",
"device": "",
"title": "Battery Maintenance Discharge Stage 3",
"priority": "0",
"sound": "falling",
"url": "",
"url_title": "",
"html": false,
"x": 880,
"y": 200,
"wires": []
},
{
"id": "ce60512c0589e51f",
"type": "change",
"z": "9170653ac436c1aa",
"name": "Change to Text",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "-1",
"fromt": "num",
"to": "Charge Current set to Max, Battery Maintenance Discharge Finished",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 460,
"y": 380,
"wires": [
[
"2439ebfd5043fba6"
]
]
},
{
"id": "30a90f2191e389e7",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-3000",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 180,
"wires": [
[
"e173c5dd7b432825"
]
]
},
{
"id": "e173c5dd7b432825",
"type": "delay",
"z": "9170653ac436c1aa",
"name": "Delay Message",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "day",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 600,
"y": 200,
"wires": [
[
"9ed99878628094ac"
]
]
},
{
"id": "9ed99878628094ac",
"type": "pushover",
"z": "9170653ac436c1aa",
"name": "",
"device": "",
"title": "Battery Maintenance Discharge Stage 2",
"priority": "0",
"sound": "falling",
"url": "",
"url_title": "",
"html": false,
"x": 880,
"y": 160,
"wires": []
},
{
"id": "14cd096a18e82179",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-6900",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 340,
"wires": [
[
"cd1b83acb7950a01"
]
]
},
{
"id": "cd1b83acb7950a01",
"type": "delay",
"z": "9170653ac436c1aa",
"name": "Delay Message",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "day",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 600,
"y": 280,
"wires": [
[
"a7b6bb0a01e771a0"
]
]
},
{
"id": "a7b6bb0a01e771a0",
"type": "pushover",
"z": "9170653ac436c1aa",
"name": "",
"device": "",
"title": "Battery Maintenance Discharge Stage 4",
"priority": "0",
"sound": "falling",
"url": "",
"url_title": "",
"html": false,
"x": 880,
"y": 240,
"wires": []
},
{
"id": "653bd1c7a254f51c",
"type": "function",
"z": "9170653ac436c1aa",
"name": "Fail Safe",
"func": "// Initialize variables\nvar currentTime = new Date();\nvar currentHour = currentTime.getHours();\nvar currentMinute = currentTime.getMinutes();\nvar output = {};\n\n// Check if the time is 23:29\nif (currentHour === 23 && currentMinute === 29) {\n output.gridsetpoint = -60; // Set gridsetpoint to -60\n output.dvcc = -1; // Set dvcc to -1\n}\n\n// Prepare output messages\nvar messages = [];\nif (output.gridsetpoint !== undefined) {\n messages.push({ payload: output.gridsetpoint, topic: \"gridsetpoint\" });\n}\nif (output.dvcc !== undefined) {\n messages.push({ payload: output.dvcc, topic: \"dvcc\" });\n}\n\n// Return messages or null if empty\nreturn messages.length > 0 ? messages : null;\n",
"outputs": 2,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 220,
"y": 300,
"wires": [
[
"8fe1fa924d62aa4c"
],
[
"2d95a991de2b7e0b"
]
]
},
{
"id": "864180fa9c2b488c",
"type": "inject",
"z": "9170653ac436c1aa",
"name": "Manual -60",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "-60",
"payloadType": "num",
"x": 210,
"y": 360,
"wires": [
[
"8fe1fa924d62aa4c"
]
]
},
{
"id": "9fe2b55ff19b9e9d",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-4500",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 260,
"wires": [
[
"6919d157fda0296c"
]
]
},
{
"id": "9ba2113319eb4d5c",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-2500",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 140,
"wires": [
[
"9df6deac9419600a"
]
]
},
{
"id": "6cfa53ec0b3e51c4",
"type": "switch",
"z": "9170653ac436c1aa",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "-3500",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 1,
"x": 430,
"y": 220,
"wires": [
[
"e173c5dd7b432825"
]
]
},
{
"id": "3b7c772a6bf98a2f",
"type": "function",
"z": "9170653ac436c1aa",
"name": "SOC",
"func": "// Constants for SOC thresholds\nconst SOC_THRESHOLD_60 = 60;\nconst SOC_THRESHOLD_50 = 50;\nconst SOC_THRESHOLD_40 = 40;\nconst SOC_THRESHOLD_37 = 37;\nconst SOC_THRESHOLD_35 = 35;\nconst SOC_THRESHOLD_29 = 29;\nconst SOC_THRESHOLD_45 = 45;\nconst SOC_THRESHOLD_42 = 42;\nconst SOC_THRESHOLD_20 = 20;\n\n// Initialize variables\nvar soc = flow.get(\"soc\"); // State of Charge (SOC)\nvar currentTime = new Date();\nvar currentHour = currentTime.getHours();\nvar currentMinute = currentTime.getMinutes();\nvar output = {};\n\n// Determine if it's summer (April to October) or winter (November to March)\nvar isSummer = (currentTime.getMonth() >= 3 && currentTime.getMonth() <= 9); // April to October\nvar isWinter = (currentTime.getMonth() >= 10 || currentTime.getMonth() <= 2); // Nov to Mar\n\n// Helper function to set output\nfunction setOutput(setpoint) {\n output.gridsetpoint = setpoint;\n}\n\n// Initialize default value\nsetOutput(-60); // Set default to -60 initially\n\n// **Stop processing any logic after 23:27 for both winter and summer**\nif (currentHour === 23 && currentMinute >= 27) {\n return [{ payload: \"No more changes after 23:27\" }]; // End the script early, no more grid setpoint updates\n}\n\n// Winter Logic - Continuous SOC monitoring from 22:30 to 23:19\nif (isWinter) {\n if (currentHour === 22 && currentMinute >= 30) {\n // From 22:30 to 22:34, warming the batteries\n if (currentMinute < 35) {\n setOutput(soc >= SOC_THRESHOLD_60 ? -1800 : (soc >= SOC_THRESHOLD_40 ? -1800 : -60));\n } else {\n // From 22:35 onwards, start at -4500 if SOC is 60% or higher\n if (soc >= SOC_THRESHOLD_60) {\n setOutput(-4500);\n } else if (soc >= SOC_THRESHOLD_50) {\n setOutput(-3000); // Change to -3000 if SOC reaches 50%\n } else if (soc >= SOC_THRESHOLD_40) {\n setOutput(-1800); // Change to -1800 if SOC reaches 40%\n } else if (soc >= SOC_THRESHOLD_37) {\n setOutput(-60); // Change to -60 if SOC reaches 37%\n } else {\n setOutput(-60); // Default -60 if SOC is below 37%\n }\n }\n }\n\n // From 23:00 to 23:19, set gridsetpoint to -6900 if SOC is 37% or higher\n if (currentHour === 23 && currentMinute < 20) {\n if (soc >= SOC_THRESHOLD_37) {\n setOutput(-6900);\n } else if (soc <= SOC_THRESHOLD_29) { // If SOC is 29% or below, set to -60\n setOutput(-60);\n }\n }\n\n // Between 23:20 and 23:27, always reset to -60\n if (currentHour === 23 && currentMinute >= 20 && currentMinute <= 27) {\n setOutput(-60);\n }\n}\n\n// Summer Logic - Continuous SOC monitoring from 20:00 to 23:25\nelse if (isSummer) {\n // From 20:00 to 20:59\n if (currentHour === 20) {\n if (soc >= SOC_THRESHOLD_60) {\n setOutput(-2500); // Set to -2500 if SOC >= 60%\n } else if (soc >= SOC_THRESHOLD_50) {\n setOutput(-1800); // Set to -1800 if SOC >= 50%\n } else if (soc <= SOC_THRESHOLD_40) {\n setOutput(-60); // Set to -60 if SOC <= 40%\n }\n } \n // From 21:00 to 21:59\n else if (currentHour === 21) {\n if (soc >= SOC_THRESHOLD_60) {\n setOutput(-3500); // Set to -3500 if SOC >= 60%\n } else if (soc <= SOC_THRESHOLD_40) {\n setOutput(-60); // Set to -60 if SOC <= 40%\n } else {\n setOutput(-1800); // Set to -1800 if SOC is between 40% and 60%\n }\n } \n // From 22:00 to 22:29\n else if (currentHour === 22 && currentMinute < 30) {\n if (soc >= SOC_THRESHOLD_60) {\n setOutput(-6000); // Set to -6000 if SOC >= 60%\n } else if (soc <= SOC_THRESHOLD_40) {\n setOutput(-60); // Set to -60 if SOC <= 40%\n }\n } \n // From 22:30 to 22:59\n else if (currentHour === 22 && currentMinute >= 30) {\n if (soc >= SOC_THRESHOLD_45) {\n setOutput(-6900); // Set to -6900 if SOC >= 45%\n } else if (soc <= SOC_THRESHOLD_37) {\n setOutput(-60); // Set to -60 if SOC <= 37%\n }\n } \n // From 23:00 to 23:25\n else if (currentHour === 23 && currentMinute <= 25) {\n if (soc >= SOC_THRESHOLD_37) {\n setOutput(-6900); // Set to -6900 if SOC >= 37%\n } else if (soc <= SOC_THRESHOLD_29) { // If SOC is 29% or below, set to -60\n setOutput(-60);\n }\n }\n\n // Between 23:26 and 23:27, always reset to -60\n if (currentHour === 23 && currentMinute >= 26 && currentMinute <= 27) {\n setOutput(-60);\n }\n}\n\n// Prepare output messages\nvar messages = [];\nif (output.gridsetpoint !== undefined && output.gridsetpoint !== -60) {\n messages.push({ payload: output.gridsetpoint });\n}\n\nreturn messages;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 230,
"y": 220,
"wires": [
[
"4b0f56724399bf55",
"9ba2113319eb4d5c",
"30a90f2191e389e7",
"6cfa53ec0b3e51c4",
"9fe2b55ff19b9e9d",
"a83960f2c22de712",
"14cd096a18e82179",
"8fe1fa924d62aa4c"
]
]
}
]