added migrated 2.x add-ons
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
32
bundles/org.openhab.binding.solarlog/.classpath
Normal file
32
bundles/org.openhab.binding.solarlog/.classpath
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
bundles/org.openhab.binding.solarlog/.project
Normal file
23
bundles/org.openhab.binding.solarlog/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openhab.binding.solarlog</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
13
bundles/org.openhab.binding.solarlog/NOTICE
Normal file
13
bundles/org.openhab.binding.solarlog/NOTICE
Normal file
@@ -0,0 +1,13 @@
|
||||
This content is produced and maintained by the openHAB project.
|
||||
|
||||
* Project home: https://www.openhab.org
|
||||
|
||||
== Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms
|
||||
of the Eclipse Public License 2.0 which is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/.
|
||||
|
||||
== Source Code
|
||||
|
||||
https://github.com/openhab/openhab-addons
|
||||
50
bundles/org.openhab.binding.solarlog/README.md
Normal file
50
bundles/org.openhab.binding.solarlog/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Solar-Log Binding
|
||||
|
||||
The [Solar-Log Family](https://www.solar-log.com/en/) of monitoring devices for PV installations provide a MODBUS (TCP) and JSON-based API to access a number of internal data related to power generation and consumption. This binding implements access to the data via the JSON API.
|
||||
|
||||
## Use of the binding
|
||||
|
||||
The Solar-Log is exposed as one thing with a number of channels that can be used to read the values for different aspects of your Solar-Log installation.
|
||||
|
||||
## Setup of the binding
|
||||
|
||||
You can either configure the Thing via the openHAB UI or via a `*.things` file, according to the following example:
|
||||
|
||||
`Thing solarlog:meter:pv "Solar-Log 300" @ "Utility Room" [ url="http://solar-log", refreshInterval=15]`
|
||||
|
||||
The parameters to be used are simple:
|
||||
|
||||
* `url` denotes the URL of your Solar-Log. If you have not changed anything, this defaults to `http://solar-log`.
|
||||
* `refreshInterval` is the interval to fetch new data. Solar-Log updates its data every 15 - 60 seconds. `15` is the default value. Values lower than this will return the result from the last 15 seconds period. No value lower than this can be set in the UI.
|
||||
|
||||
Currently, the binding does not support authenticated access to the Solar-Log JSON API (which was introduced with newer firmwares). If must set the API access to `Open` in the Solar-Log configuration in order for the binding to work.
|
||||
|
||||
## Available channels
|
||||
|
||||
The following table is taken from the official manual and contains all available channels. If you want to manually define Items, this can for example be done as follows:
|
||||
|
||||
`Number solarlog_meter_pv_yieldday "Yield Day [% W]" (gSolarLog, gUtilityRoom) { channel="solarlog:meter:pv:yieldday" }`
|
||||
|
||||
Data point | Unit | Index Description
|
||||
------------------- | --------------------- | -----------------
|
||||
lastupdate | Time in the format dd.mm.yy; hh.minmin, secsec | 100 Time
|
||||
pac | W | 101 Total output PAC from all of the inverters and meters in inverter mode
|
||||
pdc | W | 102 Total output PAC from all of the inverters
|
||||
uac | V | 103 Average voltage UAC from the inverter
|
||||
udc | V | 104 Average voltage UDC from the inverter
|
||||
yieldday | Wh | 105 Total yield for the day from all of the inverters
|
||||
yieldyesterday | Wh | 106 Total yield for the previous day from all of the inverters
|
||||
yieldmonth | Wh | 107 Total yield for the month from all of the inverters
|
||||
yieldyear | Wh | 108 Total yield for the year from all of the inverters
|
||||
yieldtotal | Wh | 109 Total yield from all of the inverters
|
||||
conspac | W | 110 Current total consumption PAC from all of the consumption meters
|
||||
consyieldday | Wh | 111 Total consumption from all of the consumption meters
|
||||
consyieldyesterday | Wh | 112 Total consumption for the previous day; all of the consumption meters
|
||||
consyieldmonth | Wh | 113 Total consumption for the month; all of the consumption meters
|
||||
consyieldyear | Wh | 114 Total consumption for the year; all of the consumption meters
|
||||
consyieldtotal | Wh | 115 Accumulated total consumption, all Consumption meter
|
||||
totalpower | Wp | 116 Installed generator power
|
||||
|
||||
## More information
|
||||
|
||||
More information about the Solar-Log Data interfaces and the exact meaning of the various channels and the documentation of the JSON API can be found in the [Manual](https://www.solar-log.com/manuals/manuals/en_GB/SolarLog_Manual_3x_EN.pdf).
|
||||
17
bundles/org.openhab.binding.solarlog/pom.xml
Normal file
17
bundles/org.openhab.binding.solarlog/pom.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.solarlog</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Bundles :: Solar-Log Binding</name>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<features name="org.openhab.binding.solarlog-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
|
||||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
|
||||
|
||||
<feature name="openhab-binding-solarlog" description="SolarLog Binding" version="${project.version}">
|
||||
<feature>openhab-runtime-base</feature>
|
||||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.solarlog/${project.version}</bundle>
|
||||
</feature>
|
||||
</features>
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 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.solarlog.internal;
|
||||
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
|
||||
/**
|
||||
* The {@link SolarLogBinding} class defines common constants, which are
|
||||
* used across the whole binding.
|
||||
*
|
||||
* @author Johann Richard - Initial contribution
|
||||
*/
|
||||
public class SolarLogBindingConstants {
|
||||
|
||||
public static final String BINDING_ID = "solarlog";
|
||||
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_SOLARLOG = new ThingTypeUID(BINDING_ID, "meter");
|
||||
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_ID_LASTUPDATETIME = "lastupdate";
|
||||
public static final String CHANNEL_ID_PAC = "pac";
|
||||
public static final String CHANNEL_ID_PDC = "pdc";
|
||||
public static final String CHANNEL_ID_UAC = "uac";
|
||||
public static final String CHANNEL_ID_UDC = "udc";
|
||||
public static final String CHANNEL_ID_YIELDDAY = "yieldday";
|
||||
public static final String CHANNEL_ID_YIELDYESTERDAY = "yieldyesterday";
|
||||
public static final String CHANNEL_ID_YIELDMONTH = "yieldmonth";
|
||||
public static final String CHANNEL_ID_YIELDYEAR = "yieldyear";
|
||||
public static final String CHANNEL_ID_YIELDTOTAL = "yieldtotal";
|
||||
public static final String CHANNEL_ID_CONSPAC = "conspac";
|
||||
public static final String CHANNEL_ID_CONSYIELDDAY = "consyieldday";
|
||||
public static final String CHANNEL_ID_CONSYIELDYESTERDAY = "consyieldyesterday";
|
||||
public static final String CHANNEL_ID_CONSYIELDMONTH = "consyieldmonth";
|
||||
public static final String CHANNEL_ID_CONSYIELDYEAR = "consyieldyear";
|
||||
public static final String CHANNEL_ID_CONSYIELDTOTAL = "consyieldtotal";
|
||||
public static final String CHANNEL_ID_TOTALPOWER = "totalpower";
|
||||
|
||||
// List of all JSON Id's for channels
|
||||
public static final String CHANNEL_LASTUPDATETIME = "100";
|
||||
public static final String CHANNEL_PAC = "101";
|
||||
public static final String CHANNEL_PDC = "102";
|
||||
public static final String CHANNEL_UAC = "103";
|
||||
public static final String CHANNEL_UDC = "104";
|
||||
public static final String CHANNEL_YIELDDAY = "105";
|
||||
public static final String CHANNEL_YIELDYESTERDAY = "106";
|
||||
public static final String CHANNEL_YIELDMONTH = "107";
|
||||
public static final String CHANNEL_YIELDYEAR = "108";
|
||||
public static final String CHANNEL_YIELDTOTAL = "109";
|
||||
public static final String CHANNEL_CONSPAC = "110";
|
||||
public static final String CHANNEL_CONSYIELDDAY = "111";
|
||||
public static final String CHANNEL_CONSYIELDYESTERDAY = "112";
|
||||
public static final String CHANNEL_CONSYIELDMONTH = "113";
|
||||
public static final String CHANNEL_CONSYIELDYEAR = "114";
|
||||
public static final String CHANNEL_CONSYIELDTOTAL = "115";
|
||||
public static final String CHANNEL_TOTALPOWER = "116";
|
||||
|
||||
// CHannel Type (DateTime or Number
|
||||
public static final String CHANNEL_TYPE_LASTUPDATETIME = "DateTime";
|
||||
public static final String CHANNEL_TYPE_PAC = "Number";
|
||||
public static final String CHANNEL_TYPE_PDC = "Number";
|
||||
public static final String CHANNEL_TYPE_UAC = "Number";
|
||||
public static final String CHANNEL_TYPE_UDC = "Number";
|
||||
public static final String CHANNEL_TYPE_YIELDDAY = "Number";
|
||||
public static final String CHANNEL_TYPE_YIELDYESTERDAY = "Number";
|
||||
public static final String CHANNEL_TYPE_YIELDMONTH = "Number";
|
||||
public static final String CHANNEL_TYPE_YIELDYEAR = "Number";
|
||||
public static final String CHANNEL_TYPE_YIELDTOTAL = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSPAC = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSYIELDDAY = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSYIELDYESTERDAY = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSYIELDMONTH = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSYIELDYEAR = "Number";
|
||||
public static final String CHANNEL_TYPE_CONSYIELDTOTAL = "Number";
|
||||
public static final String CHANNEL_TYPE_TOTALPOWER = "Number";
|
||||
|
||||
// Some basic constants (JSON ID)
|
||||
public static final String SOLARLOG_JSON_ROOT = "801";
|
||||
public static final String SOLARLOG_JSON_PROPERTIES = "170";
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 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.solarlog.internal;
|
||||
|
||||
/**
|
||||
* The {@link SolarLogChannel} Enum defines common constants, which are
|
||||
* used across the whole binding.
|
||||
*
|
||||
* @author Johann Richard - Initial contribution
|
||||
*/
|
||||
public enum SolarLogChannel {
|
||||
|
||||
CHANNEL_LASTUPDATETIME("lastupdate", "100"),
|
||||
CHANNEL_PAC("pac", "101"),
|
||||
CHANNEL_PDC("pdc", "102"),
|
||||
CHANNEL_UAC("uac", "103"),
|
||||
CHANNEL_UDC("udc", "104"),
|
||||
CHANNEL_YIELDDAY("yieldday", "105"),
|
||||
CHANNEL_YIELDYESTERDAY("yieldyesterday", "106"),
|
||||
CHANNEL_YIELDMONTH("yieldmonth", "107"),
|
||||
CHANNEL_YIELDYEAR("yieldyear", "108"),
|
||||
CHANNEL_YIELDTOTAL("yieldtotal", "109"),
|
||||
CHANNEL_CONSPAC("conspac", "110"),
|
||||
CHANNEL_CONSYIELDDAY("consyieldday", "111"),
|
||||
CHANNEL_CONSYIELDYESTERDAY("consyieldyesterday", "112"),
|
||||
CHANNEL_CONSYIELDMONTH("consyieldmonth", "113"),
|
||||
CHANNEL_CONSYIELDYEAR("consyieldyear", "114"),
|
||||
CHANNEL_CONSYIELDTOTAL("consyieldtotal", "115"),
|
||||
CHANNEL_TOTALPOWER("totalpower", "116");
|
||||
|
||||
private final String id;
|
||||
private final String index;
|
||||
|
||||
SolarLogChannel(String id, String index) {
|
||||
this.id = id;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 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.solarlog.internal;
|
||||
|
||||
/**
|
||||
* The class {@link SolarLogConfig} represents the configuration
|
||||
* values available for the Solar-Log Binding.
|
||||
*
|
||||
* @author Johann Richard - Initial contribution
|
||||
*/
|
||||
public class SolarLogConfig {
|
||||
public String url;
|
||||
public int refreshInterval;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 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.solarlog.internal;
|
||||
|
||||
import static org.openhab.binding.solarlog.internal.SolarLogBindingConstants.THING_SOLARLOG;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openhab.binding.solarlog.internal.handler.SolarLogHandler;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
|
||||
import org.openhab.core.thing.binding.ThingHandler;
|
||||
import org.openhab.core.thing.binding.ThingHandlerFactory;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The {@link SolarLogHandlerFactory} is responsible for creating things and thing
|
||||
* handlers. It is completely boiler-plate and nothing special at all.
|
||||
*
|
||||
* @author Johann Richard - Initial contribution
|
||||
*/
|
||||
@Component(configurationPid = "binding.solarlog", service = ThingHandlerFactory.class)
|
||||
public class SolarLogHandlerFactory extends BaseThingHandlerFactory {
|
||||
private final Logger logger = LoggerFactory.getLogger(SolarLogHandlerFactory.class);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_SOLARLOG);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThingHandler createHandler(Thing thing) {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
logger.debug("Create Thing Handler {}", THING_SOLARLOG);
|
||||
if (THING_SOLARLOG.equals(thingTypeUID)) {
|
||||
return new SolarLogHandler(thing);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 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.solarlog.internal.handler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openhab.binding.solarlog.internal.SolarLogBindingConstants;
|
||||
import org.openhab.binding.solarlog.internal.SolarLogChannel;
|
||||
import org.openhab.binding.solarlog.internal.SolarLogConfig;
|
||||
import org.openhab.core.io.net.http.HttpUtil;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.thing.Channel;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
import org.openhab.core.thing.ThingStatusDetail;
|
||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.State;
|
||||
import org.openhab.core.types.UnDefType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
/**
|
||||
* The {@link SolarLogHandler} is responsible for handling commands, which are
|
||||
* sent to one of the channels. It does the "heavy lifting" of connecting to the
|
||||
* Solar-Log, getting the data, parsing it and updating the channels.
|
||||
*
|
||||
* @author Johann Richard - Initial contribution
|
||||
*/
|
||||
public class SolarLogHandler extends BaseThingHandler {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(SolarLogHandler.class);
|
||||
private SolarLogConfig config;
|
||||
|
||||
private final int timeout = 5000;
|
||||
|
||||
public SolarLogHandler(Thing thing) {
|
||||
super(thing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
// Read only
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
logger.debug("Initializing Solar-Log");
|
||||
config = getConfigAs(SolarLogConfig.class);
|
||||
scheduler.scheduleWithFixedDelay(() -> {
|
||||
logger.debug("Running refresh cycle");
|
||||
try {
|
||||
refresh();
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
// Very rudimentary Exception differentiation
|
||||
} catch (IOException e) {
|
||||
logger.debug("Error reading response from Solar-Log", e);
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||
"Communication error with the device. Please retry later.");
|
||||
} catch (JsonSyntaxException je) {
|
||||
logger.warn("Invalid JSON when refreshing source {}: {}", getThing().getUID(), je.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error refreshing source {}: {}", getThing().getUID(), e.getMessage(), e);
|
||||
}
|
||||
}, 0, config.refreshInterval < 15 ? 15 : config.refreshInterval, TimeUnit.SECONDS); // Minimum interval is 15 s
|
||||
}
|
||||
|
||||
private void refresh() throws Exception {
|
||||
// Get the JSON - somehow
|
||||
logger.trace("Starting refresh handler");
|
||||
String httpMethod = "POST";
|
||||
String url = config.url + "/getjp";
|
||||
String content = "{\"801\":{\"170\":null}}";
|
||||
InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
logger.debug("Attempting to load data from {} with parameter {}", url, content);
|
||||
String response = HttpUtil.executeUrl(httpMethod, url, stream, null, timeout);
|
||||
JsonElement solarLogDataElement = new JsonParser().parse(response);
|
||||
JsonObject solarLogData = solarLogDataElement.getAsJsonObject();
|
||||
|
||||
// Check whether the data is well-formed
|
||||
if (solarLogData.has(SolarLogBindingConstants.SOLARLOG_JSON_ROOT)) {
|
||||
solarLogData = solarLogData.getAsJsonObject(SolarLogBindingConstants.SOLARLOG_JSON_ROOT);
|
||||
logger.trace("Found root node in Solar-Log data. Attempting to read data");
|
||||
if (solarLogData.has(SolarLogBindingConstants.SOLARLOG_JSON_PROPERTIES)) {
|
||||
solarLogData = solarLogData.getAsJsonObject(SolarLogBindingConstants.SOLARLOG_JSON_PROPERTIES);
|
||||
|
||||
for (SolarLogChannel channelConfig : SolarLogChannel.values()) {
|
||||
if (solarLogData.has(channelConfig.getIndex())) {
|
||||
String value = solarLogData.get(channelConfig.getIndex()).getAsString();
|
||||
Channel channel = getThing().getChannel(channelConfig.getId());
|
||||
State state = getState(value, channelConfig);
|
||||
if (channel != null) {
|
||||
logger.trace("Update channel state: {}", state);
|
||||
updateState(channel.getUID(), state);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Error refreshing source {}: {}", getThing().getUID(), channelConfig.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("Data retrieval failed, no data returned {}", response);
|
||||
}
|
||||
}
|
||||
|
||||
private State getState(String value, SolarLogChannel type) {
|
||||
switch (type) {
|
||||
// Only DateTime channel
|
||||
case CHANNEL_LASTUPDATETIME:
|
||||
try {
|
||||
logger.trace("Parsing date {}", value);
|
||||
try {
|
||||
Date date = new SimpleDateFormat("dd.MM.yy HH:mm:ss").parse(value);
|
||||
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");// dd/MM/yyyy
|
||||
String strDate = sdfDate.format(date);
|
||||
|
||||
logger.trace("Parsing date successful. Returning date. {}", new DateTimeType(strDate));
|
||||
return new DateTimeType(strDate);
|
||||
} catch (ParseException fpe) {
|
||||
logger.trace("Parsing date failed. Returning string.", fpe);
|
||||
return new StringType(value);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.warn("Parsing date failed. Returning nothing", e);
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
// All other channels should be numbers
|
||||
default:
|
||||
try {
|
||||
logger.trace("Parsing number {}", value);
|
||||
return new DecimalType(new BigDecimal(value));
|
||||
} catch (NumberFormatException e) {
|
||||
// Log a warning and return UNDEF
|
||||
logger.warn("Parsing number failed. Returning nothing", e);
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<binding:binding id="solarlog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
|
||||
|
||||
<name>Solar-Log Binding</name>
|
||||
<description>This is the binding for the Solar-Log product range developed and sold by Solare Datensysteme GmbH. The
|
||||
Solar-Log devices allow monitoring of Photovoltaic (PV) installations and provide a JSON API to extract data. This
|
||||
includes information about current energy production and use, and other vital parameters of a PV installation. This
|
||||
binding makes this data accessible to openHAB from where it can be persistently stored, used to trigger actions or be
|
||||
displayed for information.</description>
|
||||
<author>Johann Richard</author>
|
||||
|
||||
</binding:binding>
|
||||
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<thing:thing-descriptions bindingId="solarlog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
|
||||
<thing-type id="meter">
|
||||
<label>Solar-Log Meter</label>
|
||||
<description>Basic thing for the Solar-Log Binding</description>
|
||||
|
||||
<channels>
|
||||
<channel id="lastupdate" typeId="lastupdate"></channel>
|
||||
<channel id="pac" typeId="pac"></channel>
|
||||
<channel id="pdc" typeId="pdc"></channel>
|
||||
<channel id="uac" typeId="uac"></channel>
|
||||
<channel id="udc" typeId="udc"></channel>
|
||||
<channel id="yieldday" typeId="yieldday"></channel>
|
||||
<channel id="yieldyesterday" typeId="yieldyesterday"></channel>
|
||||
<channel id="yieldmonth" typeId="yieldmonth"></channel>
|
||||
<channel id="yieldyear" typeId="yieldyear"></channel>
|
||||
<channel id="yieldtotal" typeId="yieldtotal"></channel>
|
||||
<channel id="conspac" typeId="conspac"></channel>
|
||||
<channel id="consyieldday" typeId="consyieldday"></channel>
|
||||
<channel id="consyieldyesterday" typeId="consyieldyesterday"></channel>
|
||||
<channel id="consyieldmonth" typeId="consyieldmonth"></channel>
|
||||
<channel id="consyieldyear" typeId="consyieldyear"></channel>
|
||||
<channel id="consyieldtotal" typeId="consyieldtotal"></channel>
|
||||
<channel id="totalpower" typeId="totalpower"></channel>
|
||||
</channels>
|
||||
<config-description>
|
||||
<parameter name="url" type="text" required="true">
|
||||
<label>URL</label>
|
||||
<description>URL of the Solar-Log web interface (e.g. http://solar-log)</description>
|
||||
<default>http://solar-log</default>
|
||||
</parameter>
|
||||
<parameter name="refreshInterval" type="integer" min="15">
|
||||
<label>Refresh Interval</label>
|
||||
<description>States how often a refresh shall occur (in s).</description>
|
||||
<default>15</default>
|
||||
</parameter>
|
||||
</config-description>
|
||||
</thing-type>
|
||||
<channel-type id="lastupdate">
|
||||
<item-type>DateTime</item-type>
|
||||
<label>Last Update</label>
|
||||
<description>Last Update Time</description>
|
||||
<state readOnly="true"></state>
|
||||
</channel-type>
|
||||
<channel-type id="pac">
|
||||
<item-type>Number</item-type>
|
||||
<label>PAC</label>
|
||||
<description>Total output PAC from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d W"></state>
|
||||
</channel-type>
|
||||
<channel-type id="pdc">
|
||||
<item-type>Number</item-type>
|
||||
<label>PDC</label>
|
||||
<description>Total output PDC from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d W"></state>
|
||||
</channel-type>
|
||||
<channel-type id="uac">
|
||||
<item-type>Number</item-type>
|
||||
<label>UAC</label>
|
||||
<description>Average voltage UAC from the inverter</description>
|
||||
<state readOnly="true" pattern="%d V"></state>
|
||||
</channel-type>
|
||||
<channel-type id="udc">
|
||||
<item-type>Number</item-type>
|
||||
<label>UDC</label>
|
||||
<description>Average voltage UDC from the inverter</description>
|
||||
<state readOnly="true" pattern="%d V"></state>
|
||||
</channel-type>
|
||||
<channel-type id="yieldday">
|
||||
<item-type>Number</item-type>
|
||||
<label>Yield Day</label>
|
||||
<description>Total yield for the day from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="yieldyesterday">
|
||||
<item-type>Number</item-type>
|
||||
<label>Yield Yesterday</label>
|
||||
<description>Total yield for the previous day from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="yieldmonth">
|
||||
<item-type>Number</item-type>
|
||||
<label>Yield Month</label>
|
||||
<description>Total yield for the month from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="yieldyear">
|
||||
<item-type>Number</item-type>
|
||||
<label>Yield Year</label>
|
||||
<description>Total yield for the year from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="yieldtotal">
|
||||
<item-type>Number</item-type>
|
||||
<label>Yield Total</label>
|
||||
<description>Total yield from all of the inverters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="conspac">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption PAC</label>
|
||||
<description>Current total consumption PAC from all of the consumption meters (W)</description>
|
||||
<state readOnly="true" pattern="%d W"></state>
|
||||
</channel-type>
|
||||
<channel-type id="consyieldday">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption Today</label>
|
||||
<description>Total consumption from all of the consumption meters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="consyieldyesterday">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption Yesterday</label>
|
||||
<description>Total consumption for the previous day; all of the consumption meters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="consyieldmonth">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption Month</label>
|
||||
<description>Total consumption for the month; all of the consumption meters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="consyieldyear">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption Year</label>
|
||||
<description>Total consumption for the year; all of the consumption meters</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="consyieldtotal">
|
||||
<item-type>Number</item-type>
|
||||
<label>Consumption Total</label>
|
||||
<description>Accumulated total consumption, all Consumption meter</description>
|
||||
<state readOnly="true" pattern="%d Wh"></state>
|
||||
</channel-type>
|
||||
<channel-type id="totalpower">
|
||||
<item-type>Number</item-type>
|
||||
<label>Total Power</label>
|
||||
<description>Installed generator power (Wp)</description>
|
||||
<state readOnly="true" pattern="%d Wp"></state>
|
||||
</channel-type>
|
||||
|
||||
</thing:thing-descriptions>
|
||||
Reference in New Issue
Block a user