Skip to content

Commit

Permalink
[iotawatt] add input power-factor and phase
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Rosenberg <prosenb.dev@gmail.com>
  • Loading branch information
PRosenb committed Mar 24, 2024
1 parent 62f285c commit 4bc5416
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
39 changes: 21 additions & 18 deletions bundles/org.openhab.binding.iotawatt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Limitations of this version:
- No authentication support
- Support of IoTaWatt's `Input` and `Output` channels.

Supported values on the `Input` channels:

- Power consumption
- Voltage
- AC Frequency

## Supported Things

IoTaWatt binding supports one Thing called `iotawatt`.
Expand All @@ -33,11 +27,16 @@ It detects configured inputs and creates channels for them.

## Channels

| Channel | Type | Read/Write | Description |
|-------------------|--------------------------|------------|-------------------------------|
| Power Consumption | Number:Power | RO | The current power consumption |
| Voltage | Number:ElectricPotential | RO | The current voltage |
| Frequency | Number:Frequency | RO | The current AC frequency |
| Channel | Type | Read/Write | Description |
|---------------------|--------------------------|------------|---------------------------------|
| Amps | Number:Power | RO | The current amps |
| Frequency | Number:Frequency | RO | The current AC frequency |
| Power Factor | Number:Dimensionless | RO | The current power factor |
| Apparent Power | Number:Power | RO | The current apparent power |
| Reactive Power | Number:Power | RO | The current reactive power |
| Reactive Power hour | Number:Power | RO | The current reactive power hour |
| Voltage | Number:ElectricPotential | RO | The current voltage |
| Power Consumption | Number:Power | RO | The current power consumption |

## Example configuration

Expand All @@ -46,27 +45,31 @@ It detects configured inputs and creates channels for them.
```java
Thing iotawatt:iotawatt:iotawatt1 "IoTaWatt 1" [ hostname="192.168.1.10" ] {
Channels:
Type watts : input_01#watts "Power Consumption"
Type voltage : input_00#voltage "Voltage"
Type frequency : input_00#frequency "AC Frequency"
Type voltage : input_00#voltage "Voltage"
Type frequency : input_00#frequency "AC Frequency"
Type watts : input_01#watts "Power Consumption"
Type power-factor : input_01#power-factor "Power Factor"
Type phase : input_01#phase "Phase"

Type amps : output_00#Input_1_amps "Amps"
Type frequency : output_01#Input_1_hz "Frequency"
Type power-factor : output_02#Input_1_pf "Power Factor"
Type apparent-power : output_03#Input_1_va "Apparent Power"
Type reactive-power : output_04#Input_1_var "Reactive Power"
Type reactive-power-hour : output_05#Input_1_varh "Reactive Power Hour"
Type voltage : output_06#Input_1_voltage "Voltage"
Type voltage : output_06#Input_1_volts "Voltage"
Type watts : output_07#Input_1_watts "Watts"
}
```

### Items

