]> git.basschouten.com Git - openhab-addons.git/commitdiff
[modbus.e3dc] battery capacity added (#15085)
authorBernd Weymann <bernd.weymann@gmail.com>
Fri, 16 Jun 2023 05:46:32 +0000 (07:46 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Jun 2023 05:46:32 +0000 (07:46 +0200)
* 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>
bundles/org.openhab.binding.modbus.e3dc/src/main/java/org/openhab/binding/modbus/e3dc/internal/E3DCBindingConstants.java
bundles/org.openhab.binding.modbus.e3dc/src/main/java/org/openhab/binding/modbus/e3dc/internal/E3DCConfiguration.java
bundles/org.openhab.binding.modbus.e3dc/src/main/java/org/openhab/binding/modbus/e3dc/internal/handler/E3DCThingHandler.java
bundles/org.openhab.binding.modbus.e3dc/src/main/resources/OH-INF/i18n/e3dc.properties
bundles/org.openhab.binding.modbus.e3dc/src/main/resources/OH-INF/thing/bridge-e3dc.xml
bundles/org.openhab.binding.modbus.e3dc/src/main/resources/OH-INF/thing/power-channel-groups.xml
bundles/org.openhab.binding.modbus.e3dc/src/main/resources/OH-INF/thing/power-channel-types.xml

index 142fef0aa7e40982dbf2f662406993a6b01d3ea7..eca5c0f6d3a27520cab74fac40765eb8f81614a5 100644 (file)
@@ -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";
index 3e8049b9eb7ba7404ad79e1056d69cb6a9f2c0ab..43de046452ece3f67f0ce45ac9fc393701abc70a 100644 (file)
@@ -22,8 +22,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 @NonNullByDefault
 public class E3DCConfiguration {
 
-    /**
-     * Data refresh interval
-     */
     public int refresh = 2000;
+    public double batteryCapacity = -1;
 }
index 4622ad6eb65920039484f1cef67494275c2ee339..f5104dd5adcffecbaac7579292ee5deff7fe9420 100644 (file)
@@ -18,6 +18,8 @@ import static org.openhab.binding.modbus.e3dc.internal.modbus.E3DCModbusConstans
 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;
@@ -36,6 +38,8 @@ import org.openhab.core.io.transport.modbus.ModbusCommunicationInterface;
 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;
@@ -98,6 +102,8 @@ public class E3DCThingHandler extends BaseBridgeHandler {
     private ChannelUID autarkyChannel;
     private ChannelUID selfConsumptionChannel;
     private ChannelUID batterySOCChannel;
+    private ChannelUID batteryChargedChannel;
+    private ChannelUID batteryUnchargedChannel;
 
     private ChannelUID string1AmpereChannel;
     private ChannelUID string1VoltChannel;
@@ -157,6 +163,8 @@ public class E3DCThingHandler extends BaseBridgeHandler {
         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);
@@ -360,6 +368,17 @@ public class E3DCThingHandler extends BaseBridgeHandler {
                 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());
             }
index dac5178572d4c71c548da97dcd55507c1a2185ab..0a9ea0b708229640ac46e93683f32896ff984e79 100644 (file)
@@ -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
index 665d207fa04d7c1ce3891e715fc3642010dc77f8..839f0e9d6b2536558444060cb0f52ff8d9e825b3 100644 (file)
                                <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>
index 10f9730ec085a2fad0af29a54a8ad14e578db8c8..9a59e67f44c5bc5c376eada640e017c7eca781d4 100644 (file)
@@ -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>
index 2dde054cbddaa742dca5487797a7c3aaf6671c47..1da9b05e5dfd99c80a0c9f77ef8042b08a26f4f0 100644 (file)
                <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>