Skip to content

Commit

Permalink
[omnikinverter] feature: Add channels for voltage and current (#11645)
Browse files Browse the repository at this point in the history
Signed-off-by: Hans van den Bogert <[email protected]>
  • Loading branch information
hansbogert authored Dec 15, 2021
1 parent c71e5bd commit 4291729
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 26 deletions.
47 changes: 37 additions & 10 deletions bundles/org.openhab.binding.omnikinverter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ No autodiscovery available

## Channels

| Channel Type Id | Item Type | Description |
| :---------------- | :---------- | :------------ |
| power | Number:Power | The instantaneous power generation |
| energyToday | Number:Energy | The amount of energy generated today |
| energyTotal | Number:Energy | The total amount of energy generated |
| 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 |

## Full Example

Expand All @@ -38,17 +47,35 @@ Thing omnikinverter:omnik:70ecb4f0 "Solar Inverter" [ hostname="igen-wifi.lan",s
### demo.items

```
Number OmnikInverterBindingThing_InstantaneousPower "Solar Power" {channel="omnikinverter:omnik:70ecb4f0:power"}
Number OmnikInverterBindingThing_TotalGeneratedEnergyToday "Solar Energy Today" {channel="omnikinverter:omnik:70ecb4f0:energyToday"}
Number OmnikInverterBindingThing_TotalGeneratedEnergy "Solar Energy Total" {channel="omnikinverter:omnik:70ecb4f0:energyTotal"}
Number:Power OmnikInverterBindingThing_InstantaneousPower "Solar Power" <sun> {channel="omnikinverter:omnik:70ecb4f0:power"}
Number:Power OmnikInverterBindingThing_InstantaneousPower1 "Solar Power 1" <sun> {channel="omnikinverter:omnik:70ecb4f0:powerAC1"}
Number:Power OmnikInverterBindingThing_InstantaneousPower2 "Solar Power 2" <sun> {channel="omnikinverter:omnik:70ecb4f0:powerAC2"}
Number:Power OmnikInverterBindingThing_InstantaneousPower3 "Solar Power 3" <sun> {channel="omnikinverter:omnik:70ecb4f0:powerAC3"}
Number:Voltage OmnikInverterBindingThing_VoltagePV1 "PV Voltage 1" {channel="omnikinverter:omnik:70ecb4f0:voltagePV1"}
Number:Voltage OmnikInverterBindingThing_VoltagePV2 "PV Voltage 2" {channel="omnikinverter:omnik:70ecb4f0:voltagePV2"}
Number:Voltage OmnikInverterBindingThing_VoltagePV3 "PV Voltage 3" {channel="omnikinverter:omnik:70ecb4f0:voltagePV3"}
Number:Current OmnikInverterBindingThing_CurrentPV1 "PV current 1" {channel="omnikinverter:omnik:70ecb4f0:currentPV1"}
Number:Current OmnikInverterBindingThing_CurrentPV2 "PV current 2" {channel="omnikinverter:omnik:70ecb4f0:currentPV2"}
Number:Current OmnikInverterBindingThing_CurrentPV3 "PV current 3" {channel="omnikinverter:omnik:70ecb4f0:currentPV3"}
Number:Energy OmnikInverterBindingThing_TotalGeneratedEnergyToday "Solar Energy Today" <sun> {channel="omnikinverter:omnik:70ecb4f0:energyToday"}
Number:Energy OmnikInverterBindingThing_TotalGeneratedEnergy "Solar Energy Total" {channel="omnikinverter:omnik:70ecb4f0:energyTotal"}
```

### Sitemap

```
Text item=OmnikInverterBindingThing_InstantaneousPower
Text item=OmnikInverterBindingThing_TotalGeneratedEnergyToday label="Today"
Text item=OmnikInverterBindingThing_TotalGeneratedEnergy label="Total"
Text item=OmnikInverterBindingThing_InstantaneousPower1
Text item=OmnikInverterBindingThing_InstantaneousPower2
Text item=OmnikInverterBindingThing_InstantaneousPower3
Text item=OmnikInverterBindingThing_VoltagePV1
Text item=OmnikInverterBindingThing_VoltagePV2
Text item=OmnikInverterBindingThing_VoltagePV3
Text item=OmnikInverterBindingThing_CurrentPV1
Text item=OmnikInverterBindingThing_CurrentPV2
Text item=OmnikInverterBindingThing_CurrentPV3
Text item=OmnikInverterBindingThing_TotalGeneratedEnergyToday
Text item=OmnikInverterBindingThing_TotalGeneratedEnergy
```

## References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ public class OmnikInverterBindingConstants {
public static final ThingTypeUID THING_TYPE_OMNIK = new ThingTypeUID(BINDING_ID, "omnik");

// List of all Channel ids
public static final String CHANNEL_CURRENT_PV1 = "currentPV1";
public static final String CHANNEL_CURRENT_PV2 = "currentPV2";
public static final String CHANNEL_CURRENT_PV3 = "currentPV3";

public static final String CHANNEL_VOLTAGE_PV1 = "voltagePV1";
public static final String CHANNEL_VOLTAGE_PV2 = "voltagePV2";
public static final String CHANNEL_VOLTAGE_PV3 = "voltagePV3";

public static final String CHANNEL_POWER = "power";
public static final String CHANNEL_POWER_AC1 = "powerAC1";
public static final String CHANNEL_POWER_AC2 = "powerAC2";
public static final String CHANNEL_POWER_AC3 = "powerAC3";

public static final String CHANNEL_ENERGY_TODAY = "energyToday";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,168 @@ public OmnikInverterMessage(byte[] b) {
this.bytes = b;
}

public double getPower() {
private double getShort(int offset, int compensationFactor) {
ByteBuffer buf = ByteBuffer.allocate(2);
buf.put(bytes, 59, 2);
buf.put(bytes, offset, 2);
buf.rewind();
return (double) buf.getShort() / compensationFactor;
}

private double getInt(int offset, int compensationFactor) {
ByteBuffer buf = ByteBuffer.allocate(4);
buf.put(bytes, offset, 4);
buf.rewind();
return buf.getShort();
return (double) buf.getInt() / compensationFactor;
}

/**
* @return the voltage for PV1
*/
public double getVoltagePV1() {
return getShort(33, 10);
}

/**
* @return the voltage for PV2
*/
public double getVoltagePV2() {
return getShort(35, 10);
}

/**
* @return the voltage for PV3
*/
public double getVoltagePV3() {
return getShort(37, 10);
}

/**
* @return the amperage for PV1
*/
public double getCurrentPV1() {
return getShort(39, 10);
}

/**
* @return the amperage for PV2
*/
public double getCurrentPV2() {
return getShort(41, 10);
}

/**
* @return the amperage for PV3
*/
public double getCurrentPV3() {
return getShort(43, 10);
}

/**
* @return the amperage for AC1
*/
public double getAmperageAC1() {
return getShort(45, 10);
}

/**
* @return the amperage for AC2
*/
public double getAmperageAC2() {
return getShort(47, 10);
}

/**
* @return the amperage for AC3
*/
public double getAmperageAC3() {
return getShort(49, 10);
}

/**
* @return the voltage for AC1
*/
public double getVoltageAC1() {
return getShort(51, 10);
}

/**
* @return the voltage for AC2
*/
public double getVoltageAC2() {
return getShort(53, 10);
}

/**
* @return the voltage for AC3
*/
public double getVoltageAC3() {
return getShort(55, 10);
}

/**
* @return the Frequency for AC1
*/
public double getFrequencyAC1() {
return getShort(57, 100);
}

/**
* @return the power for AC1
*
* @deprecated
*/
public double getPower() {
return getShort(59, 1);
}

/**
* @return the power for AC1
*/
public double getPowerAC1() {
return getShort(59, 1);
}

/**
* @return the Frequency for AC2
*/
public double getFrequencyAC2() {
return getShort(61, 100);
}

/**
* @return the power for AC2
*/
public double getPowerAC2() {
return getShort(63, 1);
}

/**
* @return the Frequency for AC3
*/
public double getFrequencyAC3() {
return getShort(65, 100);
}

/**
* @return the power for AC3
*/
public double getPowerAC3() {
return getShort(67, 1);
}

/**
*
* @return the total energy outputted this day in kWh
*/
public double getEnergyToday() {
ByteBuffer buf = ByteBuffer.allocate(2);
buf.put(bytes, 69, 2);
buf.rewind();
return (buf.getShort() / 100.0);
return getShort(69, 100);
}

/**
*
* @return the total energy outputted in kWh
*/
public double getTotalEnergy() {
ByteBuffer buf = ByteBuffer.allocate(4);
buf.put(bytes, 71, 4);
buf.rewind();
return buf.getInt() / 10.0;
return getInt(71, 10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import javax.measure.quantity.ElectricCurrent;
import javax.measure.quantity.ElectricPotential;
import javax.measure.quantity.Power;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -58,10 +60,9 @@ public OmnikInverterHandler(Thing thing) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (OmnikInverterBindingConstants.CHANNEL_POWER.equals(channelUID.getId())) {
if (command instanceof RefreshType) {
updateData();
}
// All channels depend on data gotten from `updateData()`
if (command instanceof RefreshType) {
updateData();
}
}

Expand Down Expand Up @@ -94,6 +95,33 @@ private void updateData() {
QuantityType<Power> powerQuantity = new QuantityType<>(message.getPower(), Units.WATT);
updateState(OmnikInverterBindingConstants.CHANNEL_POWER, powerQuantity);

QuantityType<Power> powerQuantity1 = new QuantityType<>(message.getPowerAC1(), Units.WATT);
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC1, powerQuantity1);

QuantityType<Power> powerQuantity2 = new QuantityType<>(message.getPowerAC2(), Units.WATT);
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC2, powerQuantity2);

QuantityType<Power> powerQuantity3 = new QuantityType<>(message.getPowerAC3(), Units.WATT);
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC3, powerQuantity3);

QuantityType<ElectricCurrent> pvAmp1 = new QuantityType<>(message.getCurrentPV1(), Units.AMPERE);
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV1, pvAmp1);

QuantityType<ElectricCurrent> pvAmp2 = new QuantityType<>(message.getCurrentPV2(), Units.AMPERE);
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV2, pvAmp2);

QuantityType<ElectricCurrent> pvAmp3 = new QuantityType<>(message.getCurrentPV3(), Units.AMPERE);
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV3, pvAmp3);

QuantityType<ElectricPotential> pvVoltage1 = new QuantityType<>(message.getVoltagePV1(), Units.VOLT);
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV1, pvVoltage1);

QuantityType<ElectricPotential> pvVoltage2 = new QuantityType<>(message.getVoltagePV2(), Units.VOLT);
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV2, pvVoltage2);

QuantityType<ElectricPotential> pvVoltage3 = new QuantityType<>(message.getVoltagePV3(), Units.VOLT);
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV3, pvVoltage3);

updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TODAY,
new QuantityType<>(message.getEnergyToday(), Units.KILOWATT_HOUR));

Expand Down
Loading

0 comments on commit 4291729

Please sign in to comment.