From a32ac52ab7a9bc5fcd4eccfc1bfcc6fe80d96fe0 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sun, 10 Nov 2024 19:36:18 +0100 Subject: [PATCH] [shelly] Add support for Shelly Plus RGBW PM (#17692) * [shelly] Add support for Shelly Plus RGBW PM Signed-off-by: Jan N. Klug --- bundles/org.openhab.binding.shelly/README.md | 3 +- .../internal/ShellyBindingConstants.java | 1 + .../shelly/internal/ShellyHandlerFactory.java | 3 +- .../internal/api/ShellyDeviceProfile.java | 3 +- .../internal/api2/Shelly2ApiClient.java | 39 ++++++++++++++ .../internal/api2/Shelly2ApiJsonDTO.java | 24 +++++++++ .../shelly/internal/api2/Shelly2ApiRpc.java | 52 +++++++++++++++++++ .../discovery/ShellyThingCreator.java | 6 +++ .../internal/handler/ShellyComponents.java | 21 ++++++++ .../internal/handler/ShellyLightHandler.java | 6 +-- .../provider/ShellyChannelDefinitions.java | 6 +-- .../resources/OH-INF/i18n/shelly.properties | 7 ++- .../OH-INF/thing/shellyGen2_lights.xml | 40 ++++++++++++++ 13 files changed, 201 insertions(+), 10 deletions(-) create mode 100644 bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_lights.xml diff --git a/bundles/org.openhab.binding.shelly/README.md b/bundles/org.openhab.binding.shelly/README.md index 78dc8278e24..572b6e1f3a3 100644 --- a/bundles/org.openhab.binding.shelly/README.md +++ b/bundles/org.openhab.binding.shelly/README.md @@ -81,7 +81,7 @@ See section [Discovery](#discovery) for details. ### Generation 2 Plus series | thing-type | Model | Vendor ID | -| -------------------- | -------------------------------------------------------- | ---------------------------- | +|----------------------|----------------------------------------------------------|------------------------------| | shellyplus1 | Shelly Plus 1 with 1x relay | SNSW-001X16EU, S3SW-001X16EU | | shellyplus1pm | Shelly Plus 1PM with 1x relay + power meter | SNSW-001P16EU, S3SW-001P16EU | | shellyplus2pm-relay | Shelly Plus 2PM with 2x relay + power meter, relay mode | SNSW-002P16EU, SNSW-102P16EU | @@ -97,6 +97,7 @@ See section [Discovery](#discovery) for details. | shellyhtg3 | Shelly Plus HT Gen 3 with temperature + humidity sensor | S3SN-0U12A | | shellyplussmoke | Shelly Plus Smoke sensor | SNSN-0031Z | | shellypluswdus | Shelly Plus Wall Dimmer US | SNDM-0013US | +| shellyplusrgbwpm | Shelly Plus RGBW PM | SNDC-0D4P10WW | | shellywalldisplay | Shelly Plus Wall Display | SAWD-0A1XX10EU1 | | shellyblugw | SHelly BLU Gateway | SNGW-BT01 | diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java index bdb1215e722..a94fe868d61 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyBindingConstants.java @@ -82,6 +82,7 @@ public class ShellyBindingConstants { THING_TYPE_SHELLYPLUSPLUGS, // THING_TYPE_SHELLYPLUSPLUGUS, // THING_TYPE_SHELLYPLUSDIMMERUS, // + THING_TYPE_SHELLYPLUSRGBWPM, // // Shelly Wall Display THING_TYPE_SHELLYPLUSWALLDISPLAY, // diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java index 7fb4df94a35..44c2c5cf77f 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/ShellyHandlerFactory.java @@ -126,7 +126,8 @@ public class ShellyHandlerFactory extends BaseThingHandlerFactory { || thingType.equals(THING_TYPE_SHELLYRGBW2_COLOR_STR) || thingType.equals(THING_TYPE_SHELLYRGBW2_WHITE_STR) || thingType.equals(THING_TYPE_SHELLYRGBW2_WHITE_STR) || thingType.equals(THING_TYPE_SHELLYDUORGBW_STR) - || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR)) { + || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR) + || thingType.equals(THING_TYPE_SHELLYPLUSRGBWPM_STR)) { logger.debug("{}: Create new thing of type {} using ShellyLightHandler", thing.getLabel(), thingTypeUID.toString()); handler = new ShellyLightHandler(thing, messages, bindingConfig, thingTable, coapServer, httpClient); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java index 584667f4349..03190e352b4 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java @@ -208,7 +208,8 @@ public class ShellyDeviceProfile { isBulb = thingType.equals(THING_TYPE_SHELLYBULB_STR); isDuo = thingType.equals(THING_TYPE_SHELLYDUO_STR) || thingType.equals(THING_TYPE_SHELLYVINTAGE_STR) || thingType.equals(THING_TYPE_SHELLYDUORGBW_STR); - isRGBW2 = thingType.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX); + isRGBW2 = thingType.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX) + || thingType.equals(THING_TYPE_SHELLYPLUSRGBWPM_STR); isLight = isBulb || isDuo || isRGBW2; if (isLight) { minTemp = isBulb ? MIN_COLOR_TEMP_BULB : MIN_COLOR_TEMP_DUO; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java index 138d7fb4f64..7b536773a07 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java @@ -20,6 +20,7 @@ import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Random; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -67,6 +68,7 @@ import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceS import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusPower; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusSmoke; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusTempId; +import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBWStatus; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2InputStatus; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RelayStatus; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage; @@ -196,6 +198,7 @@ public class Shelly2ApiClient extends ShellyHttpClient { updated |= updateEmStatus(status, result.em11, channelUpdate); updated |= updateRollerStatus(status, result.cover0, channelUpdate); updated |= updateDimmerStatus(status, result.light0, channelUpdate); + updated |= updateRGBWStatus(status, result.rgbw0, channelUpdate); if (channelUpdate) { updated |= ShellyComponents.updateMeters(getThing(), status); } @@ -587,6 +590,21 @@ public class Shelly2ApiClient extends ShellyHttpClient { } } + protected void fillRgbwSettings(ShellyDeviceProfile profile, Shelly2GetConfigResult dc) { + if (!profile.isRGBW2 || dc.rgbw0 == null) { + return; + } + + List lights = profile.settings.lights; + if (lights != null) { + ShellySettingsRgbwLight ls = lights.get(0); + ls.autoOn = dc.rgbw0.autoOnDelay; + ls.autoOff = dc.rgbw0.autoOffDelay; + ls.name = dc.rgbw0.name; + lights.set(0, ls); + } + } + private boolean updateDimmerStatus(ShellySettingsStatus status, @Nullable Shelly2DeviceStatusLight value, boolean channelUpdate) throws ShellyApiException { ShellyDeviceProfile profile = getProfile(); @@ -605,6 +623,27 @@ public class Shelly2ApiClient extends ShellyHttpClient { return channelUpdate ? ShellyComponents.updateDimmers(getThing(), status) : false; } + private boolean updateRGBWStatus(ShellySettingsStatus status, @Nullable Shelly2RGBWStatus value, + boolean channelUpdate) throws ShellyApiException { + ShellyDeviceProfile profile = getProfile(); + if (!profile.isRGBW2 || value == null) { + return false; + } + + ShellySettingsLight ds = status.lights.get(0); + ds.brightness = Objects.requireNonNullElse(value.brightness, ds.brightness).intValue(); + if (value.rgb != null) { + ds.red = value.rgb[0]; + ds.green = value.rgb[1]; + ds.blue = value.rgb[2]; + } + ds.white = Objects.requireNonNullElse(value.white, ds.white); + ds.ison = value.output; + + status.lights.set(0, ds); + return channelUpdate ? ShellyComponents.updateRGBW(getThing(), status) : false; + } + protected @Nullable Integer getDuration(@Nullable Double timerStartedAt, @Nullable Double timerDuration) { if (timerStartedAt == null || timerDuration == null) { return null; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java index 55cadfd360e..bea3faadf9c 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java @@ -54,6 +54,8 @@ public class Shelly2ApiJsonDTO { public static final String SHELLYRPC_METHOD_LIGHT_STATUS = "Light.GetStatus"; public static final String SHELLYRPC_METHOD_LIGHT_SET = "Light.Set"; public static final String SHELLYRPC_METHOD_LIGHT_SETCONFIG = "Light.SetConfig"; + public static final String SHELLYRPC_METHOD_RGBW_STATUS = "RGBW.GetStatus"; + public static final String SHELLYRPC_METHOD_RGBW_SET = "RGBW.Set"; public static final String SHELLYRPC_METHOD_LED_SETCONFIG = "WD_UI.SetConfig"; public static final String SHELLYRPC_METHOD_WIFIGETCONG = "Wifi.GetConfig"; public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig"; @@ -499,6 +501,9 @@ public class Shelly2ApiJsonDTO { @SerializedName("light:0") public Shelly2GetConfigLight light0; + @SerializedName("rgbw:0") + public Shelly2GetConfigLight rgbw0; + @SerializedName("smoke:0") public Shelly2ConfigSmoke smoke0; } @@ -723,6 +728,20 @@ public class Shelly2ApiJsonDTO { public Boolean mute; } + public static class Shelly2RGBWStatus { + public Integer id; + public String source; + public Boolean output; + public Integer[] rgb; + public Double brightness; + public Integer white; + public Shelly2DeviceStatusTemp temperature; + public Shelly2Energy aenergy; + public Double apower; + public Double voltage; + public Double current; + } + public Shelly2DeviceStatusBle ble; public Shelly2DeviceStatusCloud cloud; public Shelly2DeviceStatusMqqt mqtt; @@ -740,6 +759,9 @@ public class Shelly2ApiJsonDTO { @SerializedName("input:100") public Shelly2InputStatus input100; // Digital Input from Add-On + @SerializedName("rgbw:0") + public Shelly2RGBWStatus rgbw0; + @SerializedName("switch:0") public Shelly2RelayStatus switch0; @SerializedName("switch:1") @@ -965,6 +987,8 @@ public class Shelly2ApiJsonDTO { public Integer brightness; @SerializedName("toggle_after") public Integer toggleAfter; + public Integer white; + public Integer[] rgb; // Shelly.SetAuth public String user; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java index fee00d32463..89b3946846b 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java @@ -68,6 +68,7 @@ import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceC import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceSettings; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusLight; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult; +import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBWStatus; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusSys.Shelly2DeviceStatusSysAvlUpdate; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2NotifyEvent; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage; @@ -306,6 +307,14 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac fillDimmerSettings(profile, dc); } profile.status.lights = profile.isBulb ? new ArrayList<>() : null; + if (profile.isRGBW2) { + ArrayList rgbwLights = new ArrayList<>(); + rgbwLights.add(new ShellySettingsRgbwLight()); + profile.settings.lights = rgbwLights; + profile.status.lights = new ArrayList<>(); + profile.status.lights.add(new ShellySettingsLight()); + fillRgbwSettings(profile, dc); + } profile.status.thermostats = profile.isTRV ? new ArrayList<>() : null; if (profile.hasBattery) { @@ -920,6 +929,26 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac @Override public ShellyStatusLight getLightStatus() throws ShellyApiException { + ShellyDeviceProfile profile = getProfile(); + if (profile.isRGBW2) { + Shelly2RGBWStatus ls = apiRequest( + new Shelly2RpcRequest().withMethod(SHELLYRPC_METHOD_RGBW_STATUS).withId(0), + Shelly2RGBWStatus.class); + ShellyStatusLightChannel lightChannel = new ShellyStatusLightChannel(); + lightChannel.red = ls.rgb[0]; + lightChannel.green = ls.rgb[1]; + lightChannel.blue = ls.rgb[2]; + lightChannel.white = ls.white; + lightChannel.brightness = ls.brightness.intValue(); + + ShellyStatusLight status = new ShellyStatusLight(); + status.lights = new ArrayList<>(); + status.lights.add(lightChannel); + status.ison = ls.output; + + return status; + } + throw new ShellyApiException("API call not implemented"); } @@ -1122,6 +1151,29 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac @Override public void setLightParms(int lightIndex, Map parameters) throws ShellyApiException { + Shelly2RpcRequestParams params = new Shelly2RpcRequestParams(); + if (getProfile().isRGBW2) { + String brightness = parameters.get(SHELLY_COLOR_BRIGHTNESS); + if (brightness != null) { + params.brightness = Integer.parseInt(brightness); + } + String red = parameters.get(SHELLY_COLOR_RED); + String green = parameters.get(SHELLY_COLOR_GREEN); + String blue = parameters.get(SHELLY_COLOR_BLUE); + if (red != null && green != null && blue != null) { + params.rgb = new Integer[] { Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue) }; + } + String white = parameters.get(SHELLY_COLOR_WHITE); + if (white != null) { + params.white = Integer.parseInt(white); + } + if (parameters.containsKey(SHELLY_LIGHT_TURN)) { + params.on = SHELLY_API_ON.equals(parameters.get(SHELLY_LIGHT_TURN)); + } + params.id = lightIndex; + + apiRequest(SHELLYRPC_METHOD_RGBW_SET, params, String.class); + } throw new ShellyApiException("API call not implemented"); } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java index 339661b30d3..108e6eb574d 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java @@ -89,6 +89,7 @@ public class ShellyThingCreator { public static final String SHELLYDT_PLUSDIMMER10V = "SNDM-00100WW"; public static final String SHELLYDT_PLUSDIMMER0110VG3 = "S3DM-0010WW"; public static final String SHELLYDT_PLUSWALLDISPLAY = "SAWD-0A1XX10EU1"; + public static final String SHELLYDT_PLUSRGBWPM = "SNDC-0D4P10WW"; // Shelly Pro Series public static final String SHELLYDT_PRO1 = "SPSW-001XE16EU"; @@ -189,6 +190,7 @@ public class ShellyThingCreator { public static final String THING_TYPE_SHELLYPLUSDIMMERUS_STR = "shellypluswdus"; public static final String THING_TYPE_SHELLYPLUSDIMMER10V_STR = "shellyplus10v"; public static final String THING_TYPE_SHELLYPLUSDIMMER0110VG3_STR = "shelly0110dimg3"; + public static final String THING_TYPE_SHELLYPLUSRGBWPM_STR = "shellyplusrgbwpm"; // Shelly Wall Display public static final String THING_TYPE_SHELLYPLUSWALLDISPLAY_STR = "shellywalldisplay"; @@ -305,6 +307,8 @@ public class ShellyThingCreator { THING_TYPE_SHELLYPLUSDIMMERUS_STR); public static final ThingTypeUID THING_TYPE_SHELLYPLUSDIMMER10V = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUSDIMMER10V_STR); + public static final ThingTypeUID THING_TYPE_SHELLYPLUSRGBWPM = new ThingTypeUID(BINDING_ID, + THING_TYPE_SHELLYPLUSRGBWPM_STR); // Shelly Wall Display public static final ThingTypeUID THING_TYPE_SHELLYPLUSWALLDISPLAY = new ThingTypeUID(BINDING_ID, @@ -398,6 +402,7 @@ public class ShellyThingCreator { THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMERUS, THING_TYPE_SHELLYPLUSDIMMERUS_STR); THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMER10V, THING_TYPE_SHELLYPLUSDIMMER10V_STR); THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMER0110VG3, THING_TYPE_SHELLYPLUSDIMMER10V_STR); + THING_TYPE_MAPPING.put(SHELLYDT_PLUSRGBWPM, THING_TYPE_SHELLYPLUSRGBWPM_STR); // Plus Mini Series THING_TYPE_MAPPING.put(SHELLYDT_MINI1, THING_TYPE_SHELLY1MINI_STR); @@ -487,6 +492,7 @@ public class ShellyThingCreator { THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMERUS_STR, THING_TYPE_SHELLYPLUSDIMMERUS_STR); THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMER10V_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR); THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMER0110VG3_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR); + THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSRGBWPM_STR, THING_TYPE_SHELLYPLUSRGBWPM_STR); THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSWALLDISPLAY_STR, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java index fd76955c3e3..b8bbc91f040 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java @@ -569,6 +569,27 @@ public class ShellyComponents { return updated; } + public static boolean updateRGBW(ShellyThingInterface thingHandler, ShellySettingsStatus orgStatus) + throws ShellyApiException { + boolean updated = false; + ShellyDeviceProfile profile = thingHandler.getProfile(); + if (profile.isRGBW2) { + if (!thingHandler.areChannelsCreated()) { + return false; + } + ShellySettingsLight light = orgStatus.lights.get(0); + ShellyColorUtils col = new ShellyColorUtils(); + col.setRGBW(light.red, light.green, light.blue, light.white); + updated |= thingHandler.updateChannel(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_RED, col.percentRed); + updated |= thingHandler.updateChannel(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_GREEN, col.percentGreen); + updated |= thingHandler.updateChannel(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_BLUE, col.percentBlue); + updated |= thingHandler.updateChannel(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_WHITE, col.percentWhite); + updated |= thingHandler.updateChannel(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_PICKER, col.toHSB()); + + } + return updated; + } + public static boolean updateDimmers(ShellyThingInterface thingHandler, ShellySettingsStatus orgStatus) throws ShellyApiException { boolean updated = false; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java index 15bd9cf2d6f..b80fc161cb5 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java @@ -353,7 +353,7 @@ public class ShellyLightHandler extends ShellyBaseHandler { postEvent(ALARM_TYPE_OVERPOWER, false); } - if (profile.inColor) { + if (profile.inColor || (profile.isGen2 && profile.isRGBW2)) { logger.trace("{}: update color settings", thingName); col.setRGBW(getInteger(light.red), getInteger(light.green), getInteger(light.blue), getInteger(light.white)); @@ -376,7 +376,7 @@ public class ShellyLightHandler extends ShellyBaseHandler { updated |= updateChannel(colorGroup, CHANNEL_COLOR_PICKER, col.toHSB()); } - if (!profile.inColor || profile.isBulb) { + if ((!profile.inColor && !profile.isGen2) || profile.isBulb) { String whiteGroup = buildWhiteGroupName(profile, channelId); col.setBrightness(getInteger(light.brightness)); updated |= updateChannel(whiteGroup, CHANNEL_BRIGHTNESS + "$Switch", col.power); @@ -458,7 +458,7 @@ public class ShellyLightHandler extends ShellyBaseHandler { if (autoOn && (newCol.brightness >= 0)) { parms.put(SHELLY_LIGHT_TURN, profile.inColor || newCol.brightness > 0 ? SHELLY_API_ON : SHELLY_API_OFF); } - if (profile.inColor) { + if (profile.inColor || (profile.isGen2 && profile.isRGBW2)) { if (oldCol.red != newCol.red || oldCol.green != newCol.green || oldCol.blue != newCol.blue || oldCol.white != newCol.white) { logger.debug("{}: Setting RGBW to {}/{}/{}/{}", thingName, newCol.red, newCol.green, newCol.blue, diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java index a2689f72433..76bce5389a6 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java @@ -431,14 +431,14 @@ public class ShellyChannelDefinitions { List lights = profile.settings.lights; if (lights != null) { ShellySettingsRgbwLight light = lights.get(idx); - String whiteGroup = profile.isRGBW2 ? group : CHANNEL_GROUP_WHITE_CONTROL; + String whiteGroup = profile.isRGBW2 && !profile.isGen2 ? group : CHANNEL_GROUP_WHITE_CONTROL; // Create power channel in color mode and brightness channel in white mode addChannel(thing, add, profile.inColor, group, CHANNEL_LIGHT_POWER); addChannel(thing, add, light.autoOn != null, group, CHANNEL_TIMER_AUTOON); addChannel(thing, add, light.autoOff != null, group, CHANNEL_TIMER_AUTOOFF); addChannel(thing, add, status.hasTimer != null, group, CHANNEL_TIMER_ACTIVE); - addChannel(thing, add, light.brightness != null, whiteGroup, CHANNEL_BRIGHTNESS); - addChannel(thing, add, light.temp != null, whiteGroup, CHANNEL_COLOR_TEMP); + addChannel(thing, add, status.brightness != null, whiteGroup, CHANNEL_BRIGHTNESS); + addChannel(thing, add, status.temp != null, whiteGroup, CHANNEL_COLOR_TEMP); } return add; diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties index bd03c597a24..f023763233e 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties @@ -88,7 +88,7 @@ thing-type.shelly.shellygas.description = Shelly Gas (Gas Sensor - Gas Leak Dete thing-type.shelly.shellytrv.description = Shelly TRV (Radiator value, battery powered) thing-type.shelly.shellyix3.description = Shelly ix3 (Activation Device with 3 inputs) thing-type.shelly.shellypludht.description = Shelly Plus HT - Temperature and Humidity Sensor - +thing-type.shelly.shellyplusrgbw.description = Shelly Plus RGBW PM - LED Controller with Power Meter # Plus Devices thing-type.shelly.shellyplus1.description = Shelly Plus 1 (Single Relay Switch) thing-type.shelly.shellyplus1pm.description = Shelly Plus 1PM - Single Relay Switch with Power Meter @@ -102,6 +102,7 @@ thing-type.shelly.shellyplushtg3.description = Shelly Plus HT Gen 3 - Humidity a thing-type.shelly.shellyplussmoke.description = Shelly Plus Smoke - Smoke Detector with Alarm thing-type.shelly.shellypluswdus.description = Shelly Wall Dimmer US Device thing-type.shelly.shellyplus10v.description = Shelly Plus Dimmer 10V +thing-type.shelly.shellyplusrgbwpm-color.description = Shelly Plus RGBW PM - RGBW Dimmer with Power Meter # Plus Mini Devices thing-type.shelly.shelly1mini.description = Shelly Plus Mini 1 - Single Relay Switch @@ -188,12 +189,16 @@ channel-group-type.shelly.duoControl.label = Light Control channel-group-type.shelly.duoControl.description = Control your light channel-group-type.shelly.rgbw2ColorControl.label = LED Strip Control (RGBW) channel-group-type.shelly.rgbw2ColorControl.description = Control your LED stripes in color mode +channel-group-type.shelly.rgbwpmColorControl.label = LED Strip Control (RGBW) +channel-group-type.shelly.rgbwpmColorControl.description = Control your LED stripes channel-group-type.shelly.rgbw2WhiteControl.label = LED Strip Control (White) channel-group-type.shelly.rgbw2WhiteControl.description = Control your LED stripes in white mode channel-group-type.shelly.colorSettingsBulb.label = Colors channel-group-type.shelly.colorSettingsBulb.description = Light colors channel-group-type.shelly.colorSettingsRGBW2.label = Colors channel-group-type.shelly.colorSettingsRGBW2.description = Light colors +channel-group-type.shelly.colorSettingsRGBWpm.label = Colors +channel-group-type.shelly.colorSettingsRGBWpm.description = Light colors channel-group-type.shelly.whiteSettings.label = White settings channel-group-type.shelly.whiteSettings.description = Adjust colors when device is in white mode channel-group-type.shelly.whiteSettingsSimple.label = White settings diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_lights.xml b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_lights.xml new file mode 100644 index 00000000000..e4612cc16f3 --- /dev/null +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_lights.xml @@ -0,0 +1,40 @@ + + + + + + @text/thing-type.shelly.shellyplusrgbw.description + ColorLight + + + + + + + + serviceName + + + + + + @text/channel-group-type.shelly.rgbwpmColorControl.description + + + + + @text/channel-group-type.shelly.colorSettingsRGBWpm.description + + + + + + + + + + +