From 9c768dc08f2c04de34e450e791b599f1035f9038 Mon Sep 17 00:00:00 2001 From: Reinhard Plaim <53980214+ranzen84@users.noreply.github.com> Date: Fri, 8 Jul 2022 21:55:57 +0200 Subject: [PATCH] [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 --- .../org.openhab.binding.goecharger/README.md | 53 +++++++++++-------- .../api/GoEStatusResponseBaseDTO.java | 3 -- .../internal/api/GoEStatusResponseDTO.java | 3 ++ .../internal/api/GoEStatusResponseV2DTO.java | 3 ++ .../handler/GoEChargerBaseHandler.java | 15 ------ .../internal/handler/GoEChargerHandler.java | 21 ++++++-- .../internal/handler/GoEChargerV2Handler.java | 34 ++++++++---- 7 files changed, 80 insertions(+), 52 deletions(-) diff --git a/bundles/org.openhab.binding.goecharger/README.md b/bundles/org.openhab.binding.goecharger/README.md index 98e4f809d..34008166f 100644 --- a/bundles/org.openhab.binding.goecharger/README.md +++ b/bundles/org.openhab.binding.goecharger/README.md @@ -112,55 +112,66 @@ rule "Set charging limit for go-eCharger" when Time cron "*/10 * * ? * *" // Trigger every 10 seconds then + var actualMaxChargingCurrentInt = (GoEChargerMaxCurrent.state as Number).intValue + if (GoEChargerExcessCharge.state == ON) { - var totalPowerOutputInWatt = Total_power_fast.state as DecimalType * 1000 - if (totalPowerOutputInWatt > 0) { - totalPowerOutputInWatt = 0 + var currentChargingPower = GoEChargerPowerAll.state as Number + var totalPowerOutputInWatt = (Total_power_fast.state as DecimalType) * 1000 + 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 = (totalPowerOutputInWatt / 3) / 230 + var maxAmp3Phases = (availableChargingPowerInWatt / 3) / 230 if (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) if (GoEChargerForceState.state != 0) { - GoEChargerForceState.sendCommand(0); + GoEChargerForceState.sendCommand(0) } // 3 phases - if ((GoEChargerPhases.state as Number) != 3) { - GoEChargerPhases.sendCommand(3); + if (GoEChargerPhases.state != 3) { + GoEChargerPhases.sendCommand(3) } - if ((GoEChargerMaxCurrent.state as Number).intValue != maxAmp3Phases.intValue) { + if (actualMaxChargingCurrentInt != maxAmp3Phases.intValue) { GoEChargerMaxCurrent.sendCommand(maxAmp3Phases.intValue) // logInfo("eCharger", "Set charging limit 3 Phases: " + maxAmp3Phases.intValue + " A") } - } else { + } else { if (maxAmp1Phase.intValue >= 6 ) { // set force state to neutral (Neutral=0, Off=1, On=2) if (GoEChargerForceState.state != 0) { - GoEChargerForceState.sendCommand(0); + GoEChargerForceState.sendCommand(0) } // switch to 1 phase -> check if this is useful - if ((GoEChargerPhases.state as Number) != 1) { + if (GoEChargerPhases.state != 1) { GoEChargerPhases.sendCommand(1) } - if ((GoEChargerMaxCurrent.state as Number).intValue != maxAmp1Phase.intValue) { + if (actualMaxChargingCurrentInt != maxAmp1Phase.intValue) { GoEChargerMaxCurrent.sendCommand(maxAmp1Phase.intValue) // logInfo("eCharger", "Set charging limit 1 Phase: " + maxAmp1Phase.intValue + " A") } } else { // switch off if (GoEChargerForceState.state != 1) { - GoEChargerForceState.sendCommand(1); + GoEChargerMaxCurrent.sendCommand(6) + GoEChargerForceState.sendCommand(1) // logInfo("eCharger", "Switch charging off") } } @@ -168,14 +179,14 @@ then } else { // set force state to neutral (Neutral=0, Off=1, On=2) if (GoEChargerForceState.state != 0) { - GoEChargerForceState.sendCommand(0); + GoEChargerForceState.sendCommand(0) } - if ((GoEChargerPhases.state as Number) != 3) { - GoEChargerPhases.sendCommand(3); + if (GoEChargerPhases.state != 3) { + GoEChargerPhases.sendCommand(3) } - if ((GoEChargerMaxCurrent.state as Number).intValue != 16) { + if (actualMaxChargingCurrentInt != 16) { GoEChargerMaxCurrent.sendCommand(16) } } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseBaseDTO.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseBaseDTO.java index da7bf4930..9a9138ae3 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseBaseDTO.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseBaseDTO.java @@ -27,9 +27,6 @@ public class GoEStatusResponseBaseDTO { @SerializedName("amp") public Integer maxCurrent; - @SerializedName("nrg") - public Integer[] energy; - @SerializedName("err") public Integer errorCode; diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseDTO.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseDTO.java index 839e0f52a..d626dc997 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseDTO.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseDTO.java @@ -45,4 +45,7 @@ public class GoEStatusResponseDTO extends GoEStatusResponseBaseDTO { @SerializedName("amx") public Integer maxCurrentTemporary; + + @SerializedName("nrg") + public Integer[] energy; } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseV2DTO.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseV2DTO.java index c65c63b22..08cb88b11 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseV2DTO.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/api/GoEStatusResponseV2DTO.java @@ -41,4 +41,7 @@ public class GoEStatusResponseV2DTO extends GoEStatusResponseBaseDTO { @SerializedName("frc") public Integer forceState; + + @SerializedName("nrg") + public Double[] energy; } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerBaseHandler.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerBaseHandler.java index d0ac23d3c..fad98597c 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerBaseHandler.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerBaseHandler.java @@ -87,21 +87,6 @@ public abstract class GoEChargerBaseHandler extends BaseThingHandler { return UnDefType.UNDEF; } 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; } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java index 71a7f1aa9..709a378ad 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java @@ -218,11 +218,26 @@ public class GoEChargerHandler extends GoEChargerBaseHandler { return UnDefType.UNDEF; } return new QuantityType<>(goeResponse.energy[9] * 100, Units.WATT); - case POWER_ALL: - if (goeResponseBase.energy == null) { + case VOLTAGE_L1: + if (goeResponse.energy == null) { 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; } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java index 3ab945448..5c75822e6 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java @@ -152,53 +152,67 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { if (goeResponse.sessionChargeConsumption == null) { 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: if (goeResponse.sessionChargeConsumptionLimit == null) { return UnDefType.UNDEF; } - return new QuantityType<>((Double) (goeResponse.sessionChargeConsumptionLimit / 1000d), - Units.KILOWATT_HOUR); + return new QuantityType<>(goeResponse.sessionChargeConsumptionLimit / 1000d, Units.KILOWATT_HOUR); case TOTAL_CONSUMPTION: if (goeResponse.totalChargeConsumption == null) { return UnDefType.UNDEF; } 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: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>((Double) (goeResponse.energy[4] / 1000d), Units.AMPERE); + return new QuantityType<>(goeResponse.energy[4], Units.AMPERE); case CURRENT_L2: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>((Double) (goeResponse.energy[5] / 1000d), Units.AMPERE); + return new QuantityType<>(goeResponse.energy[5], Units.AMPERE); case CURRENT_L3: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>((Double) (goeResponse.energy[6] / 1000d), Units.AMPERE); + return new QuantityType<>(goeResponse.energy[6], Units.AMPERE); case POWER_L1: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>(goeResponse.energy[7] * 1000, Units.WATT); + return new QuantityType<>(goeResponse.energy[7], Units.WATT); case POWER_L2: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>(goeResponse.energy[8] * 1000, Units.WATT); + return new QuantityType<>(goeResponse.energy[8], Units.WATT); case POWER_L3: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>(goeResponse.energy[9] * 1000, Units.WATT); + return new QuantityType<>(goeResponse.energy[9], Units.WATT); case POWER_ALL: if (goeResponse.energy == null) { return UnDefType.UNDEF; } - return new QuantityType<>(goeResponse.energy[11] * 1000, Units.WATT); + return new QuantityType<>(goeResponse.energy[11], Units.WATT); case FORCE_STATE: if (goeResponse.forceState == null) { return UnDefType.UNDEF;