Skip to content

Commit

Permalink
[wemo] Add DimmerSwitch support and update README (openhab#6304)
Browse files Browse the repository at this point in the history
Signed-off-by: Hans-Jörg Merk <[email protected]>
  • Loading branch information
hmerk authored and kaikreuzer committed Nov 19, 2019
1 parent 5dc1db7 commit bfb60a1
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 38 deletions.
55 changes: 36 additions & 19 deletions bundles/org.openhab.binding.wemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ The integration happens either through the WeMo-Link bridge, which acts as an IP

## Supported Things

The WeMo Binding supports the Socket, Insight, Lightswitch, Motion and Maker devices, as well as the WeMo-Link bridge with WeMo LED bulbs.
The WeMo Binding supports the Socket, Insight, Lightswitch, Motion, Dimmer, Coffemaker and Maker devices, as well as the WeMo-Link bridge with WeMo LED bulbs.

## Discovery

The WeMo devices are discovered through UPnP discovery service in the network. Devices will show up in the inbox and can be easily added as Things.

## Binding Configuration

The binding does not need any special configuration
The binding does not need any configuration.

## Thing Configuration

Expand All @@ -39,23 +39,40 @@ MZ100 94103EA2B278xxxx [ deviceID="94103EA2B278xxxx" ]

Devices support some of the following channels:

| Channel Type ID | Item Type | Description |
| ------------------ | --------- | ------------------------------------------------------------ |
| motionDetection | Switch | On if motion is detected, off otherwise. (Motion Sensor only) |
| lastMotionDetected | DateTime | Representing the Date and Time when the last motion was detected. (Motion Sensor only) |
| state | Switch | This channel controls the actual binary State of a Device or represents Motion Detection. |
| lastChangedAt | DateTime | Representing the Date and Time the device was last turned on or of. |
| lastOnFor | Number | Time in seconds an Insight device was last turned on for. |
| onToday | Number | Time in seconds an Insight device has been switched on today. |
| onTotal | Number | Time in seconds an Insight device has been switched on totally. |
| timespan | Number | Time in seconds over which onTotal applies. Typically 2 weeks except first used. |
| averagePower | Number | Average power consumption in Watts. |
| currentPower | Number | Current power consumption of an Insight device. 0 if switched off. |
| energyToday | Number | Energy in Wh used today. |
| energyTotal | Number | Energy in Wh used in total. |
| standbyLimit | Number | Minimum energy draw in W to register device as switched on (default 8W, configurable via WeMo App). |
| onStandBy | Switch | Read-only indication of whether or not the device plugged in to the insight switch is drwawing more than the standby limit. |
| brightness | Number | Brightness of a WeMo LED. |
| Channel Type ID | Item Type | Description | Available on thing
|---------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------|
| motionDetection | Switch | On if motion is detected, off otherwise. (Motion Sensor only) | Motion
| lastMotionDetected | DateTime | Date and Time when the last motion was detected. (Motion Sensor only) | Motion
| state | Switch | This channel controls the actual binary State of a Device or represents Motion Detection. | All
| lastChangedAt | DateTime | Date and Time the device was last turned on or of. | Insight
| lastOnFor | Number | Time in seconds an Insight device was last turned on for. | Insight
| onToday | Number | Time in seconds an Insight device has been switched on today. | Insight
| onTotal | Number | Time in seconds an Insight device has been switched on totally. | Insight
| timespan | Number | Time in seconds over which onTotal applies. Typically 2 weeks except first used. | Insight
| averagePower | Number | Average power consumption in Watts. | Insight
| currentPower | Number | Current power consumption of an Insight device. 0 if switched off. | Insight
| energyToday | Number | Energy in Wh used today. | Insight
| energyTotal | Number | Energy in Wh used in total. | Insight
| standbyLimit | Number | Minimum energy draw in W to register device as switched on (default 8W, configurable via WeMo App). | Insight
| onStandBy | Switch | Read-only indication of whether or not the device plugged in to the insight switch is drawing more than the standby limit. | Insight
| relay | Switch | Switches the integrated relay contact close/open | Maker
| sensor | Switch | Shows the state of the integrated sensor | Maker
| coffeeMode | String | Operation mode of a WeMo Coffee Maker | CoffeeMaker
| modeTime | Number | Current amount of time, in minutes, that the Coffee Maker has been in the current mode | CoffeeMaker
| timeRemaining | Number | Remaining brewing time of a WeMo Coffee Maker | CoffeeMaker
| waterLevelReached | Switch | Indicates if the WeMo Coffee Maker needs to be refilled | CoffeeMaker
| cleanAdvise | Switch | Indicates if a WeMo Coffee Maker needs to be cleaned | CoffeeMaker
| filterAdvise | Switch | Indicates if a WeMo Coffee Maker needs to have the filter changed | CoffeeMaker
| brewed | DateTime | Date/time the coffee maker last completed brewing coffee | CoffeeMaker
| lastCleaned | DateTime | Date/time the coffee maker last completed cleaning | CoffeeMaker
| brightness | Number | Brightness of a WeMo LED. | LED
| faderCountDownTime | Number | Dimmer fading duration time in minutes | Dimmer
| faderEnabled | Switch | Switch the fader ON/OFF | Dimmer
| timerStart | Switch | Switch the fading timer ON/OFF | Dimmer
| nightMode | Switch | Switch the nightMode ON/OFF | Dimmer
| startTime | DateTime | Time when the nightMode starts | Dimmer
| endTime | DateTime | Time when the nightMode ends | Dimmer
| nightModeBrightness | Number | Brightness used in nightMode | Dimmer


## Full Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class WemoBindingConstants {
public static final ThingTypeUID THING_TYPE_MZ100 = new ThingTypeUID(BINDING_ID, "MZ100");
public static final ThingTypeUID THING_TYPE_MAKER = new ThingTypeUID(BINDING_ID, "Maker");
public static final ThingTypeUID THING_TYPE_COFFEE = new ThingTypeUID(BINDING_ID, "CoffeeMaker");
public static final ThingTypeUID THING_TYPE_DIMMER = new ThingTypeUID(BINDING_ID, "dimmer");

// List of all Channel ids
public static final String CHANNEL_STATE = "state";
Expand All @@ -59,7 +60,6 @@ public class WemoBindingConstants {
public static final String CHANNEL_SENSOR = "sensor";
public static final String CHANNEL_ONSTANDBY = "onStandBy";


public static final String CHANNEL_COFFEEMODE = "coffeeMode";
public static final String CHANNEL_MODETIME = "modeTime";
public static final String CHANNEL_TIMEREMAINING = "timeRemaining";
Expand All @@ -69,6 +69,14 @@ public class WemoBindingConstants {
public static final String CHANNEL_BREWED = "brewed";
public static final String CHANNEL_LASTCLEANED = "lastCleaned";

public static final String CHANNEL_FADERENABLED = "faderEnabled";
public static final String CHANNEL_TIMERSTART = "timerStart";
public static final String CHANNEL_FADERCOUNTDOWNTIME = "faderCountDownTime";
public static final String CHANNEL_NIGHTMODE = "nightMode";
public static final String CHANNEL_STARTTIME = "startTime";
public static final String CHANNEL_ENDTIME = "endTime";
public static final String CHANNEL_NIGHTMODEBRIGHTNESS = "nightModeBrightness";

// List of thing configuration properties
public static final String UDN = "udn";
public static final String DEVICE_ID = "deviceID";
Expand All @@ -86,10 +94,9 @@ public class WemoBindingConstants {
.unmodifiableSet(Stream.of(THING_TYPE_SOCKET, THING_TYPE_INSIGHT, THING_TYPE_LIGHTSWITCH, THING_TYPE_MOTION)
.collect(Collectors.toSet()));

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
.unmodifiableSet(Stream
.of(THING_TYPE_SOCKET, THING_TYPE_INSIGHT, THING_TYPE_LIGHTSWITCH, THING_TYPE_MOTION,
THING_TYPE_BRIDGE, THING_TYPE_MZ100, THING_TYPE_MAKER, THING_TYPE_COFFEE)
.collect(Collectors.toSet()));
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.unmodifiableSet(Stream
.of(THING_TYPE_SOCKET, THING_TYPE_INSIGHT, THING_TYPE_LIGHTSWITCH, THING_TYPE_MOTION, THING_TYPE_BRIDGE,
THING_TYPE_MZ100, THING_TYPE_MAKER, THING_TYPE_COFFEE, THING_TYPE_DIMMER)
.collect(Collectors.toSet()));

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openhab.binding.wemo.internal.discovery.WemoLinkDiscoveryService;
import org.openhab.binding.wemo.internal.handler.WemoBridgeHandler;
import org.openhab.binding.wemo.internal.handler.WemoCoffeeHandler;
import org.openhab.binding.wemo.internal.handler.WemoDimmerHandler;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.handler.WemoLightHandler;
import org.openhab.binding.wemo.internal.handler.WemoMakerHandler;
Expand Down Expand Up @@ -64,6 +65,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

private final Map<ThingUID, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();

@SuppressWarnings({ "null", "unused" })
@Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
Expand All @@ -90,6 +92,10 @@ protected ThingHandler createHandler(Thing thing) {
logger.debug("Creating a WemoCoffeeHandler for thing '{}' with UDN '{}'", thing.getUID(),
thing.getConfiguration().get(UDN));
return new WemoCoffeeHandler(thing, upnpIOService, wemoHttpcaller);
} else if (thingTypeUID.equals(WemoBindingConstants.THING_TYPE_DIMMER)) {
logger.debug("Creating a WemoDimmerHandler for thing '{}' with UDN '{}'", thing.getUID(),
thing.getConfiguration().get("udn"));
return new WemoDimmerHandler(thing, upnpIOService, wemoHttpcaller);
} else if (thingTypeUID.equals(WemoBindingConstants.THING_TYPE_MZ100)) {
return new WemoLightHandler(thing, upnpIOService, wemoHttpcaller);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.eclipse.smarthome.config.discovery.upnp.internal.UpnpDiscoveryService;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.jupnp.model.meta.RemoteDevice;
Expand Down Expand Up @@ -73,7 +75,7 @@ public DiscoveryResult createResult(RemoteDevice device) {
}

@Override
public ThingUID getThingUID(RemoteDevice device) {
public ThingUID getThingUID(@Nullable RemoteDevice device) {
if (device != null) {
if (device.getDetails().getManufacturerDetails().getManufacturer() != null) {
if (device.getDetails().getManufacturerDetails().getManufacturer().toUpperCase().contains("BELKIN")) {
Expand Down Expand Up @@ -121,6 +123,11 @@ public ThingUID getThingUID(RemoteDevice device) {
device.getIdentity().getUdn().getIdentifierString());
return new ThingUID(THING_TYPE_COFFEE, device.getIdentity().getUdn().getIdentifierString());
}
if (device.getDetails().getModelDetails().getModelName().toLowerCase().startsWith("dimmer")) {
logger.debug("Discovered a WeMo Dimmer Switch thing with UDN '{}'",
device.getIdentity().getUdn().getIdentifierString());
return new ThingUID(THING_TYPE_DIMMER, device.getIdentity().getUdn().getIdentifierString());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ protected void updateWemoState() {
}
}

@SuppressWarnings("null")
public State getDateTimeState(String attributeValue) {
if (attributeValue != null) {
long value = 0;
Expand Down
Loading

0 comments on commit bfb60a1

Please sign in to comment.