Skip to content

Commit 4a5ab9c

Browse files
committed
implement white control (CCT) vs. color control (RGB) and white temp
channel Signed-off-by: Markus Michels <markus7017@gmail.com>
1 parent fda2178 commit 4a5ab9c

11 files changed

Lines changed: 397 additions & 104 deletions

File tree

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class ShellyDeviceProfile {
9595
public boolean isDuo; // true only if it is a Duo
9696
public boolean isRGBW2; // true only if it a RGBW2
9797
public boolean isRGBBulb; // true for Gen3 Multicolor Bulb (rgb:0 component, RGB+CCT)
98+
public boolean isRGBCCT; // true for Gen3 Duo Bulb with rgbcct:0 component (RGB + CCT mode switching)
9899
public boolean inColor; // true if bulb/rgbw2 is in color mode
99100

100101
public boolean isSensor; // true for HT & Smoke

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBStatus;
8888
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBWStatus;
8989
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2InputStatus;
90+
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2RGBCCTStatus;
9091
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RelayStatus;
9192
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage;
9293
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2StatusEm1;
@@ -373,7 +374,7 @@ protected Shelly2GetConfigResult initProfile(ShellyDeviceProfile profile, ThingT
373374
profile.status.lights.add(new ShellySettingsLight());
374375
fillRgbwSettings(profile, dc);
375376
}
376-
if (profile.isDuo && profile.isGen2) {
377+
if (profile.isDuo) {
377378
fillDuoBulbSettings(profile, dc);
378379
}
379380
if (profile.isRGBBulb) {
@@ -550,7 +551,7 @@ protected boolean fillDeviceStatus(ShellySettingsStatus status, Shelly2DeviceSta
550551
updated |= updateEmStatus(11, status, result.em11, channelUpdate);
551552
updated |= updateRollerStatus(0, status, result.cover0, channelUpdate);
552553
updated |= updateDimmerStatus(0, status, result.light0, channelUpdate);
553-
updated |= updateDuoBulbStatus(0, status, result.cct0, channelUpdate);
554+
updated |= updateDuoBulbStatus(0, status, result.cct0, result.rgbcct0, channelUpdate);
554555
updated |= updateRGBWStatus(0, status, result.rgbw0, channelUpdate);
555556
updated |= updateRGBBulbStatus(0, status, result.rgb0, channelUpdate);
556557
if (channelUpdate) {
@@ -1064,10 +1065,15 @@ protected void fillRgbwSettings(ShellyDeviceProfile profile, Shelly2GetConfigRes
10641065
}
10651066

10661067
protected void fillDuoBulbSettings(ShellyDeviceProfile profile, Shelly2GetConfigResult dc) {
1067-
if (!(profile.isDuo && profile.isGen2)) {
1068+
if (!profile.isDuo) {
10681069
return;
10691070
}
1070-
applyBulbLightSettings(profile, dc.cct0);
1071+
if (dc.rgbcct0 != null) {
1072+
profile.isRGBCCT = true;
1073+
applyBulbLightSettings(profile, dc.rgbcct0);
1074+
} else {
1075+
applyBulbLightSettings(profile, dc.cct0);
1076+
}
10711077
}
10721078

10731079
protected void fillRGBBulbSettings(ShellyDeviceProfile profile, Shelly2GetConfigResult dc) {
@@ -1125,13 +1131,24 @@ private boolean updateRGBWStatus(int id, ShellySettingsStatus status, @Nullable
11251131
value.white, null, channelUpdate, true);
11261132
}
11271133

1128-
private boolean updateDuoBulbStatus(int id, ShellySettingsStatus status, @Nullable Shelly2CCTStatus value,
1129-
boolean channelUpdate) throws ShellyApiException {
1134+
private boolean updateDuoBulbStatus(int id, ShellySettingsStatus status, @Nullable Shelly2CCTStatus cctValue,
1135+
@Nullable Shelly2RGBCCTStatus rgbcctValue, boolean channelUpdate) throws ShellyApiException {
11301136
ShellyDeviceProfile profile = getProfile();
1131-
if (!(profile.isDuo && profile.isGen2) || value == null) {
1137+
if (!profile.isDuo) {
1138+
return false;
1139+
}
1140+
if (profile.isRGBCCT && rgbcctValue != null) {
1141+
boolean inColor = "rgb".equals(rgbcctValue.mode);
1142+
profile.inColor = inColor;
1143+
profile.device.mode = inColor ? SHELLY_MODE_COLOR : SHELLY_MODE_WHITE;
1144+
return applyLightStatus(status, 0, rgbcctValue.output, rgbcctValue.brightness,
1145+
inColor ? rgbcctValue.rgb : null, null, inColor ? null : rgbcctValue.ct, channelUpdate, false);
1146+
}
1147+
if (cctValue == null) {
11321148
return false;
11331149
}
1134-
return applyLightStatus(status, 0, value.output, value.brightness, null, null, value.ct, channelUpdate, false);
1150+
return applyLightStatus(status, 0, cctValue.output, cctValue.brightness, null, null, cctValue.ct, channelUpdate,
1151+
false);
11351152
}
11361153

11371154
private boolean updateRGBBulbStatus(int id, ShellySettingsStatus status, @Nullable Shelly2RGBStatus value,

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class Shelly2ApiJsonDTO {
6565
public static final String SHELLYRPC_METHOD_CCT_STATUS = "CCT.GetStatus";
6666
public static final String SHELLYRPC_METHOD_CCT_SET = "CCT.Set";
6767
public static final String SHELLYRPC_METHOD_CCT_SETCONFIG = "CCT.SetConfig";
68+
public static final String SHELLYRPC_METHOD_RGBCCT_STATUS = "RGBCCT.GetStatus";
69+
public static final String SHELLYRPC_METHOD_RGBCCT_SET = "RGBCCT.Set";
70+
public static final String SHELLYRPC_METHOD_RGBCCT_SETCONFIG = "RGBCCT.SetConfig";
6871
public static final String SHELLYRPC_METHOD_LED_SETCONFIG = "WD_UI.SetConfig";
6972
public static final String SHELLYRPC_METHOD_WIFIGETCONG = "Wifi.GetConfig";
7073
public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig";
@@ -540,6 +543,9 @@ public class Shelly2DevConfigMqtt {
540543
@SerializedName("cct:0")
541544
public @Nullable Shelly2GetConfigLight cct0;
542545

546+
@SerializedName("rgbcct:0")
547+
public @Nullable Shelly2GetConfigLight rgbcct0;
548+
543549
@SerializedName("smoke:0")
544550
public Shelly2ConfigSmoke smoke0;
545551
}
@@ -636,6 +642,20 @@ public static class Shelly2CCTStatus {
636642
public @Nullable Double apower;
637643
}
638644

645+
// Devices with combined RGB + CCT support — component "rgbcct:0"
646+
// mode="cct": ct field valid; mode="rgb": rgb array valid
647+
public static class Shelly2RGBCCTStatus {
648+
public @Nullable Integer id;
649+
public @Nullable String source;
650+
public @Nullable String mode; // "cct" or "rgb"
651+
public @Nullable Boolean output;
652+
public @Nullable Double brightness;
653+
public @Nullable Integer[] rgb; // [R, G, B] 0-255, valid when mode="rgb"
654+
public @Nullable Integer ct; // color temperature K, valid when mode="cct"
655+
public @Nullable Shelly2Energy aenergy;
656+
public @Nullable Double apower;
657+
}
658+
639659
public static class Shelly2DeviceStatusResult {
640660
public class Shelly2DeviceStatusBle {
641661

@@ -870,6 +890,9 @@ public static class Shelly2RGBStatus {
870890
@SerializedName("cct:0")
871891
public @Nullable Shelly2CCTStatus cct0;
872892

893+
@SerializedName("rgbcct:0")
894+
public @Nullable Shelly2RGBCCTStatus rgbcct0;
895+
873896
@SerializedName("temperature:0")
874897
public Shelly2DeviceStatusTempId temperature0;
875898
@SerializedName("temperature:100")
@@ -1088,6 +1111,7 @@ public static class Shelly2RpcRequestParams {
10881111
public Integer toggleAfter;
10891112
public Integer white;
10901113
public Integer[] rgb;
1114+
public @Nullable String mode; // for RGBCCT mode switching: "rgb" or "cct"
10911115

10921116
// Shelly.SetAuth
10931117
public String user;

0 commit comments

Comments
 (0)