From 4176b996a5dde810485eb93fee54605b89aaaafa Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Sun, 25 Jul 2021 20:43:28 +1000 Subject: [PATCH] [espmilight] Add color channels ability to trigger white LEDs (#11047) * Add white shortcut for sat threshold Signed-off-by: Matthew Skinner * Fix compiler warnings. Signed-off-by: Matthew Skinner --- .../README.md | 2 +- .../EspMilightHubDiscoveryService.java | 2 +- .../handler/EspMilightHubHandler.java | 28 +++++++++---------- .../main/resources/OH-INF/config/config.xml | 12 +++++++- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt.espmilighthub/README.md b/bundles/org.openhab.binding.mqtt.espmilighthub/README.md index 5a1b10c8daa67..f2171d7fcb962 100644 --- a/bundles/org.openhab.binding.mqtt.espmilighthub/README.md +++ b/bundles/org.openhab.binding.mqtt.espmilighthub/README.md @@ -105,7 +105,7 @@ Note that the group 0 (or ALL group) is not autodiscovered as a thing and thus h | `dimmedCT` | Traditional globes grow warmer the more they are dimmed. Set this to 370, or leave blank to disable. | N | blank | | `oneTriggersNightMode` | Night mode is a much lower level of light and this feature allows it to be auto selected when your fader/slider moves to 1%. NOTE: Night mode by design locks out some controls of a physical remote, so this feature is disabled by default. | Y | false | | `powerFailsToMinimum` | If lights loose power from the power switch OR a power outage, they will default to using the lowest brightness if the light was turned off before the power failure occurred. | Y | true | -| `whiteThreshold` | RGBW globes do not respond to saturation changes, so this feature allows you to specify a number that if the saturation drops below, it will trigger the white mode. -1 will disable this feature. | Y | 12 | +| `whiteThreshold` | This feature allows you to use a color control to change to using the real white LEDs when the saturation is equal to, or below this threshold. -1 will disable this feature. | Y | 12 | ## Channels diff --git a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/discovery/EspMilightHubDiscoveryService.java b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/discovery/EspMilightHubDiscoveryService.java index b855ef4c37d3c..51edb7ec5b58f 100644 --- a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/discovery/EspMilightHubDiscoveryService.java +++ b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/discovery/EspMilightHubDiscoveryService.java @@ -70,7 +70,7 @@ public void receivedMessage(ThingUID connectionBridge, MqttBrokerConnection conn String globeType = (cutTopic.substring(0, index)); String remoteGroupID = (cutTopic.substring(index + 1, index + 2)); // openHAB's framework has better code for handling groups then the firmware does - if (!remoteGroupID.equals("0")) {// Users can manually add group 0 things if they wish + if (!"0".equals(remoteGroupID)) {// Users can manually add group 0 things if they wish publishDevice(connectionBridge, connection, topic, remoteCode, globeType, remoteGroupID); } } diff --git a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/handler/EspMilightHubHandler.java b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/handler/EspMilightHubHandler.java index c2566c264cc9a..e45475164a6c5 100644 --- a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/handler/EspMilightHubHandler.java +++ b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/java/org/openhab/binding/mqtt/espmilighthub/internal/handler/EspMilightHubHandler.java @@ -78,7 +78,7 @@ public EspMilightHubHandler(Thing thing, ThingRegistry thingRegistry) { void changeChannel(String channel, State state) { updateState(new ChannelUID(channelPrefix + channel), state); // Remote code of 0 means that all channels need to follow this change. - if (remotesGroupID.equals("0")) { + if ("0".equals(remotesGroupID)) { switch (globeType) { // These two are 8 channel remotes case "fut091": @@ -110,20 +110,20 @@ private void processIncomingState(String messageJSON) { String bulbState = Helper.resolveJSON(messageJSON, "\"state\":\"", 3); String bulbLevel = Helper.resolveJSON(messageJSON, "\"level\":", 3); if (!bulbLevel.isEmpty()) { - if (bulbLevel.equals("0") || bulbState.equals("OFF")) { + if ("0".equals(bulbLevel) || "OFF".equals(bulbState)) { changeChannel(CHANNEL_LEVEL, OnOffType.OFF); tempBulbLevel = BigDecimal.ZERO; } else { tempBulbLevel = new BigDecimal(bulbLevel); changeChannel(CHANNEL_LEVEL, new PercentType(tempBulbLevel)); } - } else if (bulbState.equals("ON") || bulbState.equals("OFF")) { // NOTE: Level is missing when this runs + } else if ("ON".equals(bulbState) || "OFF".equals(bulbState)) { // NOTE: Level is missing when this runs changeChannel(CHANNEL_LEVEL, OnOffType.valueOf(bulbState)); } bulbMode = Helper.resolveJSON(messageJSON, "\"bulb_mode\":\"", 5); switch (bulbMode) { case "white": - if (!globeType.equals("cct") && !globeType.equals("fut091")) { + if (!"cct".equals(globeType) && !"fut091".equals(globeType)) { changeChannel(CHANNEL_BULB_MODE, new StringType("white")); changeChannel(CHANNEL_COLOUR, new HSBType("0,0," + tempBulbLevel)); changeChannel(CHANNEL_DISCO_MODE, new StringType("None")); @@ -149,7 +149,7 @@ private void processIncomingState(String messageJSON) { } break; case "scene": - if (!globeType.equals("cct") && !globeType.equals("fut091")) { + if (!"cct".equals(globeType) && !"fut091".equals(globeType)) { changeChannel(CHANNEL_BULB_MODE, new StringType("scene")); } String bulbDiscoMode = Helper.resolveJSON(messageJSON, "\"mode\":", 1); @@ -158,7 +158,7 @@ private void processIncomingState(String messageJSON) { } break; case "night": - if (!globeType.equals("cct") && !globeType.equals("fut091")) { + if (!"cct".equals(globeType) && !"fut091".equals(globeType)) { changeChannel(CHANNEL_BULB_MODE, new StringType("night")); if (config.oneTriggersNightMode) { changeChannel(CHANNEL_LEVEL, new PercentType("1")); @@ -219,13 +219,13 @@ void handleLevelColour(Command command) { } else if (PercentType.ZERO.equals(hsb.getBrightness())) { turnOff(); return; - } else if (config.whiteThreshold != -1 && hsb.getSaturation().intValue() <= config.whiteThreshold - && "rgbw".equals(globeType)) { - sendMQTT("{\"command\":\"set_white\"}"); - return; + } else if (config.whiteThreshold != -1 && hsb.getSaturation().intValue() <= config.whiteThreshold) { + sendMQTT("{\"command\":\"set_white\"}");// Can't send the command and level in the same message. + sendMQTT("{\"level\":" + hsb.getBrightness().intValue() + "}"); + } else { + sendMQTT("{\"state\":\"ON\",\"level\":" + hsb.getBrightness().intValue() + ",\"hue\":" + + hsb.getHue().intValue() + ",\"saturation\":" + hsb.getSaturation().intValue() + "}"); } - sendMQTT("{\"state\":\"ON\",\"level\":" + hsb.getBrightness().intValue() + ",\"hue\":" - + hsb.getHue().intValue() + ",\"saturation\":" + hsb.getSaturation().intValue() + "}"); savedLevel = hsb.getBrightness().toBigDecimal(); return; } else if (command instanceof PercentType) { @@ -239,8 +239,8 @@ void handleLevelColour(Command command) { } sendMQTT("{\"state\":\"ON\",\"level\":" + command + "}"); savedLevel = percentType.toBigDecimal(); - if (globeType.equals("rgb_cct") || globeType.equals("fut089")) { - if (config.dimmedCT > 0 && bulbMode.equals("white")) { + if ("rgb_cct".equals(globeType) || "fut089".equals(globeType)) { + if (config.dimmedCT > 0 && "white".equals(bulbMode)) { sendMQTT("{\"state\":\"ON\",\"color_temp\":" + autoColourTemp(savedLevel.intValue()) + "}"); } } diff --git a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/resources/OH-INF/config/config.xml index 69be374fb168b..f6cf7d88e04ed 100644 --- a/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.mqtt.espmilighthub/src/main/resources/OH-INF/config/config.xml @@ -47,6 +47,15 @@ 32 + + + Saturation values at or below this value on a RGBW color control will trigger the white mode. -1 will + disable + this feature. + + 6 + + When a shortcut triggers white mode, use this for the colour white. @@ -101,7 +110,8 @@ - RGBW saturation changes, will trigger the white mode. -1 will disable this feature. + Saturation values at or below this value on a RGBW color control will trigger the white mode. -1 will + disable this feature. 12