mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[shelly] Add totalKWH channels for Shelly Pro 3EM (#17602)
* added totalkwh channel Signed-off-by: Jonathan van de Giessen <jonathan.vandegiessen@student.hu.nl> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
2c7c1c586f
commit
9ad7aab7d1
@ -271,6 +271,7 @@ public class ShellyBindingConstants {
|
|||||||
public static final String CHANNEL_DEVST_ACCUWATTS = "accumulatedWatts";
|
public static final String CHANNEL_DEVST_ACCUWATTS = "accumulatedWatts";
|
||||||
public static final String CHANNEL_DEVST_ACCUTOTAL = "accumulatedWTotal";
|
public static final String CHANNEL_DEVST_ACCUTOTAL = "accumulatedWTotal";
|
||||||
public static final String CHANNEL_DEVST_ACCURETURNED = "accumulatedReturned";
|
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_RESETTOTAL = CHANNEL_EMETER_RESETTOTAL;
|
||||||
|
|
||||||
public static final String CHANNEL_DEVST_CHARGER = "charger";
|
public static final String CHANNEL_DEVST_CHARGER = "charger";
|
||||||
|
@ -772,6 +772,7 @@ public class Shelly1ApiJsonDTO {
|
|||||||
|
|
||||||
public Double totalCurrent;
|
public Double totalCurrent;
|
||||||
public Double totalPower;
|
public Double totalPower;
|
||||||
|
public Double totalKWH;
|
||||||
public Double totalReturned;
|
public Double totalReturned;
|
||||||
|
|
||||||
@SerializedName("ext_temperature")
|
@SerializedName("ext_temperature")
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.shelly.internal.api2;
|
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.api1.Shelly1ApiJsonDTO.*;
|
||||||
import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
|
import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
|
||||||
import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
|
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;
|
||||||
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2CoverStatus;
|
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.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.Shelly2DeviceStatusHumidity;
|
||||||
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusIlluminance;
|
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusIlluminance;
|
||||||
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusPower;
|
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.switch3, channelUpdate);
|
||||||
updated |= updateRelayStatus(status, result.switch100, channelUpdate);
|
updated |= updateRelayStatus(status, result.switch100, channelUpdate);
|
||||||
updated |= updateRelayStatus(status, result.pm10, 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.em10, channelUpdate);
|
||||||
updated |= updateEmStatus(status, result.em11, channelUpdate);
|
updated |= updateEmStatus(status, result.em11, channelUpdate);
|
||||||
updated |= updateRollerStatus(status, result.cover0, channelUpdate);
|
updated |= updateRollerStatus(status, result.cover0, channelUpdate);
|
||||||
@ -354,8 +355,8 @@ public class Shelly2ApiClient extends ShellyHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2DeviceStatusEm em,
|
private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2DeviceStatusEm em,
|
||||||
boolean channelUpdate) throws ShellyApiException {
|
@Nullable Shelly2DeviceStatusEmData emData, boolean channelUpdate) throws ShellyApiException {
|
||||||
if (em == null) {
|
if (em == null || emData == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,11 +370,18 @@ public class Shelly2ApiClient extends ShellyHttpClient {
|
|||||||
status.totalReturned = em.totalAprtPower;
|
status.totalReturned = em.totalAprtPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emData.totalKWH != null) {
|
||||||
|
status.totalKWH = emData.totalKWH;
|
||||||
|
}
|
||||||
|
|
||||||
ShellySettingsMeter sm = new ShellySettingsMeter();
|
ShellySettingsMeter sm = new ShellySettingsMeter();
|
||||||
ShellySettingsEMeter emeter = status.emeters.get(0);
|
ShellySettingsEMeter emeter = status.emeters.get(0);
|
||||||
if (em.aActPower != null) {
|
if (em.aActPower != null) {
|
||||||
sm.power = emeter.power = em.aActPower;
|
sm.power = emeter.power = em.aActPower;
|
||||||
}
|
}
|
||||||
|
if (emData.aTotal != null) {
|
||||||
|
emeter.total = emData.aTotal;
|
||||||
|
}
|
||||||
if (em.aAprtPower != null) {
|
if (em.aAprtPower != null) {
|
||||||
emeter.totalReturned = em.aAprtPower;
|
emeter.totalReturned = em.aAprtPower;
|
||||||
}
|
}
|
||||||
@ -396,6 +404,9 @@ public class Shelly2ApiClient extends ShellyHttpClient {
|
|||||||
if (em.bActPower != null) {
|
if (em.bActPower != null) {
|
||||||
sm.power = emeter.power = em.bActPower;
|
sm.power = emeter.power = em.bActPower;
|
||||||
}
|
}
|
||||||
|
if (emData.bTotal != null) {
|
||||||
|
emeter.total = emData.bTotal;
|
||||||
|
}
|
||||||
if (em.bAprtPower != null) {
|
if (em.bAprtPower != null) {
|
||||||
emeter.totalReturned = em.bAprtPower;
|
emeter.totalReturned = em.bAprtPower;
|
||||||
}
|
}
|
||||||
@ -419,6 +430,9 @@ public class Shelly2ApiClient extends ShellyHttpClient {
|
|||||||
if (em.cActPower != null) {
|
if (em.cActPower != null) {
|
||||||
sm.power = emeter.power = em.cActPower;
|
sm.power = emeter.power = em.cActPower;
|
||||||
}
|
}
|
||||||
|
if (emData.cTotal != null) {
|
||||||
|
emeter.total = emData.cTotal;
|
||||||
|
}
|
||||||
if (em.cAprtPower != null) {
|
if (em.cAprtPower != null) {
|
||||||
emeter.totalReturned = em.cAprtPower;
|
emeter.totalReturned = em.cAprtPower;
|
||||||
}
|
}
|
||||||
|
@ -704,6 +704,16 @@ public class Shelly2ApiJsonDTO {
|
|||||||
|
|
||||||
public static class Shelly2DeviceStatusEmData {
|
public static class Shelly2DeviceStatusEmData {
|
||||||
public Integer id;
|
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;
|
public String[] errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +352,9 @@ public class ShellyComponents {
|
|||||||
thingHandler.updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_ACCURETURNED,
|
thingHandler.updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_ACCURETURNED,
|
||||||
toQuantityType(status.totalReturned != null ? status.totalReturned / 1000 : accumulatedReturned,
|
toQuantityType(status.totalReturned != null ? status.totalReturned / 1000 : accumulatedReturned,
|
||||||
DIGITS_KWH, Units.KILOWATT_HOUR));
|
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));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
package org.openhab.binding.shelly.internal.provider;
|
package org.openhab.binding.shelly.internal.provider;
|
||||||
|
|
||||||
import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*;
|
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 static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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_WAKEUP, "sensorWakeup", ITEMT_STRING))
|
||||||
.add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_ACCUWATTS, "meterAccuWatts", ITEMT_POWER))
|
.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_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_ACCURETURNED, "meterAccuReturned", ITEMT_ENERGY))
|
||||||
.add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL, "meterResetTotals", ITEMT_SWITCH))
|
.add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL, "meterResetTotals", ITEMT_SWITCH))
|
||||||
.add(new ShellyChannel(m, CHGR_DEVST, CHANNEL_DEVST_VOLTAGE, "supplyVoltage", ITEMT_VOLT))
|
.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);
|
|| (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_ACCUWATTS);
|
||||||
addChannel(thing, add, accuChannel, CHGR_DEVST, CHANNEL_DEVST_ACCUTOTAL);
|
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, accuChannel && (status.emeters != null), CHGR_DEVST, CHANNEL_DEVST_ACCURETURNED);
|
||||||
addChannel(thing, add, profile.is3EM, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL); // 3EM
|
addChannel(thing, add, profile.is3EM, CHGR_DEVST, CHANNEL_DEVST_RESETTOTAL); // 3EM
|
||||||
addChannel(thing, add, status.voltage != null || profile.settings.supplyVoltage != null, CHGR_DEVST,
|
addChannel(thing, add, status.voltage != null || profile.settings.supplyVoltage != null, CHGR_DEVST,
|
||||||
|
@ -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.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.label = Accumulated Apparent Power
|
||||||
channel-type.shelly.meterAccuReturned.description = Accumulated Apparent Power in kW/h of the device (including all meters)
|
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.label = Reactive Energy
|
||||||
channel-type.shelly.meterReactive.description = Instantaneous reactive power in Watts (W)
|
channel-type.shelly.meterReactive.description = Instantaneous reactive power in Watts (W)
|
||||||
channel-type.shelly.lastPower1.label = Last Power
|
channel-type.shelly.lastPower1.label = Last Power
|
||||||
|
@ -528,6 +528,19 @@
|
|||||||
</state>
|
</state>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
|
<channel-type id="totalKWH">
|
||||||
|
<item-type>Number:Energy</item-type>
|
||||||
|
<label>@text/channel-type.shelly.totalKWH.label</label>
|
||||||
|
<description>@text/channel-type.shelly.totalKWH.description</description>
|
||||||
|
<category>Energy</category>
|
||||||
|
<tags>
|
||||||
|
<tag>Measurement</tag>
|
||||||
|
<tag>Energy</tag>
|
||||||
|
</tags>
|
||||||
|
<state readOnly="true" pattern="%.3f %unit%">
|
||||||
|
</state>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="meterReactive">
|
<channel-type id="meterReactive">
|
||||||
<item-type>Number:Power</item-type>
|
<item-type>Number:Power</item-type>
|
||||||
<label>@text/channel-type.shelly.meterReactive.label</label>
|
<label>@text/channel-type.shelly.meterReactive.label</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user