Skip to content

Commit

Permalink
[modbus.e3dc] battery capacity added (#15085)
Browse files Browse the repository at this point in the history
* battery capacity added

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>

* i18n for channel additions

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>

---------

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
  • Loading branch information
weymann committed Jun 16, 2023
1 parent a5c47ae commit 03c5243
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
Expand Up @@ -53,6 +53,8 @@ public class E3DCBindingConstants {
public static final String AUTARKY_CHANNEL = "autarky";
public static final String SELF_CONSUMPTION_CHANNEL = "self-consumption";
public static final String BATTERY_STATE_OF_CHARGE_CHANNEL = "battery-soc";
public static final String BATTERY_CHARGED_CHANNEL = "battery-charged";
public static final String BATTERY_UNCHARGED_CHANNEL = "battery-uncharged";

// Channels for Wallbox Block
public static final String WB_AVAILABLE_CHANNEL = "wb-available";
Expand Down
Expand Up @@ -22,8 +22,6 @@
@NonNullByDefault
public class E3DCConfiguration {

/**
* Data refresh interval
*/
public int refresh = 2000;
public double batteryCapacity = -1;
}
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.Optional;

import javax.measure.quantity.Energy;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.modbus.e3dc.internal.E3DCConfiguration;
Expand All @@ -36,6 +38,8 @@
import org.openhab.core.io.transport.modbus.ModbusReadFunctionCode;
import org.openhab.core.io.transport.modbus.ModbusReadRequestBlueprint;
import org.openhab.core.io.transport.modbus.PollTask;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -98,6 +102,8 @@ public enum ReadStatus {
private ChannelUID autarkyChannel;
private ChannelUID selfConsumptionChannel;
private ChannelUID batterySOCChannel;
private ChannelUID batteryChargedChannel;
private ChannelUID batteryUnchargedChannel;

private ChannelUID string1AmpereChannel;
private ChannelUID string1VoltChannel;
Expand Down Expand Up @@ -157,6 +163,8 @@ public E3DCThingHandler(Bridge thing) {
autarkyChannel = channelUID(thing, POWER_GROUP, AUTARKY_CHANNEL);
selfConsumptionChannel = channelUID(thing, POWER_GROUP, SELF_CONSUMPTION_CHANNEL);
batterySOCChannel = channelUID(thing, POWER_GROUP, BATTERY_STATE_OF_CHARGE_CHANNEL);
batteryChargedChannel = channelUID(thing, POWER_GROUP, BATTERY_CHARGED_CHANNEL);
batteryUnchargedChannel = channelUID(thing, POWER_GROUP, BATTERY_UNCHARGED_CHANNEL);

string1AmpereChannel = channelUID(thing, STRINGS_GROUP, STRING1_DC_CURRENT_CHANNEL);
string1VoltChannel = channelUID(thing, STRINGS_GROUP, STRING1_DC_VOLTAGE_CHANNEL);
Expand Down Expand Up @@ -360,6 +368,17 @@ void handleDataResult(AsyncModbusReadResult result) {
updateState(autarkyChannel, block.autarky);
updateState(selfConsumptionChannel, block.selfConsumption);
updateState(batterySOCChannel, block.batterySOC);
if (config != null) {
if (config.batteryCapacity > 0) {
double soc = block.batterySOC.doubleValue();
QuantityType<Energy> charged = QuantityType.valueOf(soc * config.batteryCapacity / 100,
Units.KILOWATT_HOUR);
updateState(batteryChargedChannel, charged);
QuantityType<Energy> uncharged = QuantityType
.valueOf((100 - soc) * config.batteryCapacity / 100, Units.KILOWATT_HOUR);
updateState(batteryUnchargedChannel, uncharged);
}
}
} else {
logger.debug("Unable to get {} from provider {}", DataType.POWER, dataParser.toString());
}
Expand Down
Expand Up @@ -37,6 +37,10 @@ channel-type.modbus.battery-power-supply-channel.label = Battery Discharge
channel-type.modbus.battery-power-supply-channel.description = Battery discharges and provides Power
channel-type.modbus.battery-soc-channel.label = Battery State Of Charge
channel-type.modbus.battery-soc-channel.description = Charge Level of your attached Battery in Percent
channel-type.modbus.battery-charged-channel.label = Battery Charge
channel-type.modbus.battery-charged-channel.description = Charged energy of battery
channel-type.modbus.battery-uncharged-channel.label = Battery Open Capacity
channel-type.modbus.battery-uncharged-channel.description = Open energy capacity of battery
channel-type.modbus.charge-lock-time-channel.label = Charge Lock Time Active
channel-type.modbus.charge-lock-time-channel.description = Charge Lock Time is currently active
channel-type.modbus.discharge-lock-time-channel.label = Discharge Lock Time Active
Expand Down
Expand Up @@ -22,6 +22,10 @@
<description>Refresh Rate of E3DC values in Milliseconds</description>
<default>2000</default>
</parameter>
<parameter name="batteryCapacity" type="decimal">
<label>Battery Capacity</label>
<description>Capacity of the built in battery in kWh</description>
</parameter>
</config-description>
</bridge-type>
</thing:thing-descriptions>
Expand Up @@ -20,6 +20,8 @@
<channel id="autarky" typeId="autarky-channel"/>
<channel id="self-consumption" typeId="self-consumption-channel"/>
<channel id="battery-soc" typeId="battery-soc-channel"/>
<channel id="battery-charged" typeId="battery-charged-channel"/>
<channel id="battery-uncharged" typeId="battery-uncharged-channel"/>
</channels>
</channel-group-type>
</thing:thing-descriptions>
Expand Up @@ -75,4 +75,16 @@
<description>Charge Level of your attached Battery in Percent</description>
<state pattern="%d %unit%" readOnly="true"/>
</channel-type>
<channel-type id="battery-charged-channel">
<item-type>Number:Energy</item-type>
<label>Battery Charge</label>
<description>Charged energy of battery</description>
<state pattern="%.3f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="battery-uncharged-channel">
<item-type>Number:Energy</item-type>
<label>Battery Open Capacity</label>
<description>Open energy capacity of battery</description>
<state pattern="%.3f %unit%" readOnly="true"/>
</channel-type>
</thing:thing-descriptions>

0 comments on commit 03c5243

Please sign in to comment.