From ac32260f22bb05be007c6fa27c71500d7d1d4838 Mon Sep 17 00:00:00 2001 From: Hannes Spenger Date: Wed, 9 Feb 2022 00:02:40 +0100 Subject: [PATCH] [fronius] Added Ohmpilot thing and channel realpowersum for thing meter (#11835) * Added support for fronius ohmpilot and added smart meter power sum. Signed-off-by: urmet0 --- bundles/org.openhab.binding.fronius/README.md | 45 +++++- .../internal/FroniusBindingConstants.java | 11 +- .../internal/FroniusHandlerFactory.java | 5 + .../internal/api/OhmpilotRealtimeBodyDTO.java | 37 +++++ .../api/OhmpilotRealtimeBodyDataDTO.java | 87 +++++++++++ .../api/OhmpilotRealtimeDetailsDTO.java | 74 ++++++++++ .../api/OhmpilotRealtimeResponseDTO.java | 37 +++++ .../internal/handler/FroniusMeterHandler.java | 7 +- .../handler/FroniusOhmpilotHandler.java | 137 ++++++++++++++++++ .../resources/OH-INF/i18n/fronius.properties | 11 ++ .../resources/OH-INF/thing/thing-types.xml | 57 ++++++-- 11 files changed, 490 insertions(+), 18 deletions(-) create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java diff --git a/bundles/org.openhab.binding.fronius/README.md b/bundles/org.openhab.binding.fronius/README.md index fba833df0..4effa0f87 100644 --- a/bundles/org.openhab.binding.fronius/README.md +++ b/bundles/org.openhab.binding.fronius/README.md @@ -10,7 +10,9 @@ It supports Fronius inverters and Fronius Smart Meter. Tested with a Fronius Sym | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `bridge` | The Bridge | | `powerinverter` | Fronius Galvo, Symo and other Fronius inverters in combination with the Fronius Datamanager 1.0 / 2.0 or Fronius Datalogger. You can add multiple inverters that depend on the same datalogger with different device ids. (Default 1) | -| `meter` | Fronius Smart Meter. You can add multiple smart meters with different device ids. (The default id = 0) | +| `meter` | Fronius Smart Meter. You can add multiple smart meters with different device ids. (The default id = 0) +| `ohmpilot` | Fronius Ohmpilot. (The default id = 0) + ## Discovery @@ -18,7 +20,7 @@ There is no discovery implemented. You have to create your things manually and s ## Binding Configuration -The binding has no configuration options, all configuration is done at `bridge`, `powerinverter` or `meter` level. +The binding has no configuration options, all configuration is done at `bridge`, `powerinverter`, `meter` or `ohmpilot` level. ## Thing Configuration @@ -41,6 +43,12 @@ The binding has no configuration options, all configuration is done at `bridge`, | ---------- | ----------------------------------------------- | | `deviceId` | The identifier of your smart meter (Default: 0) | +### Ohmpilot Thing Configuration + +| Parameter | Description | +| ---------- | ----------------------------------------------- | +| `deviceId` | The identifier of your ohmpilot (Default: 0) | + ## Channels ### Channels for `powerinverter` Thing @@ -77,6 +85,7 @@ The binding has no configuration options, all configuration is done at `bridge`, | `powerrealphase1` | Number:Power | Real Power on Phase 1 | | `powerrealphase2` | Number:Power | Real Power on Phase 2 | | `powerrealphase3` | Number:Power | Real Power on Phase 3 | +| `powerrealsum` | Number:Power | Real Power summed up | | `powerfactorphase1` | Number | Power Factor on Phase 1 | | `powerfactorphase2` | Number | Power Factor on Phase 2 | | `powerfactorphase3` | Number | Power Factor on Phase 3 | @@ -85,16 +94,33 @@ The binding has no configuration options, all configuration is done at `bridge`, | | +### Channels for `ohmpilot` Thing + +| Channel ID | Item Type | Description | +| ----------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `energyrealsumconsumed` | Number:Energy | Real Energy consumed | +| `powerrealsum` | Number:Power | Real Power | +| `temperaturechannel1` | Number:Temperature | Temperature | +| `errorcode` | Number | Device error code | +| `statecode` | Number | Device state code
`0` up and running
`1` keep minimum temperature
`2` legionella protection
`3` critical fault
`4` fault
`5` boost mode | +| | ## Properties -The `meter` thing has the following properties: +### The `meter` thing has the following properties: | Property | Description | | -------- | ------------------------------ | -| `model` | The model name of the meter | -| `serial` | The serial number of the meter | +| `modelId` | The model name of the meter | +| `serialNumber` | The serial number of the meter | + +### The `ohmpilot` thing has the following property: + +| Property | Description | +| -------- | ------------------------------ | +| `modelId` | The model name of the ohmpilot | +| `serialNumber` | The serial number of the ohmpilot | ## Full Example @@ -104,6 +130,7 @@ demo.things: Bridge fronius:bridge:mybridge [hostname="192.168.66.148", refreshInterval=5] { Thing powerinverter myinverter [deviceId=1] Thing meter mymeter [deviceId=0] + Thing ohmpilot myohmpilot [deviceId=0] } ``` @@ -136,9 +163,17 @@ Number:Voltage Meter_VoltagePhase3 { channel="fronius:meter:mybridge:mymeter:vol Number:Power Meter_PowerPhase1 { channel="fronius:meter:mybridge:mymeter:powerrealphase1" } Number:Power Meter_PowerPhase2 { channel="fronius:meter:mybridge:mymeter:powerrealphase2" } Number:Power Meter_PowerPhase3 { channel="fronius:meter:mybridge:mymeter:powerrealphase3" } +Number:Power Meter_PowerSum { channel="fronius:meter:mybridge:mymeter:powerrealsum" } Number Meter_PowerFactorPhase1 { channel="fronius:meter:mybridge:mymeter:powerfactorphase1" } Number Meter_PowerFactorPhase2 { channel="fronius:meter:mybridge:mymeter:powerfactorphase2" } Number Meter_PowerFactorPhase3 { channel="fronius:meter:mybridge:mymeter:powerfactorphase3" } Number:Energy Meter_EnergyConsumed { channel="fronius:meter:mybridge:mymeter:energyrealsumconsumed" } Number:Energy Meter_EnergyProduced { channel="fronius:meter:mybridge:mymeter:energyrealsumproduced" } + +Number:Energy Ohmpilot_EnergyConsumed { channel="fronius:ohmpilot:mybridge:myohmpilot:energyrealsumconsumed" } +Number:Power Ohmpilot_PowerSum { channel="fronius:ohmpilot:mybridge:myohmpilot:powerrealsum" } +Number:Temperature Ohmpilot_Temperature { channel="fronius:ohmpilot:mybridge:myohmpilot:temperaturechannel1" } +Number Ohmpilot_State { channel="fronius:ohmpilot:mybridge:myohmpilot:statecode" } +Number Ohmpilot_Errorcode { channel="fronius:ohmpilot:mybridge:myohmpilot:errorcode" } + ``` diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java index 86fa3cf6b..2067ec250 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java @@ -22,6 +22,7 @@ import org.openhab.core.thing.ThingTypeUID; * @author Thomas Rokohl - Initial contribution * @author Peter Schraffl - Added device status and error status channels * @author Thomas Kordelle - Added inverter power, battery state of charge and PV solar yield + * @author Hannes Spenger - Added ohmpilot & meter power sum */ @NonNullByDefault public class FroniusBindingConstants { @@ -32,6 +33,7 @@ public class FroniusBindingConstants { public static final ThingTypeUID THING_TYPE_INVERTER = new ThingTypeUID(BINDING_ID, "powerinverter"); public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge"); public static final ThingTypeUID THING_TYPE_METER = new ThingTypeUID(BINDING_ID, "meter"); + public static final ThingTypeUID THING_TYPE_OHMPILOT = new ThingTypeUID(BINDING_ID, "ohmpilot"); // List of all Channel ids public static final String INVERTER_DATA_CHANNEL_DAY_ENERGY = "inverterdatachanneldayenergy"; @@ -49,8 +51,6 @@ public class FroniusBindingConstants { public static final String POWER_FLOW_P_LOAD = "powerflowchannelpload"; public static final String POWER_FLOW_P_AKKU = "powerflowchannelpakku"; public static final String POWER_FLOW_P_PV = "powerflowchannelppv"; - public static final String METER_MODEL = "model"; - public static final String METER_SERIAL = "serial"; public static final String METER_ENABLE = "enable"; public static final String METER_LOCATION = "location"; public static final String METER_CURRENT_AC_PHASE_1 = "currentacphase1"; @@ -62,11 +62,17 @@ public class FroniusBindingConstants { public static final String METER_POWER_PHASE_1 = "powerrealphase1"; public static final String METER_POWER_PHASE_2 = "powerrealphase2"; public static final String METER_POWER_PHASE_3 = "powerrealphase3"; + public static final String METER_POWER_SUM = "powerrealsum"; public static final String METER_POWER_FACTOR_PHASE_1 = "powerfactorphase1"; public static final String METER_POWER_FACTOR_PHASE_2 = "powerfactorphase2"; public static final String METER_POWER_FACTOR_PHASE_3 = "powerfactorphase3"; public static final String METER_ENERGY_REAL_SUM_CONSUMED = "energyrealsumconsumed"; public static final String METER_ENERGY_REAL_SUM_PRODUCED = "energyrealsumproduced"; + public static final String OHMPILOT_POWER_REAL_SUM = "powerrealsum"; + public static final String OHMPILOT_ENERGY_REAL_SUM_CONSUMED = "energyrealsumconsumed"; + public static final String OHMPILOT_ENERGY_SENSOR_TEMPERATURE_CHANNEL_1 = "temperaturechannel1"; + public static final String OHMPILOT_ERROR_CODE = "errorcode"; + public static final String OHMPILOT_STATE_CODE = "statecode"; /* * part of POWERFLOW_REALTIME_DATA using Symo Gen24 @@ -86,4 +92,5 @@ public class FroniusBindingConstants { public static final String INVERTER_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%&DataCollection=CommonInverterData"; public static final String POWERFLOW_REALTIME_DATA = "http://%IP%/solar_api/v1/GetPowerFlowRealtimeData.fcgi"; public static final String METER_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%&DataCollection=MeterRealtimeData"; + public static final String OHMPILOT_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetOhmPilotRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%"; } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHandlerFactory.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHandlerFactory.java index 211419978..15fea1610 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHandlerFactory.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHandlerFactory.java @@ -19,6 +19,7 @@ import java.util.Set; import org.openhab.binding.fronius.internal.handler.FroniusBridgeHandler; import org.openhab.binding.fronius.internal.handler.FroniusMeterHandler; +import org.openhab.binding.fronius.internal.handler.FroniusOhmpilotHandler; import org.openhab.binding.fronius.internal.handler.FroniusSymoInverterHandler; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; @@ -33,6 +34,7 @@ import org.osgi.service.component.annotations.Component; * handlers. * * @author Thomas Rokohl - Initial contribution + * @author Hannes Spenger - Added ohmpilot */ @Component(service = ThingHandlerFactory.class, configurationPid = "binding.fronius") public class FroniusHandlerFactory extends BaseThingHandlerFactory { @@ -44,6 +46,7 @@ public class FroniusHandlerFactory extends BaseThingHandlerFactory { add(THING_TYPE_INVERTER); add(THING_TYPE_BRIDGE); add(THING_TYPE_METER); + add(THING_TYPE_OHMPILOT); } }; @@ -62,6 +65,8 @@ public class FroniusHandlerFactory extends BaseThingHandlerFactory { return new FroniusBridgeHandler((Bridge) thing); } else if (thingTypeUID.equals(THING_TYPE_METER)) { return new FroniusMeterHandler(thing); + } else if (thingTypeUID.equals(THING_TYPE_OHMPILOT)) { + return new FroniusOhmpilotHandler(thing); } return null; } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java new file mode 100644 index 000000000..7e31ebd52 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeBody} is responsible for storing + * the "body" node of the JSON response + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeBodyDTO { + @SerializedName("Data") + private OhmpilotRealtimeBodyDataDTO data; + + public OhmpilotRealtimeBodyDataDTO getData() { + if (data == null) { + data = new OhmpilotRealtimeBodyDataDTO(); + } + return data; + } + + public void setData(OhmpilotRealtimeBodyDataDTO data) { + this.data = data; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java new file mode 100644 index 000000000..db8057ab9 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeBodyData} is responsible for storing + * the "data" node of the JSON response + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeBodyDataDTO { + @SerializedName("Details") + private OhmpilotRealtimeDetailsDTO details; + @SerializedName("EnergyReal_WAC_Sum_Consumed") + private double energyRealWACSumConsumed; + @SerializedName("PowerReal_PAC_Sum") + private double powerPACSum; + @SerializedName("Temperature_Channel_1") + private double temperatureChannel1; + @SerializedName("CodeOfError") + private int errorCode; + @SerializedName("CodeOfState") + private int stateCode; + + public OhmpilotRealtimeDetailsDTO getDetails() { + if (details == null) { + details = new OhmpilotRealtimeDetailsDTO(); + } + return details; + } + + public void setDetails(OhmpilotRealtimeDetailsDTO details) { + this.details = details; + } + + public double getEnergyRealWACSumConsumed() { + return energyRealWACSumConsumed; + } + + public void setEnergyRealWACSumConsumed(double energyRealWACSumConsumed) { + this.energyRealWACSumConsumed = energyRealWACSumConsumed; + } + + public double getPowerPACSum() { + return powerPACSum; + } + + public void setPowerPACSum(double powerPACSum) { + this.powerPACSum = powerPACSum; + } + + public double getTemperatureChannel1() { + return temperatureChannel1; + } + + public void setTemperatureChannel1(double temperatureChannel1) { + this.temperatureChannel1 = temperatureChannel1; + } + + public int getErrorCode() { + return errorCode; + } + + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public int getStateCode() { + return stateCode; + } + + public void setStateCode(int stateCode) { + this.stateCode = stateCode; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java new file mode 100644 index 000000000..e99df5f5e --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeDetails} is responsible for storing + * the "body" node of the JSON response + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeDetailsDTO { + @SerializedName("Hardware") + private String hardware; + @SerializedName("Manufacturer") + private String manufacturer; + @SerializedName("Model") + private String model; + @SerializedName("Serial") + private String serial; + @SerializedName("Software") + private String software; + + public String getHardware() { + return hardware; + } + + public void setHardware(String hardware) { + this.hardware = hardware; + } + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getSerial() { + return serial; + } + + public void setSerial(String serial) { + this.serial = serial; + } + + public String getSoftware() { + return software; + } + + public void setSoftware(String software) { + this.software = software; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java new file mode 100644 index 000000000..f41e7422b --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeResponse} is responsible for storing + * the response from the GetOhmPilotRealtimeData api + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeResponseDTO extends BaseFroniusResponse { + @SerializedName("Body") + private OhmpilotRealtimeBodyDTO body; + + public OhmpilotRealtimeBodyDTO getBody() { + if (body == null) { + body = new OhmpilotRealtimeBodyDTO(); + } + return body; + } + + public void setBody(OhmpilotRealtimeBodyDTO body) { + this.body = body; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java index 36167079c..32bafbf7a 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java @@ -29,6 +29,7 @@ import org.openhab.core.thing.Thing; * * @author Jimmy Tanagra - Initial contribution * @author Thomas Kordelle - Actually constants should be all upper case. + * @author Hannes Spenger - Added getValue for power sum */ public class FroniusMeterHandler extends FroniusBaseThingHandler { @@ -98,6 +99,8 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { return new QuantityType<>(meterRealtimeBodyData.getPowerRealPPhase2(), Units.WATT); case FroniusBindingConstants.METER_POWER_PHASE_3: return new QuantityType<>(meterRealtimeBodyData.getPowerRealPPhase3(), Units.WATT); + case FroniusBindingConstants.METER_POWER_SUM: + return new QuantityType<>(meterRealtimeBodyData.getPowerRealPSum(), Units.WATT); case FroniusBindingConstants.METER_POWER_FACTOR_PHASE_1: return meterRealtimeBodyData.getPowerFactorPhase1(); case FroniusBindingConstants.METER_POWER_FACTOR_PHASE_2: @@ -122,8 +125,8 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { Map properties = editProperties(); - properties.put(FroniusBindingConstants.METER_MODEL, meterRealtimeBodyData.getDetails().getModel()); - properties.put(FroniusBindingConstants.METER_SERIAL, meterRealtimeBodyData.getDetails().getSerial()); + properties.put(Thing.PROPERTY_MODEL_ID, meterRealtimeBodyData.getDetails().getModel()); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, meterRealtimeBodyData.getDetails().getSerial()); updateProperties(properties); } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java new file mode 100644 index 000000000..a0ec42040 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.handler; + +import java.util.Map; + +import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration; +import org.openhab.binding.fronius.internal.FroniusBindingConstants; +import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; +import org.openhab.binding.fronius.internal.api.OhmpilotRealtimeBodyDataDTO; +import org.openhab.binding.fronius.internal.api.OhmpilotRealtimeResponseDTO; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.library.types.QuantityType; +import org.openhab.core.library.unit.Units; +import org.openhab.core.thing.Thing; + +/** + * The {@link FroniusOhmpilotHandler} is responsible for updating the data, which are + * sent to one of the channels. + * + * @author Hannes Spenger - Initial contribution + * + */ +public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { + + private OhmpilotRealtimeBodyDataDTO ohmpilotRealtimeBodyData; + private FroniusBaseDeviceConfiguration config; + + public FroniusOhmpilotHandler(Thing thing) { + super(thing); + } + + @Override + protected String getDescription() { + return "Fronius Ohmpilot"; + } + + @Override + public void refresh(FroniusBridgeConfiguration bridgeConfiguration) { + updateData(bridgeConfiguration, config); + updateChannels(); + updateProperties(); + } + + @Override + public void initialize() { + config = getConfigAs(FroniusBaseDeviceConfiguration.class); + super.initialize(); + } + + /** + * Update the channel from the last data retrieved + * + * @param channelId the id identifying the channel to be updated + * @return the last retrieved data + */ + @Override + protected Object getValue(String channelId) { + if (ohmpilotRealtimeBodyData == null) { + return null; + } + + final String[] fields = channelId.split("#"); + if (fields.length < 1) { + return null; + } + final String fieldName = fields[0]; + + switch (fieldName) { + case FroniusBindingConstants.OHMPILOT_POWER_REAL_SUM: + return new QuantityType<>(ohmpilotRealtimeBodyData.getPowerPACSum(), Units.WATT); + case FroniusBindingConstants.OHMPILOT_ENERGY_REAL_SUM_CONSUMED: + return new QuantityType<>(ohmpilotRealtimeBodyData.getEnergyRealWACSumConsumed(), Units.WATT_HOUR); + case FroniusBindingConstants.OHMPILOT_ENERGY_SENSOR_TEMPERATURE_CHANNEL_1: + return new QuantityType<>(ohmpilotRealtimeBodyData.getTemperatureChannel1(), Units.KELVIN); + case FroniusBindingConstants.OHMPILOT_STATE_CODE: + return new DecimalType(ohmpilotRealtimeBodyData.getStateCode()); + case FroniusBindingConstants.OHMPILOT_ERROR_CODE: + return new DecimalType(ohmpilotRealtimeBodyData.getErrorCode()); + + default: + break; + } + + return null; + } + + private void updateProperties() { + if (ohmpilotRealtimeBodyData == null) { + return; + } + + Map properties = editProperties(); + + properties.put(Thing.PROPERTY_MODEL_ID, ohmpilotRealtimeBodyData.getDetails().getModel()); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, ohmpilotRealtimeBodyData.getDetails().getSerial()); + + updateProperties(properties); + } + + /** + * Get new data + */ + private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusBaseDeviceConfiguration config) { + OhmpilotRealtimeResponseDTO ohmpilotRealtimeResponse = getOhmpilotRealtimeData(bridgeConfiguration.hostname, + config.deviceId); + if (ohmpilotRealtimeResponse == null) { + ohmpilotRealtimeBodyData = null; + } else { + ohmpilotRealtimeBodyData = ohmpilotRealtimeResponse.getBody().getData(); + } + } + + /** + * Make the OhmpilotRealtimeData request + * + * @param ip address of the device + * @param deviceId of the device + * @return {OhmpilotRealtimeResponse} the object representation of the json response + */ + private OhmpilotRealtimeResponseDTO getOhmpilotRealtimeData(String ip, int deviceId) { + String location = FroniusBindingConstants.OHMPILOT_REALTIME_DATA_URL.replace("%IP%", + (ip != null ? ip.trim() : "")); + location = location.replace("%DEVICEID%", Integer.toString(deviceId)); + return collectDataFormUrl(OhmpilotRealtimeResponseDTO.class, location); + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/i18n/fronius.properties b/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/i18n/fronius.properties index 8a605c9cb..a01821504 100644 --- a/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/i18n/fronius.properties +++ b/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/i18n/fronius.properties @@ -20,9 +20,12 @@ thing-type.fronius.meter.channel.powerfactorphase3.label = Power Factor Phase 3 thing-type.fronius.meter.channel.powerrealphase1.label = Real Power Phase 1 thing-type.fronius.meter.channel.powerrealphase2.label = Real Power Phase 2 thing-type.fronius.meter.channel.powerrealphase3.label = Real Power Phase 3 +thing-type.fronius.meter.channel.powerrealsum.label = Real Power Sum thing-type.fronius.meter.channel.voltageacphase1.label = AC Voltage Phase 1 thing-type.fronius.meter.channel.voltageacphase2.label = AC Voltage Phase 2 thing-type.fronius.meter.channel.voltageacphase3.label = AC Voltage Phase 3 +thing-type.fronius.ohmpilot.label = Fronius Ohmpilot +thing-type.fronius.ohmpilot.description = Fronius Ohmpilot thing-type.fronius.powerinverter.label = Fronius Symo Inverter thing-type.fronius.powerinverter.description = Fronius Symo power inverter thing-type.fronius.powerinverter.channel.powerflowchannelpakku.label = Charge / Discharge of Battery @@ -39,6 +42,8 @@ thing-type.config.fronius.bridge.refreshInterval.label = Refresh Interval thing-type.config.fronius.bridge.refreshInterval.description = Specifies the refresh interval in seconds. thing-type.config.fronius.meter.deviceId.label = Device ID thing-type.config.fronius.meter.deviceId.description = Specific device identifier +thing-type.config.fronius.ohmpilot.deviceId.label = Device ID +thing-type.config.fronius.ohmpilot.deviceId.description = Specific device identifier thing-type.config.fronius.powerinverter.deviceId.label = Device ID thing-type.config.fronius.powerinverter.deviceId.description = Specific device identifier @@ -69,6 +74,12 @@ channel-type.fronius.meter_location.label = Location channel-type.fronius.meter_location.description = Meter Location Code channel-type.fronius.meter_powerfactor.label = Power Factor channel-type.fronius.meter_powerreal.label = Power +channel-type.fronius.ohmpilot_energy.label = Real Energy Consumed +channel-type.fronius.ohmpilot_energy.description = Total consumed energy [Wh] +channel-type.fronius.ohmpilot_powerreal.label = Real Power Sum +channel-type.fronius.ohmpilot_powerreal.description = Actual power consumption [W] +channel-type.fronius.ohmpilot_temperature.label = Temperature +channel-type.fronius.ohmpilot_temperature.description = Temperature of the PT1000 channel-type.fronius.pAkku.label = Battery Power channel-type.fronius.pAkku.description = Battery Power ( + discharge, - charge ) channel-type.fronius.pGrid.label = Grid Power diff --git a/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/thing/thing-types.xml index fb61c7511..f9b1c2e85 100644 --- a/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.fronius/src/main/resources/OH-INF/thing/thing-types.xml @@ -89,6 +89,9 @@ + + + @@ -106,10 +109,30 @@ - - - - + + + + Specific device identifier + 0 + + + + + + + + + + + Fronius Ohmpilot + + + + + + + + @@ -244,32 +267,48 @@ Number:ElectricCurrent - Number:ElectricPotential - Number:Power - Number - Number:Energy - + + Number:Power + + Actual power consumption [W] + + + + Number:Energy + + Total consumed energy [Wh] + + + + Number:Temperature + + Temperature of the PT1000 + + + + +