Skip to content

Commit

Permalink
First working version
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Rahner <oliver@rahner.me>
  • Loading branch information
oliverrahner committed Apr 6, 2020
1 parent 6b703fc commit 683f753
Show file tree
Hide file tree
Showing 26 changed files with 2,073 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bundles/org.openhab.binding.enera/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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-1.8">
<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="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions bundles/org.openhab.binding.enera/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.enera</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 changes: 13 additions & 0 deletions bundles/org.openhab.binding.enera/NOTICE
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions bundles/org.openhab.binding.enera/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Enera Binding
This binding provides access to live data gathered in Project Enera (https://projekt-enera.de), a public project in the area of Smart Grids.
Enera itself only provides access to gathered data via their mobile Apps with no means to analyse them elsewhere.

Using the Enera Binding, you can get access to the devices in your Enera accont(s) and retrieve meter readings as well as current consumption levels.
Other uses, such as access to historical data etc., could be added in the future.

No tests could yet be done using more than one account or more than one device per account, although everything is built for these scenarios to work.

## Supported Things
This binding provides two different thing types:

### Enera Account
This thing is your Enera Account. It acts as a bridge for the Enera Devices.
To get started you need to add at least one Enera Account and provide login credentials for it.

### Enera Device
This thing is a single device that you can see in your Enera App.
Devices cannot be added manually but will only be discovered automatically after you add an Enera Account.

On the device, you can configure the Refresh Rate. As Enera sends updates at little faster than every second, we have to reduce this rate.

You can roughly read this parameter as "update every X seconds", while it actually means "update channels only every X updates".

So, if you stick with the default value of 60, you can except one update roughly any minute.
For live consumption data, the average for all received values in the meantime will be reported.
For meter readings, only the last value will be reported.

## Discovery
After adding an Enera Account, you can (and have to) discover Device things.
To do this, go to Things > + > Enera Binding.

Note that devices added in the Enera app don't get discovered automatically, you have to trigger the discover process manually.

## Channels

| channel | type | description |
|-------------------------|--------|----------------------------------------------------------------------------------------------------------------|
| meter-reading | Number | contains the meter reading (OBIS key 1-0:1.8.0*255) |
| meter-reading-outbound | Number | contains the meter reading for outbound power (OBIS key 1-0:2.8.0*255)<br>_Note:_ This is not visible in the Enera app! |
| current-consumption | Number | contains the current power consumption (OBIS key 1-0:1.7.0*255) |
142 changes: 142 additions & 0 deletions bundles/org.openhab.binding.enera/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>2.5.4-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.enera</artifactId>

<name>openHAB Add-ons :: Bundles :: Enera Binding</name>
<properties>
<bnd.importpackage>!com.amazonaws.*,!org.joda.convert.*,!com.sun.org.apache.xpath.*,!kotlin,!org.apache.log.*,!org.bouncycastle.*,!org.apache.avalon.*</bnd.importpackage>
</properties>

<dependencies>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cognitoidp</artifactId>
<version>1.11.754</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cognitoidentity</artifactId>
<version>1.11.754</version>
</dependency>

<!-- above here are top level dependencies,
below here are dependencies of depencencies -->

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.11.0.rc1</version>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0.rc1</version>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.0.rc1</version>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.0.rc1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>jmespath-java</artifactId>
<version>1.11.755</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.755</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.755</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kms</artifactId>
<version>1.11.755</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.11.755</version>
</dependency>



<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudwatch</artifactId>
<version>1.11.755</version>
</dependency>


<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudwatchmetrics</artifactId>
<version>1.11.755</version>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.755</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.12</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>software.amazon.ion</groupId>
<artifactId>ion-java</artifactId>
<version>1.0.2</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.enera-${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-enera" description="Enera Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.enera/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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.enera.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.ThingTypeUID;

/**
* The {@link EneraBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Oliver Rahner - Initial contribution
*/
@NonNullByDefault
public class EneraBindingConstants {

private static final String BINDING_ID = "enera";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_ACCOUNT = new ThingTypeUID(BINDING_ID, "account");
public static final ThingTypeUID THING_TYPE_DEVICE = new ThingTypeUID(BINDING_ID, "device");

// List of all Properties
public static final String PROPERTY_ID = "id";
public static final String PROPERTY_NAME = "name";
public static final String PROPERTY_BRAND = "brand";
public static final String PROPERTY_SERIAL = "serial";
public static final String PROPERTY_EXTERNAL_ID = "external-id";
public static final String PROPERTY_METER_ID = "meter-id";
public static final String PROPERTY_REGISTERED_AT = "registered-at";

// AWS Cognito parameters of Enera
public static final String COGNITO_CLIENT_ID = "2iv53r55ahff70bcjo7f32a7lb";
public static final String COGNITO_USER_POOL_ID = "eu-central-1_m9ZZbQCTb";
public static final String COGNITO_REGION = "eu-central-1";

// Enera Live Consumption API data
public static final String LIVE_CONSUMPTION_URL = "ws://broker.enera.energie-vernetzen.de/rabbitmq-ws";
public static final String LIVE_CONSUMPTION_USERNAME = "energiemonitor:em-app";
public static final String LIVE_CONSUMPTION_PASSWORD = "em-app";

// Enera master data API
public static final String ENERA_BASE_URL = "https://api.enera.energie-vernetzen.de/Prod/v1";
public static final String ENERA_DEVICES_URL = ENERA_BASE_URL + "/Devices";

// OBIS keys
public static final String OBIS_METER_READING = "1-0:1.8.0*255";
public static final String OBIS_METER_READING_OUTBOUND = "1-0:2.8.0*255";
public static final String OBIS_LIVE_CONSUMPTION_TOTAL = "1-0:1.7.0*255";

// List of all Channel ids
public static final String CHANNEL_METER_READING = "meter-reading";
public static final String CHANNEL_METER_READING_OUTBOUND = "meter-reading-outbound";
public static final String CHANNEL_CURRENT_CONSUMPTION = "current-consumption";

// List all Configuration Keys
public static final String CONFIG_USERNAME = "username";
public static final String CONFIG_PASSWORD = "password";
public static final String CONFIG_RATE = "rate";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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.enera.internal;

/**
* The {@link EneraConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Oliver Rahner - Initial contribution
*/
public class EneraConfiguration {
}
Loading

0 comments on commit 683f753

Please sign in to comment.