diff --git a/README.md b/README.md index 30a3388..d4b06d3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -# WLed Binding +# WLED Binding This openHAB binding allows you to auto discover and use LED strings from the WLED project found here: -To watch what the binding does, enter this in to the openHAB console log:set TRACE org.openhab.binding.wled +## Fault Finding + +To watch what the binding does you can enter this in to the openHAB console, `log:set TRACE org.openhab.binding.wled` which will allow you to test the same commands in a web browser to determine if it is a bug in the binding, or in the firmware for WLED. ## Supported Things @@ -23,6 +25,7 @@ The full example section gives everything needed to quickly setup using textual |-|-| | `address`| The URL to your WLED device. Example is `http://192.168.0.2:80` | | `pollTime`| How often you want the states of the LED fetched in case you make changes with a non openHAB app or web browser or the light is auto changing FX. | +| `saturationThreshold` | Allows you to use a colorpicker linked to the masterControls channel to trigger the pure white LEDs when your using RGBW strings. Try setting the value to 12 or for RGB strings leave this on 0. TIP: set to 33 if you want Google devices to select the real white LEDS when you ask for white. | ## Channels diff --git a/src/main/java/org/openhab/binding/wled/internal/WLedActions.java b/src/main/java/org/openhab/binding/wled/internal/WLedActions.java new file mode 100644 index 0000000..b4f4bdb --- /dev/null +++ b/src/main/java/org/openhab/binding/wled/internal/WLedActions.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wled.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.thing.binding.ThingActions; +import org.eclipse.smarthome.core.thing.binding.ThingActionsScope; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.openhab.core.automation.annotation.ActionInput; +import org.openhab.core.automation.annotation.RuleAction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link WLedActions} is responsible for Actions. + * + * @author Matthew Skinner - Initial contribution + */ + +@ThingActionsScope(name = "wled") +@NonNullByDefault +public class WLedActions implements ThingActions { + public final Logger logger = LoggerFactory.getLogger(getClass()); + private @Nullable WLedHandler handler; + + @Override + public void setThingHandler(@Nullable ThingHandler handler) { + this.handler = (WLedHandler) handler; + } + + @Override + public @Nullable ThingHandler getThingHandler() { + return handler; + } + + @RuleAction(label = "Save Preset", description = "Save a WLED state to a preset location") + public void savePreset( + @ActionInput(name = "presetNumber", label = "Save Preset Number", description = "Enter the number of the preset you wish to save") int presetNumber) { + if (presetNumber > 0 && handler != null) { + handler.savePreset(presetNumber); + } + } + + public static void savePreset(@Nullable ThingActions actions, int presetNumber) { + if (actions instanceof WLedActions) { + ((WLedActions) actions).savePreset(presetNumber); + } else { + throw new IllegalArgumentException("Instance is not a WLED class."); + } + } +} diff --git a/src/main/java/org/openhab/binding/wled/internal/WLedBindingConstants.java b/src/main/java/org/openhab/binding/wled/internal/WLedBindingConstants.java index fefe571..d4b5764 100644 --- a/src/main/java/org/openhab/binding/wled/internal/WLedBindingConstants.java +++ b/src/main/java/org/openhab/binding/wled/internal/WLedBindingConstants.java @@ -39,6 +39,7 @@ public class WLedBindingConstants { // Configs public static final String CONFIG_ADDRESS = "address"; public static final String CONFIG_POLL_TIME = "pollTime"; + public static final String CONFIG_SAT_THRESHOLD = "saturationThreshold"; // Channels public static final String CHANNEL_MASTER_CONTROLS = "masterControls"; diff --git a/src/main/java/org/openhab/binding/wled/internal/WLedConfiguration.java b/src/main/java/org/openhab/binding/wled/internal/WLedConfiguration.java index 7d31055..413e3c0 100644 --- a/src/main/java/org/openhab/binding/wled/internal/WLedConfiguration.java +++ b/src/main/java/org/openhab/binding/wled/internal/WLedConfiguration.java @@ -23,4 +23,5 @@ public class WLedConfiguration { public String address = ""; public int pollTime; + public int saturationThreshold; } diff --git a/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java b/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java index 9eb646a..7292e0e 100644 --- a/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java +++ b/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java @@ -17,6 +17,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; @@ -42,6 +44,7 @@ import org.eclipse.smarthome.core.thing.ThingStatus; import org.eclipse.smarthome.core.thing.ThingStatusDetail; import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerService; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.RefreshType; import org.eclipse.smarthome.core.types.StateOption; @@ -277,8 +280,12 @@ public void handleCommand(ChannelUID channelUID, Command command) { masterBrightness = new BigDecimal((((HSBType) command).getBrightness()).toString()) .multiply(new BigDecimal(2.55)); primaryColor = new HSBType(command.toString()); - sendGetRequest( - "/win&TT=1000&FX=0&CY=0&CL=" + createColorHex(primaryColor) + "&A=" + masterBrightness); + if (primaryColor.getSaturation().intValue() < config.saturationThreshold) { + sendGetRequest("/win&TT=1000&FX=0&CY=0&CL=h000000&W=255" + "&A=" + masterBrightness); + } else { + sendGetRequest( + "/win&TT=1000&FX=0&CY=0&CL=" + createColorHex(primaryColor) + "&A=" + masterBrightness); + } } else {// should only be PercentType left masterBrightness = new BigDecimal(command.toString()).multiply(new BigDecimal(2.55)); sendGetRequest("/win&TT=2000&A=" + masterBrightness); @@ -386,6 +393,10 @@ public void handleCommand(ChannelUID channelUID, Command command) { * */ public void savePreset(int presetIndex) { + if (presetIndex > 16) { + logger.warn("Presets above 16 do not exist, and the action sent {}", presetIndex); + return; + } sendGetRequest("/win&PS=" + presetIndex); } @@ -406,6 +417,11 @@ public void dispose() { } } + @Override + public Collection> getServices() { + return Collections.singleton(WLedActions.class); + } + /** * @return A string that starts after finding the element and terminates when it finds the first occurence of the * end char after the element. diff --git a/src/main/resources/ESH-INF/binding/binding.xml b/src/main/resources/ESH-INF/binding/binding.xml index 0734436..f122604 100644 --- a/src/main/resources/ESH-INF/binding/binding.xml +++ b/src/main/resources/ESH-INF/binding/binding.xml @@ -3,8 +3,8 @@ xmlns:binding="https://openhab.org/schemas/binding/v1.0.0" xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> - WLed Binding - This is the binding for WLed. + WLED Binding + This is the binding for WLED Matthew Skinner diff --git a/src/main/resources/ESH-INF/thing/thing-types.xml b/src/main/resources/ESH-INF/thing/thing-types.xml index 83fff27..26e7166 100644 --- a/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/src/main/resources/ESH-INF/thing/thing-types.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - + A WLED string of LEDs Lightbulb @@ -35,6 +35,12 @@ Time in seconds of how often to fetch the state of the LEDs. 10 + + +This feature allows you to specify a number that if the saturation drops below, will trigger white. + +0 + diff --git a/target/classes/ESH-INF/binding/binding.xml b/target/classes/ESH-INF/binding/binding.xml index 0734436..f122604 100644 --- a/target/classes/ESH-INF/binding/binding.xml +++ b/target/classes/ESH-INF/binding/binding.xml @@ -3,8 +3,8 @@ xmlns:binding="https://openhab.org/schemas/binding/v1.0.0" xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> - WLed Binding - This is the binding for WLed. + WLED Binding + This is the binding for WLED Matthew Skinner diff --git a/target/classes/ESH-INF/thing/thing-types.xml b/target/classes/ESH-INF/thing/thing-types.xml index 83fff27..26e7166 100644 --- a/target/classes/ESH-INF/thing/thing-types.xml +++ b/target/classes/ESH-INF/thing/thing-types.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - + A WLED string of LEDs Lightbulb @@ -35,6 +35,12 @@ Time in seconds of how often to fetch the state of the LEDs. 10 + + +This feature allows you to specify a number that if the saturation drops below, will trigger white. + +0 + diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF index e5864c0..dbd352c 100644 --- a/target/classes/META-INF/MANIFEST.MF +++ b/target/classes/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.openhab.binding.wled -Bnd-LastModified: 1601294873574 +Bnd-LastModified: 1601535602378 Bundle-Description: This project contains the official add-ons of open HAB Bundle-Developers: openhab;email="info@openhab.org";name=openHAB;organ @@ -20,16 +20,17 @@ Bundle-SCM: url="https://github.com/openhab/openhab-addons/org.openhab tor.bundles/org.openhab.binding.wled",tag=HEAD Bundle-SymbolicName: org.openhab.binding.wled Bundle-Vendor: openHAB.org -Bundle-Version: 2.5.9.202009281207 +Bundle-Version: 2.5.9.202010010700 Created-By: 1.8.0_231 (Oracle Corporation) -Import-Package: org.eclipse.smarthome.config.discovery,org.eclipse.sma - rthome.config.discovery.mdns,org.eclipse.smarthome.core.library.types - ,org.eclipse.smarthome.core.thing,org.eclipse.smarthome.core.thing.bi - nding,org.eclipse.smarthome.core.thing.i18n,org.eclipse.smarthome.cor - e.thing.type,org.eclipse.smarthome.core.types,org.eclipse.smarthome.i - o.net.http,javax.jmdns;version="[3.5,4)",org.eclipse.jetty.client;ver - sion="[9.3,10)",org.eclipse.jetty.client.api;version="[9.3,10)",org.e - clipse.jetty.http;version="[9.3,10)",org.slf4j;version="[1.7,2)" +Import-Package: org.openhab.core.automation.annotation;resolution:=opt + ional,org.eclipse.smarthome.config.discovery,org.eclipse.smarthome.co + nfig.discovery.mdns,org.eclipse.smarthome.core.library.types,org.ecli + pse.smarthome.core.thing,org.eclipse.smarthome.core.thing.binding,org + .eclipse.smarthome.core.thing.i18n,org.eclipse.smarthome.core.thing.t + ype,org.eclipse.smarthome.core.types,org.eclipse.smarthome.io.net.htt + p,javax.jmdns;version="[3.5,4)",org.eclipse.jetty.client;version="[9. + 3,10)",org.eclipse.jetty.client.api;version="[9.3,10)",org.eclipse.je + tty.http;version="[9.3,10)",org.slf4j;version="[1.7,2)" Private-Package: ESH-INF.binding,ESH-INF.thing,org.openhab.binding.wle d.internal Provide-Capability: osgi.service;objectClass:List="org.eclipse diff --git a/target/classes/org/openhab/binding/wled/internal/WLedBindingConstants.class b/target/classes/org/openhab/binding/wled/internal/WLedBindingConstants.class index ea707d9..cac6bbd 100644 Binary files a/target/classes/org/openhab/binding/wled/internal/WLedBindingConstants.class and b/target/classes/org/openhab/binding/wled/internal/WLedBindingConstants.class differ diff --git a/target/classes/org/openhab/binding/wled/internal/WLedConfiguration.class b/target/classes/org/openhab/binding/wled/internal/WLedConfiguration.class index a238196..d4a0b58 100644 Binary files a/target/classes/org/openhab/binding/wled/internal/WLedConfiguration.class and b/target/classes/org/openhab/binding/wled/internal/WLedConfiguration.class differ diff --git a/target/classes/org/openhab/binding/wled/internal/WLedHandler.class b/target/classes/org/openhab/binding/wled/internal/WLedHandler.class index 9cf2119..f5ded04 100644 Binary files a/target/classes/org/openhab/binding/wled/internal/WLedHandler.class and b/target/classes/org/openhab/binding/wled/internal/WLedHandler.class differ