Skip to content

Commit

Permalink
Make all per phase measurements nullable on phase A
Browse files Browse the repository at this point in the history
  • Loading branch information
longzheng committed Nov 18, 2024
1 parent db3f006 commit 692a0aa
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 101 deletions.
16 changes: 8 additions & 8 deletions src/connections/modbus/models/sma/core1/gridMs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type SmaCore1GridMs1 = {
// Power
TotW: number;
// Power L1
W_phsA: number;
W_phsA: number | null;
// Power L2
W_phsB: number | null;
// Power L3
W_phsC: number | null;
// Grid voltage phase L1
PhV_phsA: number;
PhV_phsA: number | null;
// Grid voltage phase L2
PhV_phsB: number | null;
// Grid voltage phase L3
Expand All @@ -42,15 +42,15 @@ type SmaCore1GridMs2 = {

type SmaCore1GridMs3 = {
// Reactive power L1
VAr_phsA: number;
VAr_phsA: number | null;
// Reactive power L2
VAr_phsB: number | null;
// Reactive power L3
VAr_phsC: number | null;
// Apparent power
TotVA: number;
// Apparent power L1
VA_phsA: number;
VA_phsA: number | null;
// Apparent power L2
VA_phsB: number | null;
// Apparent power L3
Expand All @@ -68,7 +68,7 @@ export const SmaCore1GridMs1Model = modbusModelFactory<SmaCore1GridMs1>({
W_phsA: {
start: 2,
end: 4,
readConverter: registersToInt32,
readConverter: registersToInt32Nullable,
},
W_phsB: {
start: 4,
Expand All @@ -83,7 +83,7 @@ export const SmaCore1GridMs1Model = modbusModelFactory<SmaCore1GridMs1>({
PhV_phsA: {
start: 8,
end: 10,
readConverter: (value) => registersToUint32(value, -2),
readConverter: (value) => registersToUint32Nullable(value, -2),
},
PhV_phsB: {
start: 10,
Expand Down Expand Up @@ -135,7 +135,7 @@ export const SmaCore1GridMs3Model = modbusModelFactory<SmaCore1GridMs3>({
VAr_phsA: {
start: 0,
end: 2,
readConverter: registersToInt32,
readConverter: registersToInt32Nullable,
},
VAr_phsB: {
start: 2,
Expand All @@ -155,7 +155,7 @@ export const SmaCore1GridMs3Model = modbusModelFactory<SmaCore1GridMs3>({
VA_phsA: {
start: 8,
end: 10,
readConverter: registersToInt32,
readConverter: registersToInt32Nullable,
},
VA_phsB: {
start: 10,
Expand Down
24 changes: 12 additions & 12 deletions src/connections/modbus/models/sma/core1/meteringGridMs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ export type SmaCore1MeteringGridMsModels = SmaCore1MeteringGridMs1 &

type SmaCore1MeteringGridMs1 = {
// Grid power phase L1
PhV_phsA: number;
PhV_phsA: number | null;
// Grid power phase L2
PhV_phsB: number | null;
// Grid power phase L3
PhV_phsC: number | null;
// Power grid feeding L1
W_phsA: number;
W_phsA: number | null;
// Power grid feeding L2
W_phsB: number | null;
// Power grid feeding L3
W_phsC: number | null;
// Power drawn from grid phase L1
WIn_phsA: number;
WIn_phsA: number | null;
// Power drawn from grid phase L2
WIn_phsB: number | null;
// Power drawn from grid phase L3
WIn_phsC: number | null;
// Reactive power grid feeding phase L1
VAr_phsA: number;
VAr_phsA: number | null;
// Reactive power grid feeding phase L2
VAr_phsB: number | null;
// Reactive power grid feeding phase L3
Expand All @@ -42,13 +42,13 @@ type SmaCore1MeteringGridMs2 = {
// Displacement power factor
TotPF: number;
// Grid current phase L1
A_phsA: number;
A_phsA: number | null;
// Grid current phase L2
A_phsB: number | null;
// Grid current phase L3
A_phsC: number | null;
// Apparent power L1
VA_phsA: number;
VA_phsA: number | null;
// Apparent power L2
VA_phsB: number | null;
// Apparent power L3
Expand All @@ -72,7 +72,7 @@ export const SmaCore1MeteringGridMs1Model =
PhV_phsA: {
start: 0,
end: 2,
readConverter: (value) => registersToUint32(value, -2),
readConverter: (value) => registersToUint32Nullable(value, -2),
},
PhV_phsB: {
start: 2,
Expand All @@ -87,7 +87,7 @@ export const SmaCore1MeteringGridMs1Model =
W_phsA: {
start: 6,
end: 8,
readConverter: registersToUint32,
readConverter: registersToUint32Nullable,
},
W_phsB: {
start: 8,
Expand All @@ -102,7 +102,7 @@ export const SmaCore1MeteringGridMs1Model =
WIn_phsA: {
start: 12,
end: 14,
readConverter: registersToUint32,
readConverter: registersToUint32Nullable,
},
WIn_phsB: {
start: 14,
Expand All @@ -117,7 +117,7 @@ export const SmaCore1MeteringGridMs1Model =
VAr_phsA: {
start: 18,
end: 20,
readConverter: registersToInt32,
readConverter: registersToInt32Nullable,
},
VAr_phsB: {
start: 20,
Expand Down Expand Up @@ -149,7 +149,7 @@ export const SmaCore1MeteringGridMs2Model =
A_phsA: {
start: 2,
end: 4,
readConverter: (value) => registersToInt32(value, -3),
readConverter: (value) => registersToInt32Nullable(value, -3),
},
A_phsB: {
start: 4,
Expand All @@ -164,7 +164,7 @@ export const SmaCore1MeteringGridMs2Model =
VA_phsA: {
start: 8,
end: 10,
readConverter: registersToInt32,
readConverter: registersToInt32Nullable,
},
VA_phsB: {
start: 10,
Expand Down
4 changes: 2 additions & 2 deletions src/connections/powerwall2/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export const metersSiteSchema = z.array(
energy_imported: z.number(),
instant_average_voltage: z.number(),
instant_average_current: z.number(),
i_a_current: z.number(),
i_a_current: z.number().optional(),
i_b_current: z.number().optional(),
i_c_current: z.number().optional(),
last_phase_voltage_communication_time: z.string(),
v_l1n: z.number(),
v_l1n: z.number().optional(),
v_l2n: z.number().optional(),
v_l3n: z.number().optional(),
last_phase_power_communication_time: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions src/connections/sunspec/helpers/inverterMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export function getInverterMetrics(inverter: InverterModel) {

const scaledValues = {
A: numberWithPow10(inverter.A, inverter.A_SF),
AphA: numberWithPow10(inverter.AphA, inverter.A_SF),
AphA: numberNullableWithPow10(inverter.AphA, inverter.A_SF),
AphB: numberNullableWithPow10(inverter.AphB, inverter.A_SF),
AphC: numberNullableWithPow10(inverter.AphC, inverter.A_SF),
PPVphAB: numberNullableWithPow10(inverter.PPVphAB, inverter.V_SF),
PPVphBC: numberNullableWithPow10(inverter.PPVphBC, inverter.V_SF),
PPVphCA: numberNullableWithPow10(inverter.PPVphCA, inverter.V_SF),
PhVphA: numberWithPow10(inverter.PhVphA, inverter.V_SF),
PhVphA: numberNullableWithPow10(inverter.PhVphA, inverter.V_SF),
PhVphB: numberNullableWithPow10(inverter.PhVphB, inverter.V_SF),
PhVphC: numberNullableWithPow10(inverter.PhVphC, inverter.V_SF),
W: numberWithPow10(inverter.W, inverter.W_SF),
Expand Down
2 changes: 1 addition & 1 deletion src/connections/sunspec/helpers/meterMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getMeterMetrics(meter: MeterModel) {

const scaledValues = {
A: numberWithPow10(meter.A, meter.A_SF),
AphA: numberWithPow10(meter.AphA, meter.A_SF),
AphA: numberNullableWithPow10(meter.AphA, meter.A_SF),
AphB: numberNullableWithPow10(meter.AphB, meter.A_SF),
AphC: numberNullableWithPow10(meter.AphC, meter.A_SF),
PhV: numberNullableWithPow10(meter.PhV, meter.V_SF),
Expand Down
4 changes: 2 additions & 2 deletions src/connections/sunspec/models/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type MeterModel = {
*
* Phase A Current.
*/
AphA: number;
AphA: number | null;

/**
* AphB
Expand Down Expand Up @@ -557,7 +557,7 @@ export const meterModel = modbusModelFactory<MeterModel>({
AphA: {
start: 3,
end: 4,
readConverter: registersToInt16,
readConverter: registersToInt16Nullable,
},
AphB: {
start: 4,
Expand Down
2 changes: 1 addition & 1 deletion src/coordinator/helpers/derSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function generateDerSample({
},
voltage: {
type: 'perPhase',
phaseA: averageNumbersArray(
phaseA: averageNumbersNullableArray(
invertersData.map((data) => data.inverter.voltagePhaseA),
),
phaseB: averageNumbersNullableArray(
Expand Down
108 changes: 60 additions & 48 deletions src/helpers/influxdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ export function writeSiteSamplePoints(siteSample: SiteSample) {
.floatField('realPower', siteSample.realPower.net),
);

writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField('realPower', siteSample.realPower.phaseA),
);
if (siteSample.realPower.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField('realPower', siteSample.realPower.phaseA),
);
}

if (siteSample.realPower.phaseB) {
writeApi.writePoint(
Expand Down Expand Up @@ -99,16 +101,18 @@ export function writeSiteSamplePoints(siteSample: SiteSample) {
.floatField('reactivePower', siteSample.reactivePower.net),
);

writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField(
'reactivePower',
siteSample.reactivePower.phaseA,
),
);
if (siteSample.reactivePower.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField(
'reactivePower',
siteSample.reactivePower.phaseA,
),
);
}

if (siteSample.reactivePower.phaseB) {
writeApi.writePoint(
Expand Down Expand Up @@ -138,13 +142,15 @@ export function writeSiteSamplePoints(siteSample: SiteSample) {
}
}

writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField('voltage', siteSample.voltage.phaseA),
);
if (siteSample.voltage.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(siteSample.date)
.tag('type', 'site')
.tag('phase', 'A')
.floatField('voltage', siteSample.voltage.phaseA),
);
}

if (siteSample.voltage.phaseB) {
writeApi.writePoint(
Expand Down Expand Up @@ -197,13 +203,15 @@ export function writeDerSamplePoints(derSample: DerSample) {
.floatField('realPower', derSample.realPower.net),
);

writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField('realPower', derSample.realPower.phaseA),
);
if (derSample.realPower.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField('realPower', derSample.realPower.phaseA),
);
}

if (derSample.realPower.phaseB) {
writeApi.writePoint(
Expand Down Expand Up @@ -247,16 +255,18 @@ export function writeDerSamplePoints(derSample: DerSample) {
.floatField('reactivePower', derSample.reactivePower.net),
);

writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField(
'reactivePower',
derSample.reactivePower.phaseA,
),
);
if (derSample.reactivePower.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField(
'reactivePower',
derSample.reactivePower.phaseA,
),
);
}

if (derSample.reactivePower.phaseB) {
writeApi.writePoint(
Expand Down Expand Up @@ -287,13 +297,15 @@ export function writeDerSamplePoints(derSample: DerSample) {
}

if (derSample.voltage) {
writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField('voltage', derSample.voltage.phaseA),
);
if (derSample.voltage.phaseA) {
writeApi.writePoint(
new Point('sample')
.timestamp(derSample.date)
.tag('type', 'der')
.tag('phase', 'A')
.floatField('voltage', derSample.voltage.phaseA),
);
}

if (derSample.voltage.phaseB) {
writeApi.writePoint(
Expand Down
Loading

0 comments on commit 692a0aa

Please sign in to comment.