diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java index b5c7a7238e2..bdb1215e722 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java @@ -271,6 +271,7 @@ public class ShellyBindingConstants { public static final String CHANNEL_DEVST_ACCUWATTS = "accumulatedWatts"; public static final String CHANNEL_DEVST_ACCUTOTAL = "accumulatedWTotal"; public static final String CHANNEL_DEVST_ACCURETURNED = "accumulatedReturned"; + public static final String CHANNEL_DEVST_TOTALKWH = "totalKWH"; public static final String CHANNEL_DEVST_RESETTOTAL = CHANNEL_EMETER_RESETTOTAL; public static final String CHANNEL_DEVST_CHARGER = "charger"; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java index e0e967fe991..4d950b7fdb2 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1ApiJsonDTO.java @@ -772,6 +772,7 @@ public class Shelly1ApiJsonDTO { public Double totalCurrent; public Double totalPower; + public Double totalKWH; public Double totalReturned; @SerializedName("ext_temperature") diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java index 5e139a33149..b8cdcee251e 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java @@ -12,7 +12,7 @@ */ package org.openhab.binding.shelly.internal.api2; -import static org.openhab.binding.shelly.internal.ShellyBindingConstants.CHANNEL_INPUT; +import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*; import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*; import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; @@ -61,6 +61,7 @@ import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceS import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2CoverStatus; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusEm; +import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusEmData; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusHumidity; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusIlluminance; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusPower; @@ -190,7 +191,7 @@ public class Shelly2ApiClient extends ShellyHttpClient { updated |= updateRelayStatus(status, result.switch3, channelUpdate); updated |= updateRelayStatus(status, result.switch100, channelUpdate); updated |= updateRelayStatus(status, result.pm10, channelUpdate); - updated |= updateEmStatus(status, result.em0, channelUpdate); + updated |= updateEmStatus(status, result.em0, result.emdata0, channelUpdate); updated |= updateEmStatus(status, result.em10, channelUpdate); updated |= updateEmStatus(status, result.em11, channelUpdate); updated |= updateRollerStatus(status, result.cover0, channelUpdate); @@ -354,8 +355,8 @@ public class Shelly2ApiClient extends ShellyHttpClient { } private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2DeviceStatusEm em, - boolean channelUpdate) throws ShellyApiException { - if (em == null) { + @Nullable Shelly2DeviceStatusEmData emData, boolean channelUpdate) throws ShellyApiException { + if (em == null || emData == null) { return false; } @@ -369,11 +370,18 @@ public class Shelly2ApiClient extends ShellyHttpClient { status.totalReturned = em.totalAprtPower; } + if (emData.totalKWH != null) { + status.totalKWH = emData.totalKWH; + } + ShellySettingsMeter sm = new ShellySettingsMeter(); ShellySettingsEMeter emeter = status.emeters.get(0); if (em.aActPower != null) { sm.power = emeter.power = em.aActPower; } + if (emData.aTotal != null) { + emeter.total = emData.aTotal; + } if (em.aAprtPower != null) { emeter.totalReturned = em.aAprtPower; } @@ -396,6 +404,9 @@ public class Shelly2ApiClient extends ShellyHttpClient { if (em.bActPower != null) { sm.power = emeter.power = em.bActPower; } + if (emData.bTotal != null) { + emeter.total = emData.bTotal; + } if (em.bAprtPower != null) { emeter.totalReturned = em.bAprtPower; } @@ -419,6 +430,9 @@ public class Shelly2ApiClient extends ShellyHttpClient { if (em.cActPower != null) { sm.power = emeter.power = em.cActPower; } + if (emData.cTotal != null) { + emeter.total = emData.cTotal; + } if (em.cAprtPower != null) { emeter.totalReturned = em.cAprtPower; } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java index e131f0348e5..80e6a6204b8 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java @@ -704,6 +704,16 @@ public class Shelly2ApiJsonDTO { public static class Shelly2DeviceStatusEmData { public Integer id; + + @SerializedName("a_total_act_energy") + public Double aTotal; + @SerializedName("b_total_act_energy") + public Double bTotal; + @SerializedName("c_total_act_energy") + public Double cTotal; + + @SerializedName("total_act") + public Double totalKWH; public String[] errors; } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java index a62b1752894..fd76955c3e3 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java @@ -352,6 +352,9 @@ public class ShellyComponents { thingHandler.updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_ACCURETURNED, toQuantityType(status.totalReturned != null ? status.totalReturned / 1000 : accumulatedReturned, DIGITS_KWH, Units.KILOWATT_HOUR)); + thingHandler.updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_TOTALKWH, toQuantityType( + status.totalKWH != null ? status.totalKWH / 1000 : 0, DIGITS_KWH, Units.KILOWATT_HOUR)); + } } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java index b5c911ec649..a2689f72433 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java @@ -13,7 +13,7 @@ package org.openhab.binding.shelly.internal.provider; import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*; -import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.SHELLY_API_INVTEMP; +import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import java.util.ArrayList; @@ -133,6 +133,7 @@ public class ShellyChannelDefinitions { .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_WAKEUP, "sensorWakeup", ITEMT_STRING)) .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_ACCUWATTS, "meterAccuWatts", ITEMT_POWER)) .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_ACCUTOTAL, "meterAccuTotal", ITEMT_ENERGY)) + .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_TOTALKWH, "totalKWH", ITEMT_ENERGY)) .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_ACCURETURNED, "meterAccuReturned", ITEMT_ENERGY)) .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL, "meterResetTotals", ITEMT_SWITCH)) .add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_VOLTAGE, "supplyVoltage", ITEMT_VOLT)) @@ -332,6 +333,7 @@ public class ShellyChannelDefinitions { || (profile.hasRelays && profile.numMeters > 1 && !profile.isRoller && !profile.isRGBW2); addChannel(thing, add, accuChannel, CHGR_DEVST, CHANNEL_DEVST_ACCUWATTS); addChannel(thing, add, accuChannel, CHGR_DEVST, CHANNEL_DEVST_ACCUTOTAL); + addChannel(thing, add, accuChannel, CHGR_DEVST, CHANNEL_DEVST_TOTALKWH); addChannel(thing, add, accuChannel && (status.emeters != null), CHGR_DEVST, CHANNEL_DEVST_ACCURETURNED); addChannel(thing, add, profile.is3EM, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL); // 3EM addChannel(thing, add, status.voltage != null || profile.settings.supplyVoltage != null, CHGR_DEVST, diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties index 934f815b44e..bd03c597a24 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties @@ -300,6 +300,8 @@ channel-type.shelly.meterAccuTotal.label = Accumulated Total Power channel-type.shelly.meterAccuTotal.description = Accumulated Total Power in kW/h of the device (including all meters) channel-type.shelly.meterAccuReturned.label = Accumulated Apparent Power channel-type.shelly.meterAccuReturned.description = Accumulated Apparent Power in kW/h of the device (including all meters) +channel-type.shelly.totalKWH.label = Total Energy Consumption Device +channel-type.shelly.totalKWH.description = Total energy consumption of the device in kW/h since the device powered up (resets on restart) channel-type.shelly.meterReactive.label = Reactive Energy channel-type.shelly.meterReactive.description = Instantaneous reactive power in Watts (W) channel-type.shelly.lastPower1.label = Last Power diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen1_relay.xml b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen1_relay.xml index 5e0fb737112..b728ecd252d 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen1_relay.xml +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen1_relay.xml @@ -528,6 +528,19 @@ + + Number:Energy + + @text/channel-type.shelly.totalKWH.description + Energy + + Measurement + Energy + + + + + Number:Power