[goecharger] fix data type for energy (nrg) (#13052)

* [goecharger] fix data type for energy (nrg)
* nrg need to be double for V2
* [goecharger] update example

Signed-off-by: Reinhard Plaim <reinhardplaim@gmail.com>
This commit is contained in:
Reinhard Plaim 2022-07-08 21:55:57 +02:00 committed by GitHub
parent 57e31e2885
commit 9c768dc08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 52 deletions

View File

@ -112,55 +112,66 @@ rule "Set charging limit for go-eCharger"
when when
Time cron "*/10 * * ? * *" // Trigger every 10 seconds Time cron "*/10 * * ? * *" // Trigger every 10 seconds
then then
var actualMaxChargingCurrentInt = (GoEChargerMaxCurrent.state as Number).intValue
if (GoEChargerExcessCharge.state == ON) { if (GoEChargerExcessCharge.state == ON) {
var totalPowerOutputInWatt = Total_power_fast.state as DecimalType * 1000 var currentChargingPower = GoEChargerPowerAll.state as Number
if (totalPowerOutputInWatt > 0) { var totalPowerOutputInWatt = (Total_power_fast.state as DecimalType) * 1000
totalPowerOutputInWatt = 0 var availableChargingPowerInWatt = 0
if (totalPowerOutputInWatt > 0 && currentChargingPower > 0) {
// take care if already charging
availableChargingPowerInWatt = currentChargingPower.intValue - totalPowerOutputInWatt.intValue
} else {
if (totalPowerOutputInWatt > 0) {
totalPowerOutputInWatt = 0
}
availableChargingPowerInWatt = (totalPowerOutputInWatt.intValue * -1) + currentChargingPower.intValue
} }
totalPowerOutputInWatt = totalPowerOutputInWatt * -1 var maxAmp3Phases = (availableChargingPowerInWatt / 3) / 230
var maxAmp3Phases = (totalPowerOutputInWatt / 3) / 230
if (maxAmp3Phases > 16.0) { if (maxAmp3Phases > 16.0) {
maxAmp3Phases = 16.0 maxAmp3Phases = 16.0
} }
var maxAmp1Phase = totalPowerOutputInWatt / 230;
if (maxAmp3Phases.intValue >= 6) { var maxAmp1Phase = availableChargingPowerInWatt / 230
if (maxAmp3Phases >= 6) {
// set force state to neutral (Neutral=0, Off=1, On=2) // set force state to neutral (Neutral=0, Off=1, On=2)
if (GoEChargerForceState.state != 0) { if (GoEChargerForceState.state != 0) {
GoEChargerForceState.sendCommand(0); GoEChargerForceState.sendCommand(0)
} }
// 3 phases // 3 phases
if ((GoEChargerPhases.state as Number) != 3) { if (GoEChargerPhases.state != 3) {
GoEChargerPhases.sendCommand(3); GoEChargerPhases.sendCommand(3)
} }
if ((GoEChargerMaxCurrent.state as Number).intValue != maxAmp3Phases.intValue) { if (actualMaxChargingCurrentInt != maxAmp3Phases.intValue) {
GoEChargerMaxCurrent.sendCommand(maxAmp3Phases.intValue) GoEChargerMaxCurrent.sendCommand(maxAmp3Phases.intValue)
// logInfo("eCharger", "Set charging limit 3 Phases: " + maxAmp3Phases.intValue + " A") // logInfo("eCharger", "Set charging limit 3 Phases: " + maxAmp3Phases.intValue + " A")
} }
} else { } else {
if (maxAmp1Phase.intValue >= 6 ) { if (maxAmp1Phase.intValue >= 6 ) {
// set force state to neutral (Neutral=0, Off=1, On=2) // set force state to neutral (Neutral=0, Off=1, On=2)
if (GoEChargerForceState.state != 0) { if (GoEChargerForceState.state != 0) {
GoEChargerForceState.sendCommand(0); GoEChargerForceState.sendCommand(0)
} }
// switch to 1 phase -> check if this is useful // switch to 1 phase -> check if this is useful
if ((GoEChargerPhases.state as Number) != 1) { if (GoEChargerPhases.state != 1) {
GoEChargerPhases.sendCommand(1) GoEChargerPhases.sendCommand(1)
} }
if ((GoEChargerMaxCurrent.state as Number).intValue != maxAmp1Phase.intValue) { if (actualMaxChargingCurrentInt != maxAmp1Phase.intValue) {
GoEChargerMaxCurrent.sendCommand(maxAmp1Phase.intValue) GoEChargerMaxCurrent.sendCommand(maxAmp1Phase.intValue)
// logInfo("eCharger", "Set charging limit 1 Phase: " + maxAmp1Phase.intValue + " A") // logInfo("eCharger", "Set charging limit 1 Phase: " + maxAmp1Phase.intValue + " A")
} }
} else { } else {
// switch off // switch off
if (GoEChargerForceState.state != 1) { if (GoEChargerForceState.state != 1) {
GoEChargerForceState.sendCommand(1); GoEChargerMaxCurrent.sendCommand(6)
GoEChargerForceState.sendCommand(1)
// logInfo("eCharger", "Switch charging off") // logInfo("eCharger", "Switch charging off")
} }
} }
@ -168,14 +179,14 @@ then
} else { } else {
// set force state to neutral (Neutral=0, Off=1, On=2) // set force state to neutral (Neutral=0, Off=1, On=2)
if (GoEChargerForceState.state != 0) { if (GoEChargerForceState.state != 0) {
GoEChargerForceState.sendCommand(0); GoEChargerForceState.sendCommand(0)
} }
if ((GoEChargerPhases.state as Number) != 3) { if (GoEChargerPhases.state != 3) {
GoEChargerPhases.sendCommand(3); GoEChargerPhases.sendCommand(3)
} }
if ((GoEChargerMaxCurrent.state as Number).intValue != 16) { if (actualMaxChargingCurrentInt != 16) {
GoEChargerMaxCurrent.sendCommand(16) GoEChargerMaxCurrent.sendCommand(16)
} }
} }

View File

@ -27,9 +27,6 @@ public class GoEStatusResponseBaseDTO {
@SerializedName("amp") @SerializedName("amp")
public Integer maxCurrent; public Integer maxCurrent;
@SerializedName("nrg")
public Integer[] energy;
@SerializedName("err") @SerializedName("err")
public Integer errorCode; public Integer errorCode;

View File

@ -45,4 +45,7 @@ public class GoEStatusResponseDTO extends GoEStatusResponseBaseDTO {
@SerializedName("amx") @SerializedName("amx")
public Integer maxCurrentTemporary; public Integer maxCurrentTemporary;
@SerializedName("nrg")
public Integer[] energy;
} }

View File

@ -41,4 +41,7 @@ public class GoEStatusResponseV2DTO extends GoEStatusResponseBaseDTO {
@SerializedName("frc") @SerializedName("frc")
public Integer forceState; public Integer forceState;
@SerializedName("nrg")
public Double[] energy;
} }

View File

@ -87,21 +87,6 @@ public abstract class GoEChargerBaseHandler extends BaseThingHandler {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new StringType(goeResponseBase.firmware); return new StringType(goeResponseBase.firmware);
case VOLTAGE_L1:
if (goeResponseBase.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponseBase.energy[0], Units.VOLT);
case VOLTAGE_L2:
if (goeResponseBase.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponseBase.energy[1], Units.VOLT);
case VOLTAGE_L3:
if (goeResponseBase.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponseBase.energy[2], Units.VOLT);
} }
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }

