]> git.basschouten.com Git - openhab-addons.git/commitdiff
[SunSpec] Add missing Inverter Status, Add Channel for Vendor-Specific Status (#13480)
authorAndreas Lanz <Blizzard26@users.noreply.github.com>
Wed, 5 Oct 2022 05:49:31 +0000 (07:49 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 05:49:31 +0000 (07:49 +0200)
* [SunSpec] Added missing InverterStatus

See e.g., https://github.com/sunspec/models/blob/master/json/model_101.json#L307

* [SunSpec] Added Channel for Vendor Specific Status

* [SunSpec] Fixing two old TODOs

VA and VAR are defined as alternate unit for WATT so no breaking change.

Signed-off-by: Andreas Lanz <alanz@gmx.de>
bundles/org.openhab.binding.modbus.sunspec/README.md
bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/InverterStatus.java
bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/SunSpecConstants.java
bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/handler/InverterHandler.java
bundles/org.openhab.binding.modbus.sunspec/src/main/resources/OH-INF/i18n/sunspec.properties
bundles/org.openhab.binding.modbus.sunspec/src/main/resources/OH-INF/thing/inverter-channel-groups.xml
bundles/org.openhab.binding.modbus.sunspec/src/main/resources/OH-INF/thing/inverter-channel-types.xml

index df9c9e5d00c778b5ed1bbd56faffeeb75dc4b340..5ae9122b161aff6def67fea074ac7cd75f7d89e9 100644 (file)
@@ -65,13 +65,14 @@ Different things support a subset of the following groups.
 
 This group contains general operational information about the device.
 
-| Channel ID              | Item Type             | Description                                                                        |
-|-------------------------|-----------------------|------------------------------------------------------------------------------------|
-| cabinet-temperature     | Number:Temperature    | Temperature of the cabinet if supported in Celsius                                 |
-| heatsink-temperature    | Number:Temperature    | Device heat sink temperature in Celsius                                            |
-| transformer-temperature | Number:Temperature    | Temperature of the transformer in Celsius                                          |
-| other-temperature       | Number:Temperature    | Any other temperature reading not covered by the above items if available. Celsius |
-| status                  | String                | Device status: OFF=Off, SLEEP=Sleeping/night mode, ON=On - producing power         |
+| Channel ID              | Item Type             | Description                                                                                                                                                                                                                                                                                                     |
+|-------------------------|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| cabinet-temperature     | Number:Temperature    | Temperature of the cabinet if supported in Celsius                                                                                                                                                                                                                                                              |
+| heatsink-temperature    | Number:Temperature    | Device heat sink temperature in Celsius                                                                                                                                                                                                                                                                         |
+| transformer-temperature | Number:Temperature    | Temperature of the transformer in Celsius                                                                                                                                                                                                                                                                       |
+| other-temperature       | Number:Temperature    | Any other temperature reading not covered by the above items if available. Celsius                                                                                                                                                                                                                              |
+| status                  | String                | Device status: <ul><li>OFF=Off</li><li>SLEEP=Sleeping/night mode</li><li>STARTING=Grid Monitoring/wake-up</li><li>ON=On - producing power (also called MPPT by Specification)</li><li>THROTTLED=Production (curtailed)<li>SHUTTING_DOWN=Shutting down<li>FAULT=Fault<li> STANDBY=Standby/Maintenance/Setup</ul> |
+| status-vendor           | Number                | Vendor Specific Status Code                                                                                                                                                                                                                                                                                     |
 
 Supported by: all inverter things
 
@@ -157,8 +158,8 @@ acPhaseC: available only for meter-wye-phase and meter-delta-phase meters type i
 | ac-voltage-to-n                | Number:ElectricPotential | Voltage of this line relative to the neutral line                   |
 | ac-voltage-to-next             | Number:ElectricPotential | Voltage of this line relative to the next line                      |
 | ac-real-power                  | Number:Power             | AC Real Power value (W)                                             |
-| ac-apparent-power              | Number:Power             | AC Apparent Power value                                             |
-| ac-reactive-power              | Number:Power             | AC Reactive Power value                                             |
+| ac-apparent-power              | Number:Power             | AC Apparent Power value (VA)                                        |
+| ac-reactive-power              | Number:Power             | AC Reactive Power value (VAR)                                       |
 | ac-power-factor                | Number:Dimensionless     | AC Power Factor (%)                                                 |
 | ac-exported-real-energy        | Number:Energy            | Real Energy Exported (Wh                                            |
 | ac-imported-real-energy        | Number:Energy            | Real Energy Imported (Wh)                                           |
index f3f7ea88baa249d94db2e32689ed48eb6cd0bf39..6340e9e9adf3b9543b9ea9408c421f0e44414dba 100644 (file)
@@ -12,6 +12,9 @@
  */
 package org.openhab.binding.modbus.sunspec.internal;
 
+import java.util.Arrays;
+import java.util.Optional;
+
 /**
  * Possible values for an inverter's status field
  *
@@ -21,7 +24,12 @@ public enum InverterStatus {
 
     OFF(1),
     SLEEP(2),
+    STARTING(3),
     ON(4),
+    THROTTLED(5),
+    SHUTTING_DOWN(6),
+    FAULT(7),
+    STANDBY(8),
     UNKNOWN(-1);
 
     private final int code;
@@ -35,15 +43,8 @@ public enum InverterStatus {
     }
 
     public static InverterStatus getByCode(int code) {
-        switch (code) {
-            case 1:
-                return InverterStatus.OFF;
-            case 2:
-                return InverterStatus.SLEEP;
-            case 4:
-                return InverterStatus.ON;
-            default:
-                return InverterStatus.UNKNOWN;
-        }
+        Optional<InverterStatus> status = Arrays.stream(InverterStatus.values()).filter(s -> s.code == code)
+                .findFirst();
+        return status.orElse(InverterStatus.UNKNOWN);
     }
 }
index 0b231c21c1fe6cd001694e594107b4e08cf874e2..81ce50a7360df0dad7b0263a21c95169c2c87602 100644 (file)
@@ -92,6 +92,7 @@ public class SunSpecConstants {
     public static final String CHANNEL_TRANSFORMER_TEMPERATURE = "transformer-temperature";
     public static final String CHANNEL_OTHER_TEMPERATURE = "other-temperature";
     public static final String CHANNEL_STATUS = "status";
+    public static final String CHANNEL_STATUS_VENDOR = "status-vendor";
 
     // List of channel ids in AC general group for inverter
     public static final String CHANNEL_AC_TOTAL_CURRENT = "ac-total-current";
index e352cbbcf37a5706eddb79147af2fc8721689781..a88ab2f75a728da92552d71a02882750c75216f3 100644 (file)
@@ -23,8 +23,10 @@ import org.openhab.binding.modbus.sunspec.internal.InverterStatus;
 import org.openhab.binding.modbus.sunspec.internal.dto.InverterModelBlock;
 import org.openhab.binding.modbus.sunspec.internal.parser.InverterModelParser;
 import org.openhab.core.io.transport.modbus.ModbusRegisterArray;
+import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.thing.Thing;
+import org.openhab.core.types.State;
 import org.openhab.core.types.UnDefType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -82,6 +84,9 @@ public class InverterHandler extends AbstractSunSpecHandler {
         updateState(channelUID(GROUP_DEVICE_INFO, CHANNEL_STATUS),
                 status == null ? UnDefType.UNDEF : new StringType(status.name()));
 
+        updateState(channelUID(GROUP_DEVICE_INFO, CHANNEL_STATUS_VENDOR),
+                block.statusVendor.<State> map(DecimalType::new).orElse(UnDefType.UNDEF));
+
         // AC General group
         updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_TOTAL_CURRENT),
                 getScaled(block.acCurrentTotal, block.acCurrentSF, AMPERE));
@@ -92,14 +97,10 @@ public class InverterHandler extends AbstractSunSpecHandler {
                 getScaled(block.acFrequency, block.acFrequencySF, HERTZ));
 
         updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_APPARENT_POWER),
-                getScaled(block.acApparentPower, block.acApparentPowerSF, WATT)); // TODO: VA currently not supported,
-                                                                                  // see:
-                                                                                  // https://github.com/openhab/openhab-core/pull/1347
+                getScaled(block.acApparentPower, block.acApparentPowerSF, VOLT_AMPERE));
 
         updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_REACTIVE_POWER),
-                getScaled(block.acReactivePower, block.acReactivePowerSF, WATT)); // TODO: var currently not supported,
-                                                                                  // see:
-                                                                                  // https://github.com/openhab/openhab-core/pull/1347
+                getScaled(block.acReactivePower, block.acReactivePowerSF, VAR));
 
         updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_POWER_FACTOR),
                 getScaled(block.acPowerFactor, block.acPowerFactorSF, PERCENT));
index bc9f9f00c6720ec3edc63db7b8b905b8a04a98b6..10a4d1211cd28f4188abeec69355affbd2441258 100644 (file)
@@ -97,5 +97,12 @@ channel-type.modbus.status-type.label = Status
 channel-type.modbus.status-type.description = Device status
 channel-type.modbus.status-type.state.option.OFF = Off
 channel-type.modbus.status-type.state.option.SLEEP = Sleeping / Night mode
+channel-type.modbus.status-type.state.option.STARTING=Grid Monitoring/wake-up
 channel-type.modbus.status-type.state.option.ON = On - producing power
+channel-type.modbus.status-type.state.option.THROTTLED=Production (curtailed)
+channel-type.modbus.status-type.state.option.SHUTTING_DOWN=Shutting down
+channel-type.modbus.status-type.state.option.FAULT=Fault
+channel-type.modbus.status-type.state.option.STANDBY=Standby/Maintenance/Setup
+channel-type.modbus.status-vendor-type.label = Vendor-defined Status
+channel-type.modbus.status-vendor-type.description = Vendor-defined device status and error codes
 channel-type.modbus.transformer-temperature-type.label = Transformer Temperature
index ad7fb5a157b29c69a375a5998ee3653d13ffd64d..1e0cbef7546b8c0cc0467f0704162fcb927725cd 100644 (file)
@@ -12,6 +12,7 @@
                        <channel id="transformer-temperature" typeId="transformer-temperature-type"/>
                        <channel id="other-temperature" typeId="other-temperature-type"/>
                        <channel id="status" typeId="status-type"/>
+                       <channel id="status-vendor" typeId="status-vendor-type"/>
                </channels>
        </channel-group-type>
 
index 0ee3ccb91824a07a64a443a96bdb91a1a4590e0d..e40ae0b522b68cb64338fa68ff81f75f2b2967a0 100644 (file)
                        <options>
                                <option value="OFF">Off</option>
                                <option value="SLEEP">Sleeping / Night mode</option>
+                               <option value="STARTING">Grid Monitoring/wake-up</option>
                                <option value="ON">On - producing power</option>
+                               <option value="THROTTLED">Production (curtailed)</option>
+                               <option value="SHUTTING_DOWN">Shutting down</option>
+                               <option value="FAULT">Fault</option>
+                               <option value="STANDBY">Standby/Maintenance/Setup</option>
                        </options>
                </state>
        </channel-type>
+
+       <channel-type id="status-vendor-type">
+               <item-type>Number</item-type>
+               <label>Vendor-defined Status</label>
+               <description>Vendor-defined device status and error codes.</description>
+               <state readOnly="true" pattern="%d"/>
+       </channel-type>
 </thing:thing-descriptions>