Skip to content

Commit 1808d84

Browse files
EVCS HardyBarth: improve phase and status detection (OpenEMS#2239)
1 parent 7029b39 commit 1808d84

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

io.openems.edge.evcs.hardybarth/src/io/openems/edge/evcs/hardybarth/EvcsHardyBarthImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private void activate(ComponentContext context, Config config) {
7676
this._setFixedMinimumHardwarePower(config.minHwCurrent() / 1000 * 3 * 230);
7777
this._setFixedMaximumHardwarePower(config.maxHwCurrent() / 1000 * 3 * 230);
7878
this._setPowerPrecision(230);
79+
this._setPhases(Phases.THREE_PHASE);
7980

8081
if (config.enabled()) {
8182
this.api = new HardyBarthApi(config.ip(), this);
@@ -249,7 +250,6 @@ private boolean setTarget(int current) throws OpenemsNamedException {
249250
if (current > 0) {
250251
// Send stop pause request
251252
resultPause = this.api.sendPutRequest("/api/secc", "salia/pausecharging", "" + 0);
252-
this.debugLog("Wake up HardyBarth " + this.alias() + " from the pause");
253253
} else {
254254
// Send pause charging request
255255
resultPause = this.api.sendPutRequest("/api/secc", "salia/pausecharging", "" + 1);

io.openems.edge.evcs.hardybarth/src/io/openems/edge/evcs/hardybarth/HardyBarthReadWorker.java

+44-32
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class HardyBarthReadWorker extends AbstractCycleWorker {
1717

1818
private final EvcsHardyBarthImpl parent;
1919
private int chargingFinishedCounter = 0;
20+
private int errorCounter = 0;
2021

2122
public HardyBarthReadWorker(EvcsHardyBarthImpl parent) {
2223
this.parent = parent;
@@ -92,29 +93,29 @@ private void setEvcsChannelIds(JsonElement json) {
9293
var powerL2 = (Long) this.getValueForChannel(EvcsHardyBarth.ChannelId.RAW_ACTIVE_POWER_L2, json);
9394
var powerL3 = (Long) this.getValueForChannel(EvcsHardyBarth.ChannelId.RAW_ACTIVE_POWER_L3, json);
9495

95-
Integer phases = null;
96+
// TODO: Handle phases, having each phase value in the Nature
97+
// Keep last value if no power value was given
98+
var phases = this.parent.getPhasesAsInt();
9699
if (powerL1 != null && powerL2 != null && powerL3 != null) {
97100

98101
var sum = powerL1 + powerL2 + powerL3;
99102

100-
if (sum > 900) {
103+
if (sum > 300) {
101104
phases = 0;
102105

103-
if (powerL1 >= 300) {
106+
if (powerL1 >= 100) {
104107
phases += 1;
105108
}
106-
if (powerL2 >= 300) {
109+
if (powerL2 >= 100) {
107110
phases += 1;
108111
}
109-
if (powerL3 >= 300) {
112+
if (powerL3 >= 100) {
110113
phases += 1;
111114
}
112115
}
113116
}
114117
this.parent._setPhases(phases);
115-
if (phases != null) {
116-
this.parent.debugLog("Used phases: " + phases);
117-
}
118+
this.parent.debugLog("Used phases: " + phases);
118119

119120
// CHARGE_POWER
120121
var chargePowerLong = (Long) this.getValueFromJson(Evcs.ChannelId.CHARGE_POWER, json, value -> {
@@ -129,32 +130,34 @@ private void setEvcsChannelIds(JsonElement json) {
129130
return activePower < 100 ? 0 : activePower;
130131
}, "secc", "port0", "metering", "power", "active_total", "actual");
131132

132-
//
133133
this.parent._setChargePower(chargePowerLong == null ? null : chargePowerLong.intValue());
134134

135135
// STATUS
136136
var status = (Status) this.getValueFromJson(EvcsHardyBarth.ChannelId.RAW_CHARGE_STATUS_CHARGEPOINT, json,
137137
value -> {
138+
138139
String stringValue = TypeUtils.getAsType(OpenemsType.STRING, value);
139140
if (stringValue == null) {
140-
return Status.UNDEFINED;
141+
this.errorCounter++;
142+
this.parent.debugLog("Hardy Barth RAW_STATUS would be null! Raw value: " + value);
143+
if (this.errorCounter > 3) {
144+
return Status.ERROR;
145+
}
146+
return this.parent.getStatus();
141147
}
142148

143-
Status rawStatus = Status.UNDEFINED;
144-
switch (stringValue) {
145-
case "A":
146-
rawStatus = Status.NOT_READY_FOR_CHARGING;
147-
break;
148-
case "B":
149-
rawStatus = Status.READY_FOR_CHARGING;
149+
Status rawStatus = switch (stringValue) {
150+
case "A" -> Status.NOT_READY_FOR_CHARGING;
151+
case "B" -> {
152+
var tmpStatus = Status.READY_FOR_CHARGING;
150153

151154
// Detect if the car is full
152155
int chargePower = chargePowerLong == null ? 0 : chargePowerLong.intValue();
153156
if (this.parent.getSetChargePowerLimit().orElse(0) >= this.parent.getMinimumHardwarePower()
154157
.orElse(0) && chargePower <= 0) {
155158

156159
if (this.chargingFinishedCounter >= 90) {
157-
rawStatus = Status.CHARGING_FINISHED;
160+
tmpStatus = Status.CHARGING_FINISHED;
158161
} else {
159162
this.chargingFinishedCounter++;
160163
}
@@ -163,25 +166,34 @@ private void setEvcsChannelIds(JsonElement json) {
163166

164167
// Charging rejected because we are forcing to pause charging
165168
if (this.parent.getSetChargePowerLimit().orElse(0) == 0) {
166-
rawStatus = Status.CHARGING_REJECTED;
169+
tmpStatus = Status.CHARGING_REJECTED;
167170
}
168171
}
169-
break;
170-
case "C":
171-
case "D":
172-
rawStatus = Status.CHARGING;
173-
break;
174-
case "E":
175-
case "F":
176-
rawStatus = Status.ERROR;
177-
break;
178-
default:
179-
rawStatus = Status.UNDEFINED;
180-
break;
172+
yield tmpStatus;
173+
}
174+
case "C", "D" -> Status.CHARGING;
175+
case "E", "F" -> {
176+
this.errorCounter++;
177+
this.parent.debugLog("Hardy Barth RAW_STATUS would be an error! Raw value: " + stringValue
178+
+ " - Error counter: " + this.errorCounter);
179+
if (this.errorCounter > 3) {
180+
yield Status.ERROR;
181+
}
182+
yield this.parent.getStatus();
181183
}
182-
if (stringValue.equals("B")) {
184+
default -> {
185+
this.parent.debugLog("State " + stringValue + " is not a valid state");
186+
yield Status.UNDEFINED;
187+
}
188+
};
189+
190+
if (!stringValue.equals("B")) {
183191
this.chargingFinishedCounter = 0;
184192
}
193+
if (!stringValue.equals("E") || !stringValue.equals("F")) {
194+
this.errorCounter = 0;
195+
}
196+
185197
return rawStatus;
186198
}, "secc", "port0", "ci", "charge", "cp", "status");
187199

io.openems.edge.evcs.hardybarth/test/io/openems/edge/evcs/hardybarth/EvcsHardyBarthImplTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public void test() throws Exception {
1515
.activate(MyConfig.create() //
1616
.setId(COMPONENT_ID) //
1717
.setIp("192.168.8.101") //
18-
.setMaxHwCurrent(32) //
19-
.setMinHwCurrent(6) //
18+
.setMaxHwCurrent(32_000) //
19+
.setMinHwCurrent(6_000) //
2020
.build())
2121
.next(new TestCase());
2222
}

0 commit comments

Comments
 (0)