diff --git a/bundles/org.openhab.binding.deconz/README.md b/bundles/org.openhab.binding.deconz/README.md index ef762dfa51ec..22ef7af1e7fd 100644 --- a/bundles/org.openhab.binding.deconz/README.md +++ b/bundles/org.openhab.binding.deconz/README.md @@ -89,7 +89,7 @@ The transition time is the time to move between two states and is configured in The resolution provided is 1/10s. If no value is provided, the default value of the device is used. -`extendedcolorlight` and `colorlight` have different modes for setting the color. +`extendedcolorlight`, `colorlight` and `lightgroup` have different modes for setting the color. Some devices accept only XY, others HSB, others both modes and the binding tries to autodetect the correct mode. If this fails, the advanced `colormode` parameter can be set to `xy` or `hs`. diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/GroupAction.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/GroupAction.java index 87fa4a10dcff..3044ec7d8252 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/GroupAction.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/GroupAction.java @@ -33,14 +33,16 @@ public class GroupAction { public @Nullable Integer ct; public double @Nullable [] xy; public @Nullable String alert; + public @Nullable String colormode; public @Nullable String effect; public @Nullable Integer colorloopspeed; public @Nullable Integer transitiontime; @Override public String toString() { - return "GroupAction{" + "on=" + on + ", toggle=" + toggle + ", bri=" + bri + ", hue=" + hue + ", sat=" + sat - + ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", alert='" + alert + '\'' + ", effect='" + effect - + '\'' + ", colorloopspeed=" + colorloopspeed + ", transitiontime=" + transitiontime + '}'; + return "GroupAction{on=" + on + ", toggle=" + toggle + ", bri=" + bri + ", hue=" + hue + ", sat=" + sat + + ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", alert='" + alert + "', colormode='" + colormode + + "', effect='" + effect + "', colorloopspeed=" + colorloopspeed + ", transitiontime=" + transitiontime + + "}"; } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java index 7a30eb98d04a..d1642cfb967c 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java @@ -59,6 +59,7 @@ public class GroupThingHandler extends DeconzBaseThingHandler { private Map scenes = Map.of(); private GroupState groupStateCache = new GroupState(); + private String colorMode = ""; public GroupThingHandler(Thing thing, Gson gson, DeconzDynamicCommandDescriptionProvider commandDescriptionProvider) { @@ -66,6 +67,14 @@ public GroupThingHandler(Thing thing, Gson gson, this.commandDescriptionProvider = commandDescriptionProvider; } + @Override + public void initialize() { + ThingConfig thingConfig = getConfigAs(ThingConfig.class); + colorMode = thingConfig.colormode; + + super.initialize(); + } + @Override public void handleCommand(ChannelUID channelUID, Command command) { String channelId = channelUID.getId(); @@ -89,11 +98,17 @@ public void handleCommand(ChannelUID channelUID, Command command) { case CHANNEL_COLOR: if (command instanceof HSBType) { HSBType hsbCommand = (HSBType) command; - Integer bri = Util.fromPercentType(hsbCommand.getBrightness()); - newGroupAction.bri = bri; - if (bri > 0) { + // XY color is the implicit default: Use XY color mode if i) no color mode is set or ii) if the bulb + // is in CT mode or iii) already in XY mode. Only if the bulb is in HS mode, use this one. + if ("hs".equals(colorMode)) { newGroupAction.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR); newGroupAction.sat = Util.fromPercentType(hsbCommand.getSaturation()); + } else { + PercentType[] xy = hsbCommand.toXY(); + if (xy.length < 2) { + logger.warn("Failed to convert {} to xy-values", command); + } + newGroupAction.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 }; } } else if (command instanceof PercentType) { newGroupAction.bri = Util.fromPercentType((PercentType) command); @@ -172,6 +187,16 @@ public void messageReceived(String sensorID, DeconzBaseMessage message) { thing.getChannels().stream().map(c -> c.getUID().getId()).forEach(c -> valueUpdated(c, groupState)); groupStateCache = groupState; } + GroupAction groupAction = groupMessage.action; + if (groupAction != null) { + if (colorMode.isEmpty()) { + String cmode = groupAction.colormode; + if (cmode != null && ("hs".equals(cmode) || "xy".equals(cmode))) { + // only set the color mode if it is hs or xy, not ct + colorMode = cmode; + } + } + } } } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java index 4a6a81328b48..3a5594629b57 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java @@ -210,19 +210,19 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } else if (command instanceof HSBType) { HSBType hsbCommand = (HSBType) command; - if ("xy".equals(colorMode)) { + // XY color is the implicit default: Use XY color mode if i) no color mode is set or ii) if the bulb + // is in CT mode or iii) already in XY mode. Only if the bulb is in HS mode, use this one. + if ("hs".equals(colorMode)) { + newLightState.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR); + newLightState.sat = Util.fromPercentType(hsbCommand.getSaturation()); + } else { PercentType[] xy = hsbCommand.toXY(); if (xy.length < 2) { logger.warn("Failed to convert {} to xy-values", command); } newLightState.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 }; - newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness()); - } else { - // default is colormode "hs" (used when colormode "hs" is set or colormode is unknown) - newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness()); - newLightState.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR); - newLightState.sat = Util.fromPercentType(hsbCommand.getSaturation()); } + newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness()); } else if (command instanceof PercentType) { newLightState.bri = Util.fromPercentType((PercentType) command); } else if (command instanceof DecimalType) { diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/ThingConfig.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/ThingConfig.java index 9d26ba31dc55..a3c69e82a700 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/ThingConfig.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/ThingConfig.java @@ -23,7 +23,7 @@ @NonNullByDefault public class ThingConfig { public String id = ""; - public int lastSeenPolling = 1440; public @Nullable Double transitiontime; public String colormode = ""; + public int lastSeenPolling = 1440; } diff --git a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/config/config.xml index dc7cc0665510..bd0b4fab2fc7 100644 --- a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/config/config.xml @@ -10,23 +10,23 @@ network-address IP address or host name of deCONZ interface. - + Port of the deCONZ HTTP interface. 80 - + Port of the deCONZ Websocket. true - + password If no API Key is provided, a new one will be requested. You need to authorize the access on the deCONZ web interface. - + Timeout for asynchronous HTTP requests (in milliseconds). true @@ -52,7 +52,7 @@ The deCONZ bridge assigns an integer number ID to each device. - + Time to move between two states. If empty, the default of the device is used. Resolution is 1/10 second. @@ -63,11 +63,11 @@ The deCONZ bridge assigns an integer number ID to each device. - + Time to move between two states. If empty, the default of the device is used. Resolution is 1/10 second. - + Override the default color mode (auto-detect) @@ -78,4 +78,19 @@ + + + + The deCONZ bridge assigns an integer number ID to each group. + + + + Override the default color mode (auto-detect) + + + + + true + + diff --git a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml index dda79246633f..7a0fb8266e98 100644 --- a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml +++ b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml @@ -21,7 +21,7 @@ uid - +