forked from iobroker-community-adapters/ioBroker.fronius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1795 lines (1709 loc) · 58.8 KB
/
main.js
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
/**
*
* ioBroker Fronius inverters Adapter
*
* (c) 2017 ldittmar <[email protected]>
*
* MIT License
*
*/
/* global __dirname */
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";
// you have to require the utils module and call adapter function
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const request = require('request');
const ping = require(__dirname + '/lib/ping');
let ip, baseurl, apiver, requestType;
let isConnected = null;
// you have to call the adapter function and pass a options object
// name has to be set and has to be equal to adapters folder name and main file name excluding extension
// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0
let adapter;
function startAdapter(options) {
options = options || {};
Object.assign(options, {
name: 'fronius',
undload: function (callback) {
// is called when adapter shuts down - callback has to be called under any circumstances!
try {
adapter.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
},
objectChange: function (id, obj) {
// is called if a subscribed object changes
adapter.log.info('objectChange ' + id + ' ' + JSON.stringify(obj));
},
stateChange: function (id, state) {
// is called if a subscribed state changes
// Warning, state can be null if it was deleted
adapter.log.info('stateChange ' + id + ' ' + JSON.stringify(state));
// you can use the ack flag to detect if it is status (true) or command (false)
if (state && !state.ack) {
adapter.log.info('ack is not set!');
}
},
message: function (obj) {
// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ...
let wait = false;
if (obj) {
switch (obj.command) {
case 'checkIP':
checkIP(obj.message, function (res) {
if (obj.callback)
adapter.sendTo(obj.from, obj.command, JSON.stringify(res), obj.callback);
});
wait = true;
break;
case 'getDeviceInfo':
getActiveDeviceInfo("System", obj.message, function (res) {
if (obj.callback)
adapter.sendTo(obj.from, obj.command, JSON.stringify(res), obj.callback);
});
wait = true;
break;
case 'getDeviceInfoInverter':
getActiveDeviceInfo("Inverter", obj.message, function (res) {
if (obj.callback)
adapter.sendTo(obj.from, obj.command, JSON.stringify(res), obj.callback);
});
wait = true;
break;
case 'getDeviceInfoSensor':
getActiveDeviceInfo("SensorCard", obj.message, function (res) {
if (obj.callback)
adapter.sendTo(obj.from, obj.command, JSON.stringify(res), obj.callback);
});
wait = true;
break;
case 'getDeviceInfoString':
getActiveDeviceInfo("StringControl", obj.message, function (res) {
if (obj.callback)
adapter.sendTo(obj.from, obj.command, JSON.stringify(res), obj.callback);
});
wait = true;
break;
default:
adapter.log.warn("Unknown command: " + obj.command);
break;
}
}
if (!wait && obj.callback) {
adapter.sendTo(obj.from, obj.command, obj.message, obj.callback);
}
return true;
},
ready: main
});
adapter = new utils.Adapter(options);
return adapter;
}
//Check if IP is a Fronius inverter
function checkIP(ipToCheck, callback) {
request.get(requestType + ipToCheck + '/solar_api/GetAPIVersion.cgi', function (error, response, body) {
try {
const testData = JSON.parse(body);
if (!error && response.statusCode == 200 && 'BaseURL' in testData) {
callback({error: 0, message: testData});
} else {
adapter.log.error("IP invalid");
callback({error: 1, message: {}});
}
} catch (e) {
adapter.log.error("IP is not a Fronis inverter");
callback({error: 1, message: {}});
}
});
}
//Check Fronius devices v1
function getActiveDeviceInfo(type, url, callback) {
request.get(requestType + url + 'GetActiveDeviceInfo.cgi?DeviceClass=' + type, function (error, response, body) {
try {
const deviceData = JSON.parse(body);
if (!error && response.statusCode == 200 && 'Body' in deviceData) {
callback({error: 0, message: deviceData.Body.Data});
} else {
adapter.log.warn(deviceData.Head.Status.Reason);
callback({error: 1, message: {}});
}
} catch (e) {
callback({error: 1, message: {}});
}
});
}
function createInverterObjects(id) {
adapter.setObjectNotExists('inverter.' + id, {
type: 'channel',
common: {
name: "inverter with device ID " + id,
role: "info"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.DAY_ENERGY', {
type: 'state',
common: {
name: "day energy",
type: "number",
role: "value",
unit: "Wh",
read: true,
write: false,
desc: "Energy generated on current day"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.FAC', {
type: 'state',
common: {
name: "FAC",
type: "number",
role: "value",
unit: "Hz",
read: true,
write: false,
desc: "AC frequency"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.IAC', {
type: "state",
common: {
name: "IAC",
type: "number",
role: "value",
unit: "A",
read: true,
write: false,
desc: "AC current"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.IDC', {
type: "state",
common: {
name: "IDC",
type: "number",
role: "value",
unit: "A",
read: true,
write: false,
desc: "DC current"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.PAC', {
type: "state",
common: {
name: "PAC",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: "AC power"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.TOTAL_ENERGY', {
type: "state",
common: {
name: "total energy",
type: "number",
role: "value",
unit: "Wh",
read: true,
write: false,
desc: "Energy generated overall"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.UAC', {
type: "state",
common: {
name: "UAC",
type: "number",
role: "value",
unit: "V",
read: true,
write: false,
desc: "AC voltage"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.UDC', {
type: "state",
common: {
name: "UDC",
type: "number",
role: "value",
unit: "V",
read: true,
write: false,
desc: "DC voltage"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.YEAR_ENERGY', {
type: "state",
common: {
name: "year energy",
type: "number",
role: "value",
unit: "Wh",
read: true,
write: false,
desc: "Energy generated in current year"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.StatusCode', {
type: "state",
common: {
name: "status code",
type: "number",
role: "value",
read: true,
write: false,
desc: "Status code for the inverter"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.StatusCodeString', {
type: "state",
common: {
name: "status code",
type: "string",
role: "value",
read: true,
write: false,
desc: "Meaning of numerical status codes for the inverter"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.ErrorCode', {
type: "state",
common: {
name: "error code",
type: "number",
role: "value",
read: true,
write: false,
desc: "Error code for the inverter"
},
native: {}
});
adapter.setObjectNotExists('inverter.' + id + '.ErrorCodeString', {
type: "state",
common: {
name: "error code",
type: "string",
role: "value",
read: true,
write: false,
desc: "Meaning of numerical error codes for the inverter"
},
native: {}
});
}
function getStringErrorCode100(errorcode) {
switch (errorcode) {
case 102:
return "AC voltage too high";
case 103:
return "AC voltage too low";
case 105:
return "AC frequency too high";
case 106:
return "AC frequency too low";
case 107:
return "AC grid outside the permissible limits";
case 108:
return "Stand alone operation detected";
default:
return "";
}
}
function getStringErrorCode300(errorcode) {
switch (errorcode) {
case 301:
return "Overcurrent (AC)";
case 302:
return "Overcurrent (DC)";
case 303:
return "DC module over temperature";
case 304:
return "AC module over temperature";
case 305:
return "No power being fed in, despite closed relay";
case 306:
return "PV output too low for feeding energy into the grid";
case 307:
return "LOW PV VOLTAGE! DC input voltage too low for feeding energy into the grid";
case 308:
return "Intermediate circuit voltage too high";
case 309:
return "DC input voltage MPPT 1 too high";
case 311:
return "Polarity of DC strings reversed";
case 313:
return "DC input voltage MPPT 2 too high";
case 314:
return "Current sensor calibration timeout";
case 315:
return "AC current sensor error";
case 316:
return "Interrupt Check fail";
case 325:
return "Overtemperature in the connection area";
case 326:
return "Fan 1 error";
case 327:
return "Fan 2 error";
default:
return "";
}
}
function getStringErrorCode400(errorcode) {
switch (errorcode) {
case 401:
return "No communication possible with the power stage set";
case 406:
return "AC module temperature sensor faulty (L1)";
case 407:
return "AC module temperature sensor faulty (L2)";
case 408:
return "DC component measured in the grid too high";
case 412:
return "Fixed voltage mode has been selected instead of MPP voltage mode and the fixed voltage has been set to too low or too high a value";
case 415:
return "Safety cut out via option card or RECERBO has triggered";
case 416:
return "No communication possible between power stage set and control system";
case 417:
return "Hardware ID problem";
case 419:
return "Unique ID conflict";
case 420:
return "No communication possible with the Hybrid manager";
case 421:
return "HID range error";
case 425:
return "No communication with the power stage set possible";
case 426:
case 427:
case 428:
return "Possible hardware fault";
case 431:
return "Software problem";
case 436:
return "Functional incompatibility (one or more PC boards in the inverter are not compatible with each other, e.g. after a PC board has been replaced.";
case 437:
return "Power stage set problem";
case 438:
return "Functional incompatibility (one or more PC boards in the inverter in the inverter are not compatible with each other, e.g. after a PC board has been replaced)";
case 443:
return "Intermediate circuit voltage too low or asymmetric";
case 445:
return "– Compatability error (e.g. due to replacement of a PC board) – invalid power stage set configuration";
case 447:
return "Insulation fault";
case 448:
return "Neutral conductor not connected";
case 450:
return "Guard cannot be found";
case 451:
return "Memory error detected";
case 452:
return "Communication error between the processors";
case 453:
return "Grid voltage and power stage set are incompatible";
case 454:
return "Grid frequency and power stage set are incompatible";
case 456:
return "Anti-islanding function is no longer implemented correctly";
case 457:
return "Grid relay sticking or the neutral conductor ground voltage is too high";
case 458:
return "Error when recording the measuring signal";
case 459:
return "Error when recording the measuring signal for the insulation test";
case 460:
return "Reference voltage source for the digital signal processor (DSP) is working out of tolerance";
case 461:
return "Fault in the DSP data memory";
case 462:
return "Error with DC feed monitoring routine";
case 463:
return "Reversed AC polarity, AC connector inserted incorrectly";
case 474:
return "RCMU sensor faulty";
case 475:
return "Solar panel ground fault, insulation fault (connection between solar panel and ground)";
case 476:
return "Driver supply voltage too low";
case 480:
case 481:
return "Functional incompatibility (one or more PC boards in the inverter are not compatible with each other, e.g. after a PC board has been replaced)";
case 482:
return "Setup after the initial start-up was interrupted";
case 483:
return "Voltage UDC fixed on MPP2 string out of limits";
case 485:
return "CAN transmit buffer is full";
default:
return "";
}
}
function getStringErrorCode500(errorcode) {
switch (errorcode) {
case 502:
return "Insulation error on the solar panels";
case 509:
return "No energy fed into the grid in the past 24 hours";
case 515:
return "No communication with filter possible";
case 516:
return "No communication possible with the storage unit";
case 517:
return "Power derating caused by too high a temperature";
case 518:
return "Internal DSP malfunction";
case 519:
return "No communication possible with the storage unit";
case 520:
return "No energy fed into the grid by MPPT1 in the past 24 hours";
case 522:
return "DC low string 1";
case 523:
return "DC low string 2";
case 558:
case 559:
return "Functional incompatibility (one or more PC boards in the inverter are not compatible with each other, e.g. after a PC board has been replaced)";
case 560:
return "Derating caused by over-frequency";
case 564:
return "Functional incompatibility (one or more PC boards in the inverter are not compatible with each other, e.g. after a PC board has been replaced)";
case 566:
return "Arc detector switched off (e.g. during external arc monitoring)";
case 567:
return "Grid Voltage Dependent Power Reduction is active";
default:
return "";
}
}
function getStringErrorCode600(errorcode) {
switch (errorcode) {
case 601:
return "CAN bus is full";
case 603:
return "AC module temperature sensor faulty (L3)";
case 604:
return "DC module temperature sensor faulty";
case 607:
return "RCMU error";
case 608:
return "Functional incompatibility (one or more PC boards in the inverter are not compatible with each other, e.g. after a PC board has been replaced)";
default:
return "";
}
}
function getStringErrorCode700(errorcode) {
switch (errorcode) {
case 701:
case 702:
case 703:
case 704:
case 705:
case 706:
case 707:
case 708:
case 709:
case 710:
case 711:
case 712:
case 713:
case 714:
case 715:
case 716:
return "Provides information about the internal processor status";
case 721:
return "EEPROM has been reinitialised";
case 722:
case 723:
case 724:
case 725:
case 726:
case 727:
case 728:
case 729:
case 730:
return "Provides information about the internal processor status";
case 731:
return "Initialisation error – USB flash drive is not supported";
case 732:
return "Initialisation erro – Over current on USB stick";
case 733:
return "No USB flash drive connected";
case 734:
return "Update file not recognised or not present";
case 735:
return "Update file does not match the device, update file too old";
case 736:
return "Write or read error occurred";
case 737:
return "File could not be opened";
case 738:
return "Log file cannot be saved (e.g. USB flash drive is write protected or full)";
case 740:
return "Initialisation error-error in file system on USB flash drive";
case 741:
return "Error during recording of logging data";
case 743:
return "Error occurred during update process";
case 745:
return "Update file corrupt";
case 746:
return "Error occurred during update process";
case 751:
return "Time lost";
case 752:
return "Real Time Clock module communication error";
case 753:
return "Internal error: Real Time Clock module is in emergency mode";
case 754:
case 755:
return "Provides information about the processor status";
case 757:
return "Hardware error in the Real Time Clock module";
case 758:
return "Internal error: Real Time Clock module is in emergency mode";
case 760:
return "Internal hardware error";
case 761:
case 762:
case 763:
case 764:
case 765:
return "Provides information about the internal processor status";
case 766:
return "Emergency power de-rating has been activated";
case 767:
return "Provides information about the internal processor status";
case 768:
return "Different power limitation in the hardware modules";
case 772:
return "Storage unit not available";
case 773:
return "Software update group 0 (invalid country setup)";
case 775:
return "PMC power stage set not available";
case 776:
return "Invalid device type";
case 781:
case 782:
case 783:
case 784:
case 785:
case 786:
case 787:
case 788:
case 789:
case 790:
case 791:
case 792:
case 793:
case 794:
return "Provides information about the internal processor status";
default:
return "";
}
}
//Get Infos from Inverter
function getInverterRealtimeData(id) {
request.get(requestType + ip + baseurl + 'GetInverterRealtimeData.cgi?Scope=Device&DeviceId=' + id + '&DataCollection=CommonInverterData', function (error, response, body) {
if (!error && response.statusCode == 200) {
try {
const data = JSON.parse(body);
if ("Body" in data) {
createInverterObjects(id);
const resp = data.Body.Data;
adapter.setState("inverter." + id + ".DAY_ENERGY", {val: resp.DAY_ENERGY.Value, ack: true});
adapter.setState("inverter." + id + ".TOTAL_ENERGY", {val: resp.TOTAL_ENERGY.Value, ack: true});
adapter.setState("inverter." + id + ".YEAR_ENERGY", {val: resp.YEAR_ENERGY.Value, ack: true});
if ("PAC" in resp) {
adapter.setState("inverter." + id + ".FAC", {val: resp.FAC.Value, ack: true});
adapter.setState("inverter." + id + ".IAC", {val: resp.IAC.Value, ack: true});
adapter.setState("inverter." + id + ".IDC", {val: resp.IDC.Value, ack: true});
adapter.setState("inverter." + id + ".PAC", {val: resp.PAC.Value, ack: true});
adapter.setState("inverter." + id + ".UAC", {val: resp.UAC.Value, ack: true});
adapter.setState("inverter." + id + ".UDC", {val: resp.UDC.Value, ack: true});
} else {
adapter.setState("inverter." + id + ".FAC", {val: 0, ack: true});
adapter.setState("inverter." + id + ".IAC", {val: 0, ack: true});
adapter.setState("inverter." + id + ".IDC", {val: 0, ack: true});
adapter.setState("inverter." + id + ".PAC", {val: 0, ack: true});
adapter.setState("inverter." + id + ".UAC", {val: 0, ack: true});
adapter.setState("inverter." + id + ".UDC", {val: 0, ack: true});
}
const status = resp.DeviceStatus;
let statusCode = parseInt(status.StatusCode);
adapter.setState("inverter." + id + ".StatusCode", {val: statusCode, ack: true});
let statusCodeString = "Startup";
if (statusCode === 7) {
statusCodeString = "Running";
} else if (statusCode === 8) {
statusCodeString = "Standby";
} else if (statusCode === 9) {
statusCodeString = "Bootloading";
} else if (statusCode === 10) {
statusCodeString = "Error";
}
adapter.setState("inverter." + id + ".StatusCodeString", {val: statusCodeString, ack: true});
statusCode = parseInt(status.ErrorCode);
adapter.setState("inverter." + id + ".ErrorCode", {val: statusCode, ack: true});
if (statusCode >= 700) {
statusCodeString = getStringErrorCode700(statusCode);
} else if (statusCode >= 600) {
statusCodeString = getStringErrorCode600(statusCode);
} else if (statusCode >= 500) {
statusCodeString = getStringErrorCode500(statusCode);
} else if (statusCode >= 400) {
statusCodeString = getStringErrorCode400(statusCode);
} else if (statusCode >= 300) {
statusCodeString = getStringErrorCode300(statusCode);
} else {
statusCodeString = getStringErrorCode100(statusCode);
}
adapter.setState("inverter." + id + ".ErrorCodeString", {val: statusCodeString, ack: true});
} else {
adapter.log.warn(data.Head.Status.Reason + " inverter: " + id);
}
} catch (e) {
adapter.log.warn(e);
}
}
});
}
function createStorageObjects(id) {
adapter.setObjectNotExists('storage', {
type: 'channel',
common: {
name: "detailed information about Storage devices",
role: "info"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id, {
type: 'channel',
common: {
name: "storage with device ID " + id,
role: "info"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller', {
type: 'channel',
common: {
name: "controller",
role: "info"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Model', {
type: "state",
common: {
name: "ManufacturerModel Controller",
type: "string",
role: "value",
read: true,
write: false,
desc: "Manufacturer & Model from controller"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Enable', {
type: "state",
common: {
name: "enable",
type: "boolean",
role: "value",
read: true,
write: false,
desc: "controller enabled"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.StateOfCharge_Relative', {
type: "state",
common: {
name: "State of charge",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: "Realative state of charge"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Voltage_DC', {
type: "state",
common: {
name: "Voltage DC",
type: "number",
role: "value",
unit: "V",
read: true,
write: false,
desc: "Voltage DC"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Current_DC', {
type: "state",
common: {
name: "Current DC",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: "Current DC"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Temperature_Cell', {
type: "state",
common: {
name: "Cell temperature",
type: "number",
role: "value",
unit: "°C",
read: true,
write: false,
desc: "Cell temperature"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Voltage_DC_Maximum_Cell', {
type: "state",
common: {
name: "Voltage DC Maximum Cell",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: "Voltage DC Maximum Cell"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.Voltage_DC_Minimum_Cell', {
type: "state",
common: {
name: "Voltage DC Minimum Cell",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: "Voltage DC Minimum Cell"
},
native: {}
});
adapter.setObjectNotExists('storage.' + id + '.controller.DesignedCapacity', {
type: "state",
common: {
name: "Designed capacity",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: "Designed capacity"
},
native: {}
});
}
function getStorageRealtimeData(id) {
request.get(requestType + ip + baseurl + 'GetStorageRealtimeData.cgi?Scope=Device&DeviceId=' + id, function (error, response, body) {
if (!error && response.statusCode == 200) {
try {
const data = JSON.parse(body);
if ("Body" in data) {
createStorageObjects(id);
const resp = data.Body.Data.Controller;
adapter.setState("storage." + id + ".controller.Model", {val: resp.Details.Manufacturer + ' ' + resp.Details.Model, ack: true});
adapter.setState("storage." + id + ".controller.Enable", {val: resp.Enable === '1', ack: true});
adapter.setState("storage." + id + ".controller.StateOfCharge_Relative", {val: resp.StateOfCharge_Relative, ack: true});
adapter.setState("storage." + id + ".controller.Voltage_DC", {val: resp.Voltage_DC, ack: true});
adapter.setState("storage." + id + ".controller.Current_DC", {val: resp.Current_DC, ack: true});
adapter.setState("storage." + id + ".controller.Temperature_Cell", {val: resp.Temperature_Cell, ack: true});
adapter.setState("storage." + id + ".controller.Voltage_DC_Maximum_Cell", {val: resp.Voltage_DC_Maximum_Cell, ack: true});
adapter.setState("storage." + id + ".controller.Voltage_DC_Minimum_Cell", {val: resp.Voltage_DC_Minimum_Cell, ack: true});
adapter.setState("storage." + id + ".controller.DesignedCapacity", {val: resp.DesignedCapacity, ack: true});
} else {
adapter.log.warn(data.Head.Status.Reason + " storage: " + id);
}
} catch (e) {
adapter.log.warn(e);
}
}
});
}
function createMeterObjects(id) {
adapter.setObjectNotExists('meter', {
type: 'channel',
common: {
name: "detailed information about Meter devices",
role: "info"
},
native: {}
});
adapter.setObjectNotExists('meter.' + id, {
type: 'channel',
common: {
name: "meter with device ID " + id,
role: "info"
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.Model', {
type: "state",
common: {
name: "ManufacturerModel",
type: "string",
role: "value",
read: true,
write: false,
desc: "Manufacturer & Model"
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReal_P_Sum', {
type: "state",
common: {
name: "current power",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: "current total power"
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReal_P_Phase_1', {
type: "state",
common: {
name: "PowerReal_P_Phase_1",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: ""
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReal_P_Phase_2', {
type: "state",
common: {
name: "PowerReal_P_Phase_2",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: ""
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReal_P_Phase_3', {
type: "state",
common: {
name: "PowerReal_P_Phase_3",
type: "number",
role: "value",
unit: "W",
read: true,
write: false,
desc: ""
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReactive_Q_Sum', {
type: "state",
common: {
name: "PowerReactive_Q_Sum",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: ""
},
native: {}
});
adapter.setObjectNotExists('meter.' + id + '.PowerReactive_Q_Phase_1', {
type: "state",
common: {
name: "PowerReactive_Q_Phase_1",
type: "number",
role: "value",
unit: "?",
read: true,
write: false,
desc: ""
},