From baf077d71d3a9dc30da5d07fe8a2f1666372b034 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 2 Feb 2023 12:46:46 +0100 Subject: [PATCH] [omnikinverter] added extra parameters (temperature, AC frequency, AC current, AC voltage and total hours running) (#14244) * [omnikinverter] Added temperature sensor * [Omnikinverter] Bugfix for wrong channeltype item-type Prevents 'Received HTTP PUT request with an invalid item name' when adding items * [Omnik] Added AC Voltage, Currrent and Frequency and total running hours Signed-off-by: Dave --- .../README.md | 39 ++-- .../OmnikInverterBindingConstants.java | 16 ++ .../internal/OmnikInverterMessage.java | 30 ++- .../handler/OmnikInverterHandler.java | 51 +++++ .../OH-INF/i18n/omnikinverter.properties | 48 ++++- .../resources/OH-INF/thing/thing-types.xml | 176 ++++++++++++------ .../test/OmnikInverterMessageTest.java | 55 ++++++ 7 files changed, 336 insertions(+), 79 deletions(-) diff --git a/bundles/org.openhab.binding.omnikinverter/README.md b/bundles/org.openhab.binding.omnikinverter/README.md index 1f82a8a61..34f64d126 100644 --- a/bundles/org.openhab.binding.omnikinverter/README.md +++ b/bundles/org.openhab.binding.omnikinverter/README.md @@ -21,20 +21,31 @@ No autodiscovery available ## Channels -| Channel Type Id | Item Type | Description | -|:---------------|:--------------|:------------------------------------------------------------------------------------------------------------------| -| power | Number:Power | The instantaneous power generation for feed 1 to the grid, in Watt by default (**deprecated**; same as powerAC1) | -| powerAC1 | Number:Power | The instantaneous power generation for feed 1 to the grid, in Watt by default | -| powerAC2 | Number:Power | The instantaneous power generation for feed 2 to the grid, in Watt by default | -| powerAC3 | Number:Power | The instantaneous power generation for feed 3 to the grid, in Watt by default | -| currentPV1 | Number:Current | The current generation for input string 1, in ampere by default | -| currentPV2 | Number:Current | The current generation for input string 2, in ampere by default | -| currentPV3 | Number:Current | The current generation for input string 3, in ampere by default | -| voltagePV1 | Number:Voltage | The voltage on input string 1, in volt by default | -| voltagePV2 | Number:Voltage | The voltage on input string 2, in volt by default | -| voltagePV3 | Number:Voltage | The voltage on input string 3, in volt by default | -| energyToday | Number:Energy | The amount of energy generated today, in kWh by default | -| energyTotal | Number:Energy | The total amount of energy generated, in kWh by default | +| Channel Type Id | Item Type | Description | +|:----------------|:-------------------------|:-----------------------------------------------------------------------------------------------------------------| +| power | Number:Power | The instantaneous power generation for feed 1 to the grid, in Watt by default (**deprecated**; same as powerAC1) | +| powerAC1 | Number:Power | The instantaneous power generation for feed 1 to the grid, in Watt by default | +| powerAC2 | Number:Power | The instantaneous power generation for feed 2 to the grid, in Watt by default | +| powerAC3 | Number:Power | The instantaneous power generation for feed 3 to the grid, in Watt by default | +| voltageAC1 | Number:ElectricPotential | The voltage for feed 1 to the grid, in Volt by default | +| voltageAC2 | Number:ElectricPotential | The voltage for feed 2 to the grid, in Volt by default | +| voltageAC3 | Number:ElectricPotential | The voltage for feed 3 to the grid, in Volt by default | +| currentAC1 | Number:ElectricCurrent | The current for feed 1 to the grid, in ampere by default | +| currentAC2 | Number:ElectricCurrent | The current for feed 2 to the grid, in ampere by default | +| currentAC3 | Number:ElectricCurrent | The current for feed 3 to the grid, in ampere by default | +| frequencyAC1 | Number:Frequency | The frequrence of feed 1 of the grid, in hertz by default | +| frequencyAC2 | Number:Frequency | The frequrence of feed 2 of the grid, in hertz by default | +| frequencyAC3 | Number:Frequency | The frequrence of feed 3 of the grid, in hertz by default | +| currentPV1 | Number:ElectricCurrent | The current generation for input string 1, in ampere by default | +| currentPV2 | Number:ElectricCurrent | The current generation for input string 2, in ampere by default | +| currentPV3 | Number:ElectricCurrent | The current generation for input string 3, in ampere by default | +| voltagePV1 | Number:ElectricPotential | The voltage on input string 1, in volt by default | +| voltagePV2 | Number:ElectricPotential | The voltage on input string 2, in volt by default | +| voltagePV3 | Number:ElectricPotential | The voltage on input string 3, in volt by default | +| energyToday | Number:Energy | The amount of energy generated today, in kWh by default | +| energyTotal | Number:Energy | The total amount of energy generated, in kWh by default | +| temperature | Number:Temperature | The temperature from the sensor | +| hoursTotal | Number:Time | The total amount of running hours | ## Full Example diff --git a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterBindingConstants.java b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterBindingConstants.java index c12225953..a59824c67 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterBindingConstants.java +++ b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterBindingConstants.java @@ -43,7 +43,23 @@ public class OmnikInverterBindingConstants { public static final String CHANNEL_POWER_AC2 = "powerAC2"; public static final String CHANNEL_POWER_AC3 = "powerAC3"; + public static final String CHANNEL_VOLTAGE_AC1 = "voltageAC1"; + public static final String CHANNEL_VOLTAGE_AC2 = "voltageAC2"; + public static final String CHANNEL_VOLTAGE_AC3 = "voltageAC3"; + + public static final String CHANNEL_CURRENT_AC1 = "currentAC1"; + public static final String CHANNEL_CURRENT_AC2 = "currentAC2"; + public static final String CHANNEL_CURRENT_AC3 = "currentAC3"; + + public static final String CHANNEL_FREQUENCY_AC1 = "frequencyAC1"; + public static final String CHANNEL_FREQUENCY_AC2 = "frequencyAC2"; + public static final String CHANNEL_FREQUENCY_AC3 = "frequencyAC3"; + public static final String CHANNEL_ENERGY_TODAY = "energyToday"; public static final String CHANNEL_ENERGY_TOTAL = "energyTotal"; + + public static final String CHANNEL_TEMPERATURE = "temperature"; + + public static final String CHANNEL_HOURS_TOTAL = "hoursTotal"; } diff --git a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterMessage.java b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterMessage.java index a7d8fb5b6..4b06e4eb3 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterMessage.java +++ b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/OmnikInverterMessage.java @@ -87,23 +87,23 @@ public class OmnikInverterMessage { } /** - * @return the amperage for AC1 + * @return the current for AC1 */ - public double getAmperageAC1() { + public double getCurrentAC1() { return getShort(45, 10); } /** - * @return the amperage for AC2 + * @return the current for AC2 */ - public double getAmperageAC2() { + public double getCurrentAC2() { return getShort(47, 10); } /** - * @return the amperage for AC3 + * @return the current for AC3 */ - public double getAmperageAC3() { + public double getCurrentAC3() { return getShort(49, 10); } @@ -141,7 +141,7 @@ public class OmnikInverterMessage { * @deprecated */ public double getPower() { - return getShort(59, 1); + return getPowerAC1(); } /** @@ -194,4 +194,20 @@ public class OmnikInverterMessage { public double getTotalEnergy() { return getInt(71, 10); } + + /** + * + * @return the current temperature in Celsius + */ + public double getTemperature() { + return getShort(31, 10); + } + + /** + * + * @return the total amount of hours the inverter produced energy + */ + public double getHoursTotal() { + return getInt(75, 1); + } } diff --git a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/handler/OmnikInverterHandler.java b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/handler/OmnikInverterHandler.java index 20702752e..d1f5f8e3b 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/handler/OmnikInverterHandler.java +++ b/bundles/org.openhab.binding.omnikinverter/src/main/java/org/openhab/binding/omnikinverter/internal/handler/OmnikInverterHandler.java @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit; import javax.measure.quantity.ElectricCurrent; import javax.measure.quantity.ElectricPotential; +import javax.measure.quantity.Frequency; import javax.measure.quantity.Power; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -30,6 +31,7 @@ import org.openhab.binding.omnikinverter.internal.OmnikInverterBindingConstants; import org.openhab.binding.omnikinverter.internal.OmnikInverterConfiguration; import org.openhab.binding.omnikinverter.internal.OmnikInverterMessage; import org.openhab.core.library.types.QuantityType; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -92,6 +94,9 @@ public class OmnikInverterHandler extends BaseThingHandler { updateStatus(ThingStatus.ONLINE); + /** + * AC + **/ QuantityType powerQuantity = new QuantityType<>(message.getPower(), Units.WATT); updateState(OmnikInverterBindingConstants.CHANNEL_POWER, powerQuantity); @@ -104,6 +109,43 @@ public class OmnikInverterHandler extends BaseThingHandler { QuantityType powerQuantity3 = new QuantityType<>(message.getPowerAC3(), Units.WATT); updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC3, powerQuantity3); + QuantityType voltageQuantity1 = new QuantityType<>(message.getVoltageAC1(), + Units.VOLT); + updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_AC1, voltageQuantity1); + + QuantityType voltageQuantity2 = new QuantityType<>(message.getVoltageAC2(), + Units.VOLT); + updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_AC2, voltageQuantity2); + + QuantityType voltageQuantity3 = new QuantityType<>(message.getVoltageAC3(), + Units.VOLT); + updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_AC3, voltageQuantity3); + + QuantityType currentQuantity1 = new QuantityType<>(message.getCurrentAC1(), + Units.AMPERE); + updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_AC1, currentQuantity1); + + QuantityType currentQuantity2 = new QuantityType<>(message.getCurrentAC2(), + Units.AMPERE); + updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_AC2, currentQuantity2); + + QuantityType currentQuantity3 = new QuantityType<>(message.getCurrentAC3(), + Units.AMPERE); + updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_AC3, currentQuantity3); + + QuantityType frequencyQuantity1 = new QuantityType<>(message.getFrequencyAC1(), Units.HERTZ); + updateState(OmnikInverterBindingConstants.CHANNEL_FREQUENCY_AC1, frequencyQuantity1); + + QuantityType frequencyQuantity2 = new QuantityType<>(message.getFrequencyAC2(), Units.HERTZ); + updateState(OmnikInverterBindingConstants.CHANNEL_FREQUENCY_AC2, frequencyQuantity2); + + QuantityType frequencyQuantity3 = new QuantityType<>(message.getFrequencyAC3(), Units.HERTZ); + updateState(OmnikInverterBindingConstants.CHANNEL_FREQUENCY_AC3, frequencyQuantity3); + + /** + * PV + **/ + QuantityType pvAmp1 = new QuantityType<>(message.getCurrentPV1(), Units.AMPERE); updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV1, pvAmp1); @@ -122,11 +164,20 @@ public class OmnikInverterHandler extends BaseThingHandler { QuantityType pvVoltage3 = new QuantityType<>(message.getVoltagePV3(), Units.VOLT); updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV3, pvVoltage3); + /** + * MISC + **/ updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TODAY, new QuantityType<>(message.getEnergyToday(), Units.KILOWATT_HOUR)); updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TOTAL, new QuantityType<>(message.getTotalEnergy(), Units.KILOWATT_HOUR)); + + updateState(OmnikInverterBindingConstants.CHANNEL_TEMPERATURE, + new QuantityType<>(message.getTemperature(), SIUnits.CELSIUS)); + + updateState(OmnikInverterBindingConstants.CHANNEL_HOURS_TOTAL, + new QuantityType<>(message.getHoursTotal(), Units.HOUR)); } } catch (UnknownHostException | NoRouteToHostException | ConnectException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); diff --git a/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/i18n/omnikinverter.properties b/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/i18n/omnikinverter.properties index 55276ae52..0ab0fc4b5 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/i18n/omnikinverter.properties +++ b/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/i18n/omnikinverter.properties @@ -7,6 +7,42 @@ addon.omnikinverter.description = This is the binding for the Omnik solar grid i thing-type.omnikinverter.omnik.label = OmnikInverter Binding Thing thing-type.omnikinverter.omnik.description = Thing for OmnikInverter Binding +thing-type.omnikinverter.omnik.channel.currentAC1.label = Current AC1 +thing-type.omnikinverter.omnik.channel.currentAC1.description = The current for output channel 1 +thing-type.omnikinverter.omnik.channel.currentAC2.label = Current AC2 +thing-type.omnikinverter.omnik.channel.currentAC2.description = The current for output channel 2 +thing-type.omnikinverter.omnik.channel.currentAC3.label = Current AC3 +thing-type.omnikinverter.omnik.channel.currentAC3.description = The current for output channel 3 +thing-type.omnikinverter.omnik.channel.currentPV1.label = Current PV1 +thing-type.omnikinverter.omnik.channel.currentPV1.description = The current on input string 1 +thing-type.omnikinverter.omnik.channel.currentPV2.label = Current PV2 +thing-type.omnikinverter.omnik.channel.currentPV2.description = The current on input string 2 +thing-type.omnikinverter.omnik.channel.currentPV3.label = Current PV3 +thing-type.omnikinverter.omnik.channel.currentPV3.description = The current on input string 3 +thing-type.omnikinverter.omnik.channel.frequencyAC1.label = Frequency AC1 +thing-type.omnikinverter.omnik.channel.frequencyAC1.description = The frequency for output channel 1 +thing-type.omnikinverter.omnik.channel.frequencyAC2.label = Frequency AC2 +thing-type.omnikinverter.omnik.channel.frequencyAC2.description = The frequency for output channel 2 +thing-type.omnikinverter.omnik.channel.frequencyAC3.label = Frequency AC3 +thing-type.omnikinverter.omnik.channel.frequencyAC3.description = The frequency for output channel 3 +thing-type.omnikinverter.omnik.channel.powerAC1.label = Instantaneous Power AC1 +thing-type.omnikinverter.omnik.channel.powerAC1.description = The instantaneous power for output channel 1 +thing-type.omnikinverter.omnik.channel.powerAC2.label = Instantaneous Power AC2 +thing-type.omnikinverter.omnik.channel.powerAC2.description = The instantaneous power for output channel 2 +thing-type.omnikinverter.omnik.channel.powerAC3.label = Instantaneous Power AC3 +thing-type.omnikinverter.omnik.channel.powerAC3.description = The instantaneous power for output channel 3 +thing-type.omnikinverter.omnik.channel.voltageAC1.label = Voltage AC1 +thing-type.omnikinverter.omnik.channel.voltageAC1.description = The voltage for output channel 1 +thing-type.omnikinverter.omnik.channel.voltageAC2.label = Voltage AC2 +thing-type.omnikinverter.omnik.channel.voltageAC2.description = The voltage for output channel 2 +thing-type.omnikinverter.omnik.channel.voltageAC3.label = Voltage AC3 +thing-type.omnikinverter.omnik.channel.voltageAC3.description = The voltage for output channel 3 +thing-type.omnikinverter.omnik.channel.voltagePV1.label = Voltage PV1 +thing-type.omnikinverter.omnik.channel.voltagePV1.description = The voltage on the input string 1 +thing-type.omnikinverter.omnik.channel.voltagePV2.label = Voltage PV2 +thing-type.omnikinverter.omnik.channel.voltagePV2.description = The voltage on the input string 2 +thing-type.omnikinverter.omnik.channel.voltagePV3.label = Voltage PV3 +thing-type.omnikinverter.omnik.channel.voltagePV3.description = The voltage on the input string 3 # thing types config @@ -19,9 +55,19 @@ thing-type.config.omnikinverter.omnik.serial.description = The serial of the Omn # channel types +channel-type.omnikinverter.currentAC.label = Current AC +channel-type.omnikinverter.currentPV.label = Current PV channel-type.omnikinverter.energyToday.label = Energy Today channel-type.omnikinverter.energyToday.description = The amount of energy generated today channel-type.omnikinverter.energyTotal.label = Total Generated Energy channel-type.omnikinverter.energyTotal.description = The amount of generated energy in total +channel-type.omnikinverter.frequencyAC.label = Frequency AC +channel-type.omnikinverter.hoursTotal.label = Running Hours +channel-type.omnikinverter.hoursTotal.description = The total amount of running hours channel-type.omnikinverter.power.label = Instantaneous Power -channel-type.omnikinverter.power.description = The instantaneous power generation +channel-type.omnikinverter.power.description = Deprecated! See channel 'powerAC1' +channel-type.omnikinverter.powerAC.label = Instantaneous Power AC +channel-type.omnikinverter.temperature.label = Current Temperature +channel-type.omnikinverter.temperature.description = The temperature from the sensor +channel-type.omnikinverter.voltageAC.label = Voltage AC +channel-type.omnikinverter.voltagePV.label = Voltage PV diff --git a/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/thing/thing-types.xml index 21de16074..e8010521f 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.omnikinverter/src/main/resources/OH-INF/thing/thing-types.xml @@ -9,20 +9,85 @@ Thing for OmnikInverter Binding + - - - - - - - - - + + + The instantaneous power for output channel 1 + + + + The instantaneous power for output channel 2 + + + + The instantaneous power for output channel 3 + + + + The voltage for output channel 1 + + + + The voltage for output channel 2 + + + + The voltage for output channel 3 + + + + The current for output channel 1 + + + + The current for output channel 2 + + + + The current for output channel 3 + + + + The frequency for output channel 1 + + + + The frequency for output channel 2 + + + + The frequency for output channel 3 + + + + The current on input string 1 + + + + The current on input string 2 + + + + The current on input string 3 + + + + The voltage on the input string 1 + + + + The voltage on the input string 2 + + + + The voltage on the input string 3 + + + - @@ -39,67 +104,43 @@ The serial of the Omnik inverter's Wifi module. This the number part only. - + Number:Power - The instantaneous power generation for output 1 + Deprecated! See channel 'powerAC1' - + Number:Power - - The instantaneous power generation for output 1 + - - Number:Power - - The instantaneous power generation for output 2 + + Number:ElectricPotential + - - Number:Power - - The instantaneous power generation for output 3 + + Number:ElectricCurrent + - - Number:Current - - The current on input string 1 + + Number:Frequency + + + + + Number:ElectricCurrent + - - Number:Current - - The current on input string 2 - - - - Number:Current - - The current on input string 3 - - - - Number:Voltage - - The voltage on input string 1 - - - - Number:Voltage - - The voltage on input string 2 - - - - Number:Voltage - - The voltage PV3 + + Number:ElectricPotential + @@ -112,7 +153,28 @@ Number:Energy The amount of generated energy in total - - + + Number:Temperature + + The temperature from the sensor + Temperature + + Measurement + Temperature + + + + + Number:Time + + The total amount of running hours + + + + Number:Time + + The total amount of running hours + + diff --git a/bundles/org.openhab.binding.omnikinverter/src/test/java/org/openhab/binding/omnikinverter/internal/test/OmnikInverterMessageTest.java b/bundles/org.openhab.binding.omnikinverter/src/test/java/org/openhab/binding/omnikinverter/internal/test/OmnikInverterMessageTest.java index 83d9e2c22..7446fad3a 100644 --- a/bundles/org.openhab.binding.omnikinverter/src/test/java/org/openhab/binding/omnikinverter/internal/test/OmnikInverterMessageTest.java +++ b/bundles/org.openhab.binding.omnikinverter/src/test/java/org/openhab/binding/omnikinverter/internal/test/OmnikInverterMessageTest.java @@ -55,6 +55,51 @@ public class OmnikInverterMessageTest { assertEquals(-1.0, message.getPowerAC3(), 0.01); } + @Test + public void testGetVoltageAC1() { + assertEquals(236.0, message.getVoltageAC1(), 0.01); + } + + @Test + public void testGetVoltageAC2() { + assertEquals(-0.1, message.getVoltageAC2(), 0.01); + } + + @Test + public void testGetVoltageAC3() { + assertEquals(-0.1, message.getVoltageAC3(), 0.01); + } + + @Test + public void testGetCurrentAC1() { + assertEquals(0.5, message.getCurrentAC1(), 0.01); + } + + @Test + public void testGetCurrentAC2() { + assertEquals(-0.1, message.getCurrentAC2(), 0.01); + } + + @Test + public void testGetCurrentAC3() { + assertEquals(-0.1, message.getCurrentAC3(), 0.01); + } + + @Test + public void testGetFrequencyAC1() { + assertEquals(50.06, message.getFrequencyAC1(), 0.01); + } + + @Test + public void testGetFrequencyAC2() { + assertEquals(-0.01, message.getFrequencyAC2(), 0.01); + } + + @Test + public void testGetFrequencyAC3() { + assertEquals(-0.01, message.getFrequencyAC3(), 0.01); + } + @Test public void testGetCurrentPV1() { assertEquals(0.5, message.getCurrentPV1(), 0.01); @@ -94,4 +139,14 @@ public class OmnikInverterMessageTest { public void testGetEnergyToday() { assertEquals(11.13, message.getEnergyToday(), 0.01); } + + @Test + public void testGetTemperature() { + assertEquals(31.7, message.getTemperature(), 0.01); + } + + @Test + public void testGetHoursTotal() { + assertEquals(17693, message.getHoursTotal(), 0.01); + } }