Skip to content

Commit

Permalink
[shelly] Add channels device#deviceName, relay#outputName + refactori…
Browse files Browse the repository at this point in the history
…ng (#8396)

Signed-off-by: Markus Michels <markus7017@gmail.com>
  • Loading branch information
markus7017 authored Sep 12, 2020
1 parent 314c283 commit 58e9eb9
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 120 deletions.
19 changes: 11 additions & 8 deletions bundles/org.openhab.binding.shelly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Again if the device is not on the same local IP subnet you need special router/s
Otherwise disable the Auto-CoIoT feature in the binding config (not the thing config), disable CoIoT events in the thing configuration and enable sensors events (http callback).
Nevertheless in this setup the binding can communicate the device, but you are loosing the benefits of CoIoT.

Refer to openHAB's general documentation when running openHAB in a docker container. Enabling UPnP discovery has additional setup requirements.
Refer to openHAB's general documentation when running openHAB in a docker container. Enabling mDNS discovery has additional setup requirements.

### Re-discover when IP address has changed

Expand Down Expand Up @@ -206,7 +206,8 @@ Every device has a channel group `device` with the following channels:

|Group |Channel |Type |read-only|Description |
|----------|-------------------|--------|---------|---------------------------------------------------------------------------------|
|device |uptime |Number |yes |Number of seconds since the device was powered up |
|device |deviceName |String |yes |Device name as configured in the Shelly App |
| |uptime |Number |yes |Number of seconds since the device was powered up |
| |wifiSignal |Number |yes |WiFi signal strength (4=excellent, 3=good, 2=not string, 1=unreliable, 0=none) |
| |innerTemp |Number |yes |Internal device temperature (when provided by the device) |
| |selfTest |String |yes |Result from device self-test (pending/not_completed/running/completed/unknown) |
Expand Down Expand Up @@ -330,6 +331,7 @@ Depending on the device type and firmware release channels might be not availabl
|----------|-------------|---------|---------|---------------------------------------------------------------------------------|
|relay |output |Switch |r/w |Controls the relay's output channel (on/off) |
| |input |Switch |yes |ON: Input/Button is powered, see General Notes on Channels |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|sensors |temperature1 |Number |yes |Temperature value of external sensor #1 (if connected to temp/hum addon) |
| |temperature2 |Number |yes |Temperature value of external sensor #2 (if connected to temp/hum addon) |
| |temperature3 |Number |yes |Temperature value of external sensor #3 (if connected to temp/hum addon) |
Expand All @@ -342,6 +344,7 @@ Depending on the device type and firmware release channels might be not availabl
|relay |output |Switch |r/w |Controls the relay's output channel (on/off) |
| |input |Switch |yes |ON: Input/Button is powered, see General Notes on Channels |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter |currentWatts |Number |yes |Current power consumption in Watts |
| |lastPower1 |Number |yes |Energy consumption in Watts for a round minute, 1 minute ago |
| |lastPower2 |Number |yes |Energy consumption in Watts for a round minute, 2 minutes ago |
Expand All @@ -360,6 +363,7 @@ Depending on the device type and firmware release channels might be not availabl
|relay |output |Switch |r/w |Controls the relay's output channel (on/off) |
| |input |Switch |yes |ON: Input/Button is powered, see General Notes on Channels |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter1 |currentWatts |Number |yes |Current power consumption in Watts |
| |totalKWH |Number |yes |Total energy consumption in Watts since the device powered up (resets on restart)|
| |returnedKWH |Number |yes |Total returned energy, kw/h |
Expand All @@ -383,6 +387,7 @@ The thing id is derived from the service name, so that's the reason why the thin
|relay |output |Switch |r/w |Controls the relay's output channel (on/off) |
| |input |Switch |yes |ON: Input/Button is powered, see General Notes on Channels |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter1 |currentWatts |Number |yes |Current power consumption in Watts |
| |totalKWH |Number |yes |Total energy consumption in Watts since the device powered up (resets on restart)|
| |returnedKWH |Number |yes |Total returned energy, kw/h |
Expand Down Expand Up @@ -419,12 +424,14 @@ The thing id is derived from the service name, so that's the reason why the thin
| |autoOff |Number |r/w |Relay #1: Sets a timer to turn the device OFF after every ON command; in seconds|
| |timerActive |Switch |yes |Relay #1: ON: An auto-on/off timer is active |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|relay2 |output |Switch |r/w |Relay #2: Controls the relay's output channel (on/off) |
| |input |Switch |yes |ON: Input/Button is powered, see General Notes on Channels |
| |autoOn |Number |r/w |Relay #2: Sets a timer to turn the device ON after every OFF command; in seconds|
| |autoOff |Number |r/w |Relay #2: Sets a timer to turn the device OFF after every ON command; in seconds|
| |timerActive |Switch |yes |Relay #2: ON: An auto-on/off timer is active |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter |currentWatts |Number |yes |Current power consumption in Watts |
| |lastPower1 |Number |yes |Energy consumption in Watts for a round minute, 1 minute ago |
| |totalKWH |Number |yes |Total energy consumption in Watts since the device powered up (resets on restart)|
Expand Down Expand Up @@ -508,9 +515,7 @@ The Shelly 4Pro provides 4 relays and 4 power meters.
| |autoOn |Number |r/w |Sets a timer to turn the device ON after every OFF command; in seconds |
| |autoOff |Number |r/w |Sets a timer to turn the device OFF after every ON command; in seconds |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
|status |loaderror |Switch |yes |Last error, "no" if none |
| |overload |Switch |yes |Overload condition detected, switch dimmer off or reduce load! |
| |overtemperature |Switch|yes |Internal device temperature over maximum. Switch off, check physical installation|
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter |currentWatts |Number |yes |Current power consumption in Watts |
| |lastPower1 |Number |yes |Energy consumption in Watts for a round minute, 1 minute ago |
| |lastPower2 |Number |yes |Energy consumption in Watts for a round minute, 2 minutes ago |
Expand All @@ -528,9 +533,7 @@ The Shelly 4Pro provides 4 relays and 4 power meters.
| |autoOn |Number |r/w |Sets a timer to turn the device ON after every OFF command; in seconds |
| |autoOff |Number |r/w |Sets a timer to turn the device OFF after every ON command; in seconds |
| |button |Trigger |yes |Event trigger with payload SHORT_PRESSED or LONG_PRESSED (FW 1.5.6+) |
|status |loaderror |Switch |yes |Last error, "no" if none |
| |overload |Switch |yes |Overload condition detected, switch dimmer off or reduce load! |
| |overtemperature |Switch|yes |Internal device temperature over maximum. Switch off, check physical installation|
| |outputName |String |yes |Logical name of this relay output as configured in the Shelly App |
|meter |currentWatts |Number |yes |Current power consumption in Watts |
| |lastPower1 |Number |yes |Energy consumption in Watts for a round minute, 1 minute ago |
| |lastPower2 |Number |yes |Energy consumption in Watts for a round minute, 2 minutes ago |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public class ShellyBindingConstants {

// Relay
public static final String CHANNEL_GROUP_RELAY_CONTROL = "relay";
public static final String CHANNEL_OUTPUT_NAME = "outputName";
public static final String CHANNEL_OUTPUT = "output";
public static final String CHANNEL_INPUT = "input";
public static final String CHANNEL_INPUT1 = "input1";
Expand Down Expand Up @@ -215,10 +216,6 @@ public class ShellyBindingConstants {
public static final String CHANNEL_EMETER_CURRENT = "current";
public static final String CHANNEL_EMETER_PFACTOR = "powerFactor";

public static final String CHANNEL_GROUP_LED_CONTROL = "led";
public static final String CHANNEL_LED_STATUS_DISABLE = "statusLed";
public static final String CHANNEL_LED_POWER_DISABLE = "powerLed";

public static final String CHANNEL_GROUP_SENSOR = "sensors";
public static final String CHANNEL_SENSOR_TEMP = "temperature";
public static final String CHANNEL_SENSOR_HUM = "humidity";
Expand Down Expand Up @@ -272,6 +269,7 @@ public class ShellyBindingConstants {

// Device Status
public static final String CHANNEL_GROUP_DEV_STATUS = "device";
public static final String CHANNEL_DEVST_NAME = "deviceName";
public static final String CHANNEL_DEVST_UPTIME = "uptime";
public static final String CHANNEL_DEVST_HEARTBEAT = "heartBeat";
public static final String CHANNEL_DEVST_RSSI = "wifiSignal";
Expand All @@ -285,6 +283,8 @@ public class ShellyBindingConstants {
public static final String CHANNEL_DEVST_UPDATE = "updateAvailable";
public static final String CHANNEL_DEVST_SELFTTEST = "selfTest";

public static final String CHANNEL_LED_STATUS_DISABLE = "statusLed";
public static final String CHANNEL_LED_POWER_DISABLE = "powerLed";
// Button/xi3
public static final String CHANNEL_GROUP_STATUS = "status";
public static final String CHANNEL_STATUS_EVENTTYPE = "lastEvent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ public static class ShellySettingsAttributes {
}

public static class ShellySettingsStatus {
public String name; // FW 1.8: Symbolic Device name is configurable

@SerializedName("wifi_sta")
public ShellySettingsWiFiNetwork wifiSta; // WiFi client configuration. See /settings/sta for details

Expand Down Expand Up @@ -687,6 +689,7 @@ public static class ShellyControlRelay {
}

public static class ShellyShortStatusRelay {
public String name; // FW 1.8+: Channel could now have a logical name
@SerializedName("is_valid")
public Boolean isValid;
public Boolean ison; // Whether output channel is on or off
Expand All @@ -712,6 +715,8 @@ public static class ShellyShortLightStatus {
}

public static class ShellyStatusRelay {
public String name; // FW 1.8: Symbolic channel name is configurable

@SerializedName("wifi_sta")
public ShellySettingsWiFiNetwork wifiSta; // WiFi status
// public ShellyStatusCloud cloud; // Cloud status
Expand Down Expand Up @@ -780,6 +785,8 @@ public static class ShellyStatusDimmer {
}

public static class ShellyControlRoller {
public String name; // FW 1.8: Symbolic name is configurable

@SerializedName("roller_pos")
public Integer rollerPos; // number Desired position in percent
public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.shelly.internal.ShellyBindingConstants;
import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsDimmer;
import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsGlobal;
import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsInput;
import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsRelay;
import org.openhab.binding.shelly.internal.api.ShellyApiJsonDTO.ShellySettingsStatus;
import org.openhab.binding.shelly.internal.util.ShellyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -70,8 +67,6 @@ public class ShellyDeviceProfile {
public int numRollers = 0; // number of Rollers, usually 1
public boolean isRoller = false; // true for Shelly2 in roller mode
public boolean isDimmer = false; // true for a Shelly Dimmer (SHDM-1)
public boolean isPlugS = false; // true if it is a Shelly Plug S
public int numHumSensors = 0; // number of external humidity sensors

public int numMeters = 0;
public boolean isEMeter = false; // true for ShellyEM/3EM
Expand All @@ -81,7 +76,6 @@ public class ShellyDeviceProfile {
public boolean isDuo = false; // true only if it is a Duo
public boolean isRGBW2 = false; // true only if it a a RGBW2
public boolean inColor = false; // true if bulb/rgbw2 is in color mode
public boolean hasLed = false; // true if battery device

public boolean isSensor = false; // true for HT & Smoke
public boolean hasBattery = false; // true if battery device
Expand Down Expand Up @@ -116,17 +110,17 @@ public ShellyDeviceProfile initialize(String thingType, String json) throws Shel
}

// General settings
deviceType = ShellyUtils.getString(settings.device.type);
deviceType = getString(settings.device.type);
mac = getString(settings.device.mac);
hostname = settings.device.hostname != null && !settings.device.hostname.isEmpty()
? settings.device.hostname.toLowerCase()
: "shelly-" + mac.toUpperCase().substring(6, 11);
mode = !getString(settings.mode).isEmpty() ? getString(settings.mode).toLowerCase() : "";
hwRev = settings.hwinfo != null ? getString(settings.hwinfo.hwRevision) : "";
hwBatchId = settings.hwinfo != null ? getString(settings.hwinfo.batchId.toString()) : "";
fwDate = getString(StringUtils.substringBefore(settings.fw, "/"));
fwVersion = getString(StringUtils.substringBetween(settings.fw, "/", "@"));
fwId = getString(StringUtils.substringAfter(settings.fw, "@"));
fwDate = substringBefore(settings.fw, "/");
fwVersion = substringBetween(settings.fw, "/", "@");
fwId = substringAfter(settings.fw, "@");
discoverable = (settings.discoverable == null) || settings.discoverable;

inColor = isLight && mode.equalsIgnoreCase(SHELLY_MODE_COLOR);
Expand Down Expand Up @@ -177,17 +171,14 @@ public boolean isInitialized() {
}

public void initFromThingType(String name) {
String thingType = (name.contains("-") ? StringUtils.substringBefore(name, "-") : name).toLowerCase().trim();
String thingType = (name.contains("-") ? substringBefore(name, "-") : name).toLowerCase().trim();
if (thingType.isEmpty()) {
return;
}

isPlugS = thingType.equals(ShellyBindingConstants.THING_TYPE_SHELLYPLUGS_STR);

isBulb = thingType.equals(THING_TYPE_SHELLYBULB_STR);
isDuo = thingType.equals(THING_TYPE_SHELLYDUO_STR) || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR);
isRGBW2 = thingType.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX);
hasLed = isPlugS;
isLight = isBulb || isDuo || isRGBW2;
if (isLight) {
minTemp = isBulb ? MIN_COLOR_TEMP_BULB : MIN_COLOR_TEMP_DUO;
Expand Down
Loading

0 comments on commit 58e9eb9

Please sign in to comment.