```java
Number input_watts "Current Watts" { channel="iotawatt:iotawatt:iotawatt1:input_01#watts" }
Number input_voltage "Current Voltage" { channel="iotawatt:iotawatt:iotawatt1:input_00#voltage" }
Number input_frequency "Current AC Frequency" { channel="iotawatt:iotawatt:iotawatt1:input_00#frequency" }
Number input_watts "Watts" { channel="iotawatt:iotawatt:iotawatt1:input_01#watts" }
Number input_voltage "Voltage" { channel="iotawatt:iotawatt:iotawatt1:input_00#voltage" }
Number input_frequency "AC Frequency" { channel="iotawatt:iotawatt:iotawatt1:input_00#frequency" }
Number input_power_factor "Power Factor" { channel="iotawatt:iotawatt:iotawatt1:input_01#power-factor" }
Number input_phase "Phase" { channel="iotawatt:iotawatt:iotawatt1:input_01#phase" }

Number output_amps "Amps" { channel="iotawatt:iotawatt:iotawatt1:output_00#Input_1_amps" }
Number output_frequency "Frequency" { channel="iotawatt:iotawatt:iotawatt1:output_01#Input_1_hz" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public enum IoTaWattChannelType {
REACTIVE_POWER("reactive-power", "reactive-power", "Number:power", Units.VAR),
REACTIVE_POWER_HOUR("reactive-power-hour", "reactive-power-hour", "Number:Energy", Units.VAR_HOUR),
VOLTAGE("voltage", "voltage", "Number:ElectricPotential", Units.VOLT),
WATTS("watts", "watts", "Number:Power", Units.WATT);// ACTIVE_POWER
WATTS("watts", "watts", "Number:Power", Units.WATT), // ACTIVE_POWER
PHASE("phase", "phase", "Number:Dimensionless", Units.ONE);

/**
* Id of the channel in XML definition channel-type id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public record StatusResponse(@Nullable List<Input> inputs, @Nullable List<Output> outputs) {
public record Input(int channel, @Nullable @SerializedName("Vrms") Float vrms,
@Nullable @SerializedName("Hz") Float hz, @Nullable Float phase,
@Nullable @SerializedName("Watts") Float watts) {
@Nullable @SerializedName("Watts") Float watts, @Nullable @SerializedName("Pf") Float pf) {
}

public record Output(String name, String units, Float value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ private void updateInputs(List<StatusResponse.Input> inputs) {
createAndUpdateInputChannel(channelNumber, input.watts(), IoTaWattChannelType.WATTS);
createAndUpdateInputChannel(channelNumber, input.vrms(), IoTaWattChannelType.VOLTAGE);
createAndUpdateInputChannel(channelNumber, input.hz(), IoTaWattChannelType.FREQUENCY);
createAndUpdateInputChannel(channelNumber, input.pf(), IoTaWattChannelType.POWER_FACTOR);
createAndUpdateInputChannel(channelNumber, input.phase(), IoTaWattChannelType.PHASE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@
<state pattern="%.2f W" readOnly="true">
</state>
</channel-type>
<channel-type id="phase">
<item-type>Number:Dimensionless</item-type>
<label>Phase</label>
<description>The current phase.</description>
<state pattern="%.2f" readOnly="true"/>
</channel-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ void pollDevice_whenAllSupportedInputTypes_updateAllChannels()
final Float hertz = 50.1f;
final Float phase0 = 0.1f;
final Float wattsValue = 1.1f;
final float phase1 = 0.2f;
final Float phase1 = 0.2f;
final Float powerFactor = 0.3f;
when(deviceHandlerCallback.getThingUID()).thenReturn(thingUID);
final List<StatusResponse.Input> inputs = List.of(new StatusResponse.Input(0, voltageRms, hertz, phase0, null),
new StatusResponse.Input(1, null, null, phase1, wattsValue));
final List<StatusResponse.Input> inputs = List.of(
new StatusResponse.Input(0, voltageRms, hertz, phase0, null, null),
new StatusResponse.Input(1, null, null, phase1, wattsValue, powerFactor));
final StatusResponse statusResponse = new StatusResponse(inputs, List.of());
when(ioTaWattClient.fetchStatus()).thenReturn(Optional.of(statusResponse));

Expand All @@ -92,8 +94,12 @@ void pollDevice_whenAllSupportedInputTypes_updateAllChannels()
createState(voltageRms, Units.VOLT));
verify(deviceHandlerCallback).updateState(createInputChannelUID("00", "frequency"),
createState(hertz, Units.HERTZ));
verify(deviceHandlerCallback).updateState(createInputChannelUID("00", "phase"), createState(phase0, Units.ONE));
verify(deviceHandlerCallback).updateState(createInputChannelUID("01", "watts"),
createState(wattsValue, Units.WATT));
verify(deviceHandlerCallback).updateState(createInputChannelUID("01", "phase"), createState(phase1, Units.ONE));
verify(deviceHandlerCallback).updateState(createInputChannelUID("01", "power-factor"),
createState(powerFactor, Units.ONE));
}

@Test
Expand Down

0 comments on commit 4bc5416

Please sign in to comment.