@enyo-energy/sunspec-sdk 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -348,6 +348,16 @@ class SunspecBattery extends BaseSunspecDevice {
348
348
  const mpptBatteryPowerW = this.extractBatteryPowerFromMPPT(mpptDataList);
349
349
  if (batteryData) {
350
350
  const advancedBatteryModel = this.sunspecClient.findModel(801);
351
+ const batteryBaseModel = this.sunspecClient.findModel(sunspec_interfaces_js_1.SunspecModelId.BatteryBase);
352
+ // Determine battery power: prefer model 802 w field, then MPPT extraction, then undefined
353
+ let batteryPowerW;
354
+ if (batteryBaseModel && (batteryData.chargePower !== undefined || batteryData.dischargePower !== undefined)) {
355
+ // Model 802 provides power directly: positive = charge, negative = discharge
356
+ batteryPowerW = (batteryData.chargePower || 0) - (batteryData.dischargePower || 0);
357
+ }
358
+ else if (!advancedBatteryModel) {
359
+ batteryPowerW = mpptBatteryPowerW;
360
+ }
351
361
  const batteryMessage = {
352
362
  id: (0, node_crypto_1.randomUUID)(),
353
363
  message: enyo_data_bus_value_js_1.EnyoDataBusMessageEnum.BatteryValuesUpdateV1,
@@ -359,7 +369,7 @@ class SunspecBattery extends BaseSunspecDevice {
359
369
  resolution,
360
370
  data: {
361
371
  batterySoC: batteryData.soc || batteryData.chaState || 0,
362
- batteryPowerW: advancedBatteryModel ? undefined : mpptBatteryPowerW,
372
+ batteryPowerW,
363
373
  state: this.mapToEnyoBatteryState(batteryData.chaSt),
364
374
  }
365
375
  };
@@ -499,6 +509,21 @@ class SunspecBattery extends BaseSunspecDevice {
499
509
  }
500
510
  return this.sunspecClient.readBatteryControls();
501
511
  }
512
+ /**
513
+ * Read full battery base data from Model 802
514
+ *
515
+ * Returns the complete Model 802 data structure with all fields,
516
+ * including nameplate, SoC/health, status, events, voltage, current, and power.
517
+ *
518
+ * @returns Promise<SunspecBatteryBaseData | null> - Full model 802 data or null if not available
519
+ */
520
+ async readBatteryBaseData() {
521
+ if (!this.isConnected()) {
522
+ console.error('Battery not connected');
523
+ return null;
524
+ }
525
+ return this.sunspecClient.readBatteryBaseData();
526
+ }
502
527
  /**
503
528
  * Write custom battery control settings
504
529
  *
@@ -1,4 +1,4 @@
1
- import { type SunspecBatteryControls, SunspecStorageMode } from "./sunspec-interfaces.cjs";
1
+ import { type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode } from "./sunspec-interfaces.cjs";
2
2
  import { ApplianceManager, EnergyApp } from "@enyo-energy/energy-app-sdk";
3
3
  import { EnyoApplianceName } from "@enyo-energy/energy-app-sdk/dist/types/enyo-appliance.js";
4
4
  import { EnyoNetworkDevice } from "@enyo-energy/energy-app-sdk/dist/types/enyo-network-device.js";
@@ -130,6 +130,15 @@ export declare class SunspecBattery extends BaseSunspecDevice {
130
130
  * @returns Promise<SunspecBatteryControls | null> - Current control settings or null if error
131
131
  */
132
132
  getBatteryControls(): Promise<SunspecBatteryControls | null>;
133
+ /**
134
+ * Read full battery base data from Model 802
135
+ *
136
+ * Returns the complete Model 802 data structure with all fields,
137
+ * including nameplate, SoC/health, status, events, voltage, current, and power.
138
+ *
139
+ * @returns Promise<SunspecBatteryBaseData | null> - Full model 802 data or null if not available
140
+ */
141
+ readBatteryBaseData(): Promise<SunspecBatteryBaseData | null>;
133
142
  /**
134
143
  * Write custom battery control settings
135
144
  *
@@ -3,7 +3,7 @@
3
3
  * SunSpec block interfaces with block numbers
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SunspecStorageMode = exports.SunspecChargeSource = exports.SunspecVArPctMode = exports.SunspecEnableControl = exports.SunspecConnectionControl = exports.SunspecStorageControlMode = exports.SunspecBatteryChargeState = exports.SunspecMPPTOperatingState = exports.SunspecModelId = exports.DEFAULT_RETRY_CONFIG = void 0;
6
+ exports.SunspecStorageMode = exports.SunspecChargeSource = exports.SunspecVArPctMode = exports.SunspecEnableControl = exports.SunspecConnectionControl = exports.SunspecStorageControlMode = exports.SunspecBatteryEvent1 = exports.SunspecBatteryBankState = exports.SunspecBatteryType = exports.SunspecBatteryControlMode = exports.SunspecBatteryChargeState = exports.SunspecMPPTOperatingState = exports.SunspecModelId = exports.DEFAULT_RETRY_CONFIG = void 0;
7
7
  exports.DEFAULT_RETRY_CONFIG = {
8
8
  initialDelayMs: 1000,
9
9
  maxDelayMs: 30000,
@@ -61,6 +61,87 @@ var SunspecBatteryChargeState;
61
61
  SunspecBatteryChargeState[SunspecBatteryChargeState["HOLDING"] = 6] = "HOLDING";
62
62
  SunspecBatteryChargeState[SunspecBatteryChargeState["TESTING"] = 7] = "TESTING";
63
63
  })(SunspecBatteryChargeState || (exports.SunspecBatteryChargeState = SunspecBatteryChargeState = {}));
64
+ /**
65
+ * Battery Control Mode values for Model 802
66
+ * Offset 17: LocRemCtl - Local/Remote control mode
67
+ */
68
+ var SunspecBatteryControlMode;
69
+ (function (SunspecBatteryControlMode) {
70
+ SunspecBatteryControlMode[SunspecBatteryControlMode["REMOTE"] = 0] = "REMOTE";
71
+ SunspecBatteryControlMode[SunspecBatteryControlMode["LOCAL"] = 1] = "LOCAL";
72
+ })(SunspecBatteryControlMode || (exports.SunspecBatteryControlMode = SunspecBatteryControlMode = {}));
73
+ /**
74
+ * Battery Type values for Model 802
75
+ * Offset 21: Typ - Battery type
76
+ */
77
+ var SunspecBatteryType;
78
+ (function (SunspecBatteryType) {
79
+ SunspecBatteryType[SunspecBatteryType["NOT_APPLICABLE_UNKNOWN"] = 0] = "NOT_APPLICABLE_UNKNOWN";
80
+ SunspecBatteryType[SunspecBatteryType["LEAD_ACID"] = 1] = "LEAD_ACID";
81
+ SunspecBatteryType[SunspecBatteryType["NICKEL_METAL_HYDRIDE"] = 2] = "NICKEL_METAL_HYDRIDE";
82
+ SunspecBatteryType[SunspecBatteryType["NICKEL_CADMIUM"] = 3] = "NICKEL_CADMIUM";
83
+ SunspecBatteryType[SunspecBatteryType["LITHIUM_ION"] = 4] = "LITHIUM_ION";
84
+ SunspecBatteryType[SunspecBatteryType["CARBON_ZINC"] = 5] = "CARBON_ZINC";
85
+ SunspecBatteryType[SunspecBatteryType["ZINC_CHLORIDE"] = 6] = "ZINC_CHLORIDE";
86
+ SunspecBatteryType[SunspecBatteryType["ALKALINE"] = 7] = "ALKALINE";
87
+ SunspecBatteryType[SunspecBatteryType["RECHARGEABLE_ALKALINE"] = 8] = "RECHARGEABLE_ALKALINE";
88
+ SunspecBatteryType[SunspecBatteryType["SODIUM_SULFUR"] = 9] = "SODIUM_SULFUR";
89
+ SunspecBatteryType[SunspecBatteryType["FLOW"] = 10] = "FLOW";
90
+ SunspecBatteryType[SunspecBatteryType["SUPER_CAPACITOR"] = 11] = "SUPER_CAPACITOR";
91
+ SunspecBatteryType[SunspecBatteryType["OTHER"] = 99] = "OTHER";
92
+ })(SunspecBatteryType || (exports.SunspecBatteryType = SunspecBatteryType = {}));
93
+ /**
94
+ * Battery Bank State values for Model 802
95
+ * Offset 22: State - Battery bank state
96
+ */
97
+ var SunspecBatteryBankState;
98
+ (function (SunspecBatteryBankState) {
99
+ SunspecBatteryBankState[SunspecBatteryBankState["DISCONNECTED"] = 1] = "DISCONNECTED";
100
+ SunspecBatteryBankState[SunspecBatteryBankState["INITIALIZING"] = 2] = "INITIALIZING";
101
+ SunspecBatteryBankState[SunspecBatteryBankState["CONNECTED"] = 3] = "CONNECTED";
102
+ SunspecBatteryBankState[SunspecBatteryBankState["STANDBY"] = 4] = "STANDBY";
103
+ SunspecBatteryBankState[SunspecBatteryBankState["SOC_PROTECTION"] = 5] = "SOC_PROTECTION";
104
+ SunspecBatteryBankState[SunspecBatteryBankState["SUSPENDING"] = 6] = "SUSPENDING";
105
+ SunspecBatteryBankState[SunspecBatteryBankState["FAULT"] = 99] = "FAULT";
106
+ })(SunspecBatteryBankState || (exports.SunspecBatteryBankState = SunspecBatteryBankState = {}));
107
+ /**
108
+ * Battery Event 1 bit positions for Model 802
109
+ * Offset 26-27: Evt1 - Battery event bitfield
110
+ */
111
+ var SunspecBatteryEvent1;
112
+ (function (SunspecBatteryEvent1) {
113
+ SunspecBatteryEvent1[SunspecBatteryEvent1["COMMUNICATION_ERROR"] = 0] = "COMMUNICATION_ERROR";
114
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_TEMP_ALARM"] = 1] = "OVER_TEMP_ALARM";
115
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_TEMP_WARNING"] = 2] = "OVER_TEMP_WARNING";
116
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_TEMP_ALARM"] = 3] = "UNDER_TEMP_ALARM";
117
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_TEMP_WARNING"] = 4] = "UNDER_TEMP_WARNING";
118
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_CHARGE_CURRENT_ALARM"] = 5] = "OVER_CHARGE_CURRENT_ALARM";
119
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_CHARGE_CURRENT_WARNING"] = 6] = "OVER_CHARGE_CURRENT_WARNING";
120
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_DISCHARGE_CURRENT_ALARM"] = 7] = "OVER_DISCHARGE_CURRENT_ALARM";
121
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_DISCHARGE_CURRENT_WARNING"] = 8] = "OVER_DISCHARGE_CURRENT_WARNING";
122
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_VOLT_ALARM"] = 9] = "OVER_VOLT_ALARM";
123
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_VOLT_WARNING"] = 10] = "OVER_VOLT_WARNING";
124
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_VOLT_ALARM"] = 11] = "UNDER_VOLT_ALARM";
125
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_VOLT_WARNING"] = 12] = "UNDER_VOLT_WARNING";
126
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_SOC_MIN_ALARM"] = 13] = "UNDER_SOC_MIN_ALARM";
127
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_SOC_MIN_WARNING"] = 14] = "UNDER_SOC_MIN_WARNING";
128
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_SOC_MAX_ALARM"] = 15] = "OVER_SOC_MAX_ALARM";
129
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_SOC_MAX_WARNING"] = 16] = "OVER_SOC_MAX_WARNING";
130
+ SunspecBatteryEvent1[SunspecBatteryEvent1["VOLTAGE_IMBALANCE_WARNING"] = 17] = "VOLTAGE_IMBALANCE_WARNING";
131
+ SunspecBatteryEvent1[SunspecBatteryEvent1["TEMPERATURE_IMBALANCE_ALARM"] = 18] = "TEMPERATURE_IMBALANCE_ALARM";
132
+ SunspecBatteryEvent1[SunspecBatteryEvent1["TEMPERATURE_IMBALANCE_WARNING"] = 19] = "TEMPERATURE_IMBALANCE_WARNING";
133
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONTACTOR_ERROR"] = 20] = "CONTACTOR_ERROR";
134
+ SunspecBatteryEvent1[SunspecBatteryEvent1["FAN_ERROR"] = 21] = "FAN_ERROR";
135
+ SunspecBatteryEvent1[SunspecBatteryEvent1["FUSE_ERROR"] = 22] = "FUSE_ERROR";
136
+ SunspecBatteryEvent1[SunspecBatteryEvent1["GROUND_FAULT"] = 23] = "GROUND_FAULT";
137
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OPEN_DOOR_ERROR"] = 24] = "OPEN_DOOR_ERROR";
138
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CURRENT_IMBALANCE_WARNING"] = 25] = "CURRENT_IMBALANCE_WARNING";
139
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OTHER_ALARM"] = 26] = "OTHER_ALARM";
140
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OTHER_WARNING"] = 27] = "OTHER_WARNING";
141
+ SunspecBatteryEvent1[SunspecBatteryEvent1["RESERVED_1"] = 28] = "RESERVED_1";
142
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONFIGURATION_ALARM"] = 29] = "CONFIGURATION_ALARM";
143
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONFIGURATION_WARNING"] = 30] = "CONFIGURATION_WARNING";
144
+ })(SunspecBatteryEvent1 || (exports.SunspecBatteryEvent1 = SunspecBatteryEvent1 = {}));
64
145
  /**
65
146
  * Storage Control Mode bitfield values for Model 124
66
147
  *
@@ -178,6 +178,83 @@ export declare enum SunspecBatteryChargeState {
178
178
  HOLDING = 6,
179
179
  TESTING = 7
180
180
  }
181
+ /**
182
+ * Battery Control Mode values for Model 802
183
+ * Offset 17: LocRemCtl - Local/Remote control mode
184
+ */
185
+ export declare enum SunspecBatteryControlMode {
186
+ REMOTE = 0,
187
+ LOCAL = 1
188
+ }
189
+ /**
190
+ * Battery Type values for Model 802
191
+ * Offset 21: Typ - Battery type
192
+ */
193
+ export declare enum SunspecBatteryType {
194
+ NOT_APPLICABLE_UNKNOWN = 0,
195
+ LEAD_ACID = 1,
196
+ NICKEL_METAL_HYDRIDE = 2,
197
+ NICKEL_CADMIUM = 3,
198
+ LITHIUM_ION = 4,
199
+ CARBON_ZINC = 5,
200
+ ZINC_CHLORIDE = 6,
201
+ ALKALINE = 7,
202
+ RECHARGEABLE_ALKALINE = 8,
203
+ SODIUM_SULFUR = 9,
204
+ FLOW = 10,
205
+ SUPER_CAPACITOR = 11,
206
+ OTHER = 99
207
+ }
208
+ /**
209
+ * Battery Bank State values for Model 802
210
+ * Offset 22: State - Battery bank state
211
+ */
212
+ export declare enum SunspecBatteryBankState {
213
+ DISCONNECTED = 1,
214
+ INITIALIZING = 2,
215
+ CONNECTED = 3,
216
+ STANDBY = 4,
217
+ SOC_PROTECTION = 5,
218
+ SUSPENDING = 6,
219
+ FAULT = 99
220
+ }
221
+ /**
222
+ * Battery Event 1 bit positions for Model 802
223
+ * Offset 26-27: Evt1 - Battery event bitfield
224
+ */
225
+ export declare enum SunspecBatteryEvent1 {
226
+ COMMUNICATION_ERROR = 0,
227
+ OVER_TEMP_ALARM = 1,
228
+ OVER_TEMP_WARNING = 2,
229
+ UNDER_TEMP_ALARM = 3,
230
+ UNDER_TEMP_WARNING = 4,
231
+ OVER_CHARGE_CURRENT_ALARM = 5,
232
+ OVER_CHARGE_CURRENT_WARNING = 6,
233
+ OVER_DISCHARGE_CURRENT_ALARM = 7,
234
+ OVER_DISCHARGE_CURRENT_WARNING = 8,
235
+ OVER_VOLT_ALARM = 9,
236
+ OVER_VOLT_WARNING = 10,
237
+ UNDER_VOLT_ALARM = 11,
238
+ UNDER_VOLT_WARNING = 12,
239
+ UNDER_SOC_MIN_ALARM = 13,
240
+ UNDER_SOC_MIN_WARNING = 14,
241
+ OVER_SOC_MAX_ALARM = 15,
242
+ OVER_SOC_MAX_WARNING = 16,
243
+ VOLTAGE_IMBALANCE_WARNING = 17,
244
+ TEMPERATURE_IMBALANCE_ALARM = 18,
245
+ TEMPERATURE_IMBALANCE_WARNING = 19,
246
+ CONTACTOR_ERROR = 20,
247
+ FAN_ERROR = 21,
248
+ FUSE_ERROR = 22,
249
+ GROUND_FAULT = 23,
250
+ OPEN_DOOR_ERROR = 24,
251
+ CURRENT_IMBALANCE_WARNING = 25,
252
+ OTHER_ALARM = 26,
253
+ OTHER_WARNING = 27,
254
+ RESERVED_1 = 28,
255
+ CONFIGURATION_ALARM = 29,
256
+ CONFIGURATION_WARNING = 30
257
+ }
181
258
  /**
182
259
  * Storage Control Mode bitfield values for Model 124
183
260
  *
@@ -247,6 +324,102 @@ export interface SunspecBatteryData extends SunspecBlock {
247
324
  temperature?: number;
248
325
  status?: number;
249
326
  }
327
+ /**
328
+ * Battery Base data structure based on Model 802 (Battery Base Model)
329
+ *
330
+ * SunSpec Model 802 Register Map (offsets relative to model start):
331
+ * - 0-1: ID and Length
332
+ * - 2: AHRtg - Nameplate charge capacity (AH) (uint16)
333
+ * - 3: WHRtg - Nameplate energy capacity (WH) (uint16)
334
+ * - 4: WChaRteMax - Maximum rate of charge (W) (uint16)
335
+ * - 5: WDisChaRteMax - Maximum rate of discharge (W) (uint16)
336
+ * - 6: DisChaRte - Self discharge rate (%) (uint16)
337
+ * - 7: SoCMax - Maximum state of charge (%) (uint16)
338
+ * - 8: SoCMin - Minimum state of charge (%) (uint16)
339
+ * - 9: SoCRsvMax - Maximum reserve SOC (%) (uint16)
340
+ * - 10: SoCRsvMin - Minimum reserve SOC (%) (uint16)
341
+ * - 11: SoC - State of charge (%) (uint16)
342
+ * - 12: DoD - Depth of discharge (%) (uint16)
343
+ * - 13: SoH - State of health (%) (uint16)
344
+ * - 14-15: NCyc - Cycle count (uint32)
345
+ * - 16: ChaSt - Charge status (enum16)
346
+ * - 17: LocRemCtl - Local/Remote control (enum16)
347
+ * - 18: Hb - Heartbeat (uint16)
348
+ * - 19: CtrlHb - Controller heartbeat (uint16)
349
+ * - 20: AlmRst - Alarm reset (uint16)
350
+ * - 21: Typ - Battery type (enum16)
351
+ * - 22: State - Battery bank state (enum16)
352
+ * - 23: StateVnd - Vendor-specific state (enum16)
353
+ * - 24-25: WarrDt - Warranty date (uint32)
354
+ * - 26-27: Evt1 - Event bitfield 1 (bitfield32)
355
+ * - 28-29: Evt2 - Event bitfield 2 (bitfield32)
356
+ * - 30-31: EvtVnd1 - Vendor event bitfield 1 (bitfield32)
357
+ * - 32-33: EvtVnd2 - Vendor event bitfield 2 (bitfield32)
358
+ * - 34: V - Battery voltage (V) (uint16)
359
+ * - 35: VMax - Maximum battery voltage (V) (uint16)
360
+ * - 36: VMin - Minimum battery voltage (V) (uint16)
361
+ * - 37: CellVMax - Maximum cell voltage (V) (uint16)
362
+ * - 38: CellVMaxStr - String containing max cell voltage (uint16)
363
+ * - 39: CellVMaxMod - Module containing max cell voltage (uint16)
364
+ * - 40: CellVMin - Minimum cell voltage (V) (uint16)
365
+ * - 41: CellVMinStr - String containing min cell voltage (uint16)
366
+ * - 42: CellVMinMod - Module containing min cell voltage (uint16)
367
+ * - 43: CellVAvg - Average cell voltage (V) (uint16)
368
+ * - 44: A - Battery current (A) (int16)
369
+ * - 45: AChaMax - Maximum charge current (A) (uint16)
370
+ * - 46: ADisChaMax - Maximum discharge current (A) (uint16)
371
+ * - 47: W - Battery power (W) (int16)
372
+ * - 48: ReqInvState - Requested inverter state (enum16)
373
+ * - 49: ReqW - Requested power (W) (int16)
374
+ * - 50: SetOp - Set operation (enum16)
375
+ * - 51: SetInvState - Set inverter state (enum16)
376
+ * Scale factors at offsets 52-63
377
+ */
378
+ export interface SunspecBatteryBaseData extends SunspecBlock {
379
+ blockNumber: 802;
380
+ ahRtg?: number;
381
+ whRtg?: number;
382
+ wChaRteMax?: number;
383
+ wDisChaRteMax?: number;
384
+ disChaRte?: number;
385
+ soCMax?: number;
386
+ soCMin?: number;
387
+ soCRsvMax?: number;
388
+ soCRsvMin?: number;
389
+ soC?: number;
390
+ doD?: number;
391
+ soH?: number;
392
+ nCyc?: number;
393
+ chaSt?: number;
394
+ chaStName?: string;
395
+ locRemCtl?: number;
396
+ typ?: number;
397
+ typName?: string;
398
+ state?: number;
399
+ stateName?: string;
400
+ evt1?: number;
401
+ evt2?: number;
402
+ evtVnd1?: number;
403
+ evtVnd2?: number;
404
+ v?: number;
405
+ vMax?: number;
406
+ vMin?: number;
407
+ cellVMax?: number;
408
+ cellVMaxStr?: number;
409
+ cellVMaxMod?: number;
410
+ cellVMin?: number;
411
+ cellVMinStr?: number;
412
+ cellVMinMod?: number;
413
+ cellVAvg?: number;
414
+ a?: number;
415
+ aChaMax?: number;
416
+ aDisChaMax?: number;
417
+ w?: number;
418
+ reqInvState?: number;
419
+ reqW?: number;
420
+ setOp?: number;
421
+ setInvState?: number;
422
+ }
250
423
  /**
251
424
  * Meter data structure
252
425
  */