Skip to content

Commit

Permalink
[energenie] Initial contribution (openhab#6461)
Browse files Browse the repository at this point in the history
* [energenie] oh1 migration

Signed-off-by: Hans-Jörg Merk <hans-joerg.merk@t-online.de>
Co-authored-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
  • Loading branch information
2 people authored and andrewfg committed Aug 31, 2020
1 parent 81d6843 commit 1b479cf
Show file tree
Hide file tree
Showing 20 changed files with 1,140 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
/bundles/org.openhab.binding.dwdpollenflug/ @DerOetzi
/bundles/org.openhab.binding.dwdunwetter/ @limdul79
/bundles/org.openhab.binding.elerotransmitterstick/ @vbier
/bundles/org.openhab.binding.energenie/ @hmerk
/bundles/org.openhab.binding.enocean/ @fruggy83
/bundles/org.openhab.binding.enturno/ @klocsson
/bundles/org.openhab.binding.etherrain/ @dfad1469
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
<artifactId>org.openhab.binding.elerotransmitterstick</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.energenie</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.enocean</artifactId>
Expand Down
32 changes: 32 additions & 0 deletions bundles/org.openhab.binding.energenie/.classpath
Original file line number Diff line number Diff line change
@@ -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-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="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions bundles/org.openhab.binding.energenie/.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.energenie</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.energenie/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
95 changes: 95 additions & 0 deletions bundles/org.openhab.binding.energenie/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Gembird energenie Binding

This binding integrates the Gembird energenie range of power extenders by using the Energenie Data Exchange Protocol and power reading devices through HTTP interface.


## Supported Things

The Binding supports PM2-LAN, PMS-LAN, PMS2-LAN or PMS-WLAN power extenders as well as PWM-LAN power measurement devices.

## Discovery

Gembird energenie devices don't support autodiscovery.
All Things need to be created manually either in PaperUI or within Things files.

## Binding Configuration

The Binding does not need any specific configuration

## Thing Configuration

The device requires the IP-address and a password as a configuration value in order for the binding to know where to access it and to login to the device.

| Parameter | Description |
|-----------|------------------------------------------------------|
| host | IP-Address of energenie device |
| password | Password to access energenie device, defaults to "1" |

## Channels

The following channels are supported by PM2-LAN, PMS-LAN, PMS2-LAN or PMS-WLAN devices

| channel | type | description |
|----------|--------|----------------------------------------------------|
| socket1 | Switch | This is the control channel for the first socket |
| socket2 | Switch | This is the control channel for the second socket |
| socket3 | Switch | This is the control channel for the third socket |
| socket4 | Switch | This is the control channel for the fourth socket |

PWM-LAN devices support the following channels

| channel | type | description |
|----------|--------------------------|------------------------------------------|
| voltage | Number:ElectricPotential | Channel for output voltage measurement |
| current | Number:ElectricCurrent | Channel for output current measurement |
| power | Number:Power | Channel for output power measurement |
| energy | Number:Energy | channel for output energy measurement |

## Full Example

Things

```
Thing energenie:pm2lan:pm2lan [ host="xxx.xxx.xxx.xxx", password="your password" ]
Thing energenie:pmslan:pmslan [ host="xxx.xxx.xxx.xxx", password="your password" ]
Thing energenie:pms2lan:pms2lan [ host="xxx.xxx.xxx.xxx", password="your password" ]
Thing energenie:pmswlan:pmswlan [ host="xxx.xxx.xxx.xxx", password="your password" ]
Thing energenie:pwmlan:pwmlan [ host="xxx.xxx.xxx.xxx", password="your password" ]
```

Items

```
//Power extenders
Switch Socket1 { channel="energenie:pm2lan:pm2lan:socket1" }
Switch Socket2 { channel="energenie:pm2lan:pm2lan:socket2" }
Switch Socket3 { channel="energenie:pm2lan:pm2lan:socket3" }
Switch Socket4 { channel="energenie:pm2lan:pm2lan:socket4" }
//Power measurement
Number Voltage { channel="energenie:pwmlan:pwmlan:voltage" }
Number Current { channel="energenie:pwmlan:pwmlan:current" }
Number Power { channel="energenie:pwmlan:pwmlan:power" }
Number Energy { channel="energenie:pwmlan:pwmlan:energy" }
```

Sitemap

```
sitemap energenie label="Energenie Devices"
{
Frame {
// Power extenders
Switch item=Socket1
Switch item=Socket2
Switch item=Socket3
Switch item=Socket4
// Power measurement
Number item=Voltage
Number item=Current
Number item=Power
Number item=Energy
}
}
```
16 changes: 16 additions & 0 deletions bundles/org.openhab.binding.energenie/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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.5-SNAPSHOT</version>
</parent>

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

<name>openHAB Add-ons :: Bundles :: Energenie Binding</name>

</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.energenie-${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-energenie" description="Energenie Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.energenie/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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.energenie.internal;

import java.util.Collections;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

/**
* The {@link EnergenieBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Hans-Jörg Merk - Initial contribution
*/
@NonNullByDefault
public class EnergenieBindingConstants {

private static final String BINDING_ID = "energenie";

public static final int TCP_PORT = 5000;

public static final int STATCRYP_LEN = 4;
public static final int CTRLCRYP_LEN = 4;
public static final int KEY_LEN = 8;
public static final int TASK_LEN = 4;
public static final int SOLUTION_LEN = 4;

public static final String STATE_ON = "0x11";
public static final String STATE_ON_NO_VOLTAGE = "0x12";
public static final String STATE_OFF = "0x22";
public static final String STATE_OFF_NO_VOLTAGE = "0x21";

public static final String V21_STATE_ON = "0x41";
public static final String V21_STATE_OFF = "0x82";

public static final String WLAN_STATE_ON = "0x51";
public static final String WLAN_STATE_OFF = "0x92";

public static final byte SWITCH_ON = 0x01;
public static final byte SWITCH_OFF = 0x02;
public static final byte DONT_SWITCH = 0x04;

public static final int SOCKET_COUNT = 4; // AC power sockets, not network ones

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_PM2LAN = new ThingTypeUID(BINDING_ID, "pm2lan");
public static final ThingTypeUID THING_TYPE_PMSLAN = new ThingTypeUID(BINDING_ID, "pmslan");
public static final ThingTypeUID THING_TYPE_PMS2LAN = new ThingTypeUID(BINDING_ID, "pms2lan");
public static final ThingTypeUID THING_TYPE_PMSWLAN = new ThingTypeUID(BINDING_ID, "pmswlan");
public static final ThingTypeUID THING_TYPE_PWMLAN = new ThingTypeUID(BINDING_ID, "pwmlan");

// List of all Channel ids
public static final Pattern CHANNEL_SOCKET = Pattern.compile("socket(\\d)");

public static final String VOLTAGE = "voltage";
public static final String CURRENT = "current";
public static final String POWER = "power";
public static final String ENERGY = "energy";

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
Stream.of(THING_TYPE_PM2LAN, THING_TYPE_PMSLAN, THING_TYPE_PMS2LAN, THING_TYPE_PMSLAN, THING_TYPE_PWMLAN)
.collect(Collectors.toSet()));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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.energenie.internal;

import static org.openhab.binding.energenie.internal.EnergenieBindingConstants.*;

import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.openhab.binding.energenie.internal.handler.EnergenieHandler;
import org.openhab.binding.energenie.internal.handler.EnergeniePWMHandler;
import org.osgi.service.component.annotations.Component;

/**
* The {@link EnergenieHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Hans-Jörg Merk - Initial contribution
*/
@NonNullByDefault
@Component(configurationPid = "binding.energenie", service = ThingHandlerFactory.class)
public class EnergenieHandlerFactory extends BaseThingHandlerFactory {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = EnergenieBindingConstants.SUPPORTED_THING_TYPES_UIDS;

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}

@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

if (THING_TYPE_PMSLAN.equals(thingTypeUID)) {
return new EnergenieHandler(thing, EnergenieProtocolEnum.V20);
} else if (THING_TYPE_PM2LAN.equals(thingTypeUID)) {
return new EnergenieHandler(thing, EnergenieProtocolEnum.V20);
} else if (THING_TYPE_PMS2LAN.equals(thingTypeUID)) {
return new EnergenieHandler(thing, EnergenieProtocolEnum.V21);
} else if (THING_TYPE_PMSWLAN.equals(thingTypeUID)) {
return new EnergenieHandler(thing, EnergenieProtocolEnum.WLAN);
} else if (THING_TYPE_PWMLAN.equals(thingTypeUID)) {
return new EnergeniePWMHandler(thing);
}
return null;
}
}
Loading

0 comments on commit 1b479cf

Please sign in to comment.