Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modbus.e3dc] Add battery capacity #15085

Merged
merged 2 commits into from Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"/>
weymann marked this conversation as resolved.
Show resolved Hide resolved
</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>