View File

@ -218,11 +218,26 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponse.energy[9] * 100, Units.WATT); return new QuantityType<>(goeResponse.energy[9] * 100, Units.WATT);
case POWER_ALL: case VOLTAGE_L1:
if (goeResponseBase.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponseBase.energy[11] * 10, Units.WATT); return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
case VOLTAGE_L2:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
case VOLTAGE_L3:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
case POWER_ALL:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[11] * 10, Units.WATT);
} }
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }

View File

@ -152,53 +152,67 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
if (goeResponse.sessionChargeConsumption == null) { if (goeResponse.sessionChargeConsumption == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.sessionChargeConsumption / 1000d), Units.KILOWATT_HOUR); return new QuantityType<>(goeResponse.sessionChargeConsumption / 1000d, Units.KILOWATT_HOUR);
case SESSION_CHARGE_CONSUMPTION_LIMIT: case SESSION_CHARGE_CONSUMPTION_LIMIT:
if (goeResponse.sessionChargeConsumptionLimit == null) { if (goeResponse.sessionChargeConsumptionLimit == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.sessionChargeConsumptionLimit / 1000d), return new QuantityType<>(goeResponse.sessionChargeConsumptionLimit / 1000d, Units.KILOWATT_HOUR);
Units.KILOWATT_HOUR);
case TOTAL_CONSUMPTION: case TOTAL_CONSUMPTION:
if (goeResponse.totalChargeConsumption == null) { if (goeResponse.totalChargeConsumption == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.totalChargeConsumption / 1000d), Units.KILOWATT_HOUR); return new QuantityType<>((Double) (goeResponse.totalChargeConsumption / 1000d), Units.KILOWATT_HOUR);
case VOLTAGE_L1:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
case VOLTAGE_L2:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
case VOLTAGE_L3:
if (goeResponse.energy == null) {
return UnDefType.UNDEF;
}
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
case CURRENT_L1: case CURRENT_L1:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.energy[4] / 1000d), Units.AMPERE); return new QuantityType<>(goeResponse.energy[4], Units.AMPERE);
case CURRENT_L2: case CURRENT_L2:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.energy[5] / 1000d), Units.AMPERE); return new QuantityType<>(goeResponse.energy[5], Units.AMPERE);
case CURRENT_L3: case CURRENT_L3:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>((Double) (goeResponse.energy[6] / 1000d), Units.AMPERE); return new QuantityType<>(goeResponse.energy[6], Units.AMPERE);
case POWER_L1: case POWER_L1:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponse.energy[7] * 1000, Units.WATT); return new QuantityType<>(goeResponse.energy[7], Units.WATT);
case POWER_L2: case POWER_L2:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponse.energy[8] * 1000, Units.WATT); return new QuantityType<>(goeResponse.energy[8], Units.WATT);
case POWER_L3: case POWER_L3:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponse.energy[9] * 1000, Units.WATT); return new QuantityType<>(goeResponse.energy[9], Units.WATT);
case POWER_ALL: case POWER_ALL:
if (goeResponse.energy == null) { if (goeResponse.energy == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new QuantityType<>(goeResponse.energy[11] * 1000, Units.WATT); return new QuantityType<>(goeResponse.energy[11], Units.WATT);
case FORCE_STATE: case FORCE_STATE:
if (goeResponse.forceState == null) { if (goeResponse.forceState == null) {
return UnDefType.UNDEF; return UnDefType.UNDEF;