Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Change to using single master color channel.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Skinner <[email protected]>
  • Loading branch information
Skinah committed Sep 27, 2020
1 parent b86efa7 commit 20eba86
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 106 deletions.
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This openHAB binding allows you to auto discover and use LED strings from the WLED project found here:
<https://github.com/Aircoookie/WLED>

To watch what the binding does, enter this in to the openHAB console log:set TRACE org.openhab.binding.wled

## Supported Things

| Thing Type ID | Description |
Expand All @@ -11,31 +13,32 @@ This openHAB binding allows you to auto discover and use LED strings from the WL

## Discovery

The auto discovery will work with this binding if your network supports mDNS searches.
If it fails to work, you can manually add a WLED string by using the UI to manually add a `wled` thing.
The auto discovery will work with this binding if your network supports mDNS.
If it fails to find your WLED, you can manually add a `wled` thing by using the UI or textual methods.
The full example section gives everything needed to quickly setup using textual config.

## Thing Configuration

| Parameter | Description |
|-|-|
| `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. |
| `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. |

## Channels

| Channel | Type | Description |
|-|-|-|
| `masterBrightness` | Dimmer | Changes the global brightness of the LED string. |
| `masterControls` | Color | Gives you control over the WLED like it is a normal light. Tag this control for Alexa or Google/Nest to change the lights instantly to any color, brightness or on/off state that you ask for regardless of what mode the light is in. |
| `primaryColor` | Color | The primary color used in FX. |
| `secondaryColor` | Color | The secondary color used in FX. |
| `solidColor` | Color | Will change the primaryColor with any commands, the difference is that the FX is changed to SOLID first so you can use this tagged for Alexa or Google/Nest devices to change the lights instantly to any color you ask for. |
| `palettes` | String | A list of palettes you can select from. |
| `fx` | String | A list of Effects you can select from. |
| `speed` | Dimmer | Changes the speed of the loaded effect. |
| `intensity` | Dimmer | Changes the intensity of the loaded effect. |
| `presets` | String | A list of presets you can select from. |
| `presetDuration` | Dimmer | How long it takes to change from one preset to the next with `presetCycle` turned ON. |
| `presetCycle` | Switch | Turns on automatic changing from one preset to the next. |
| `presetDuration` | Dimmer | How long it takes to change from one preset to the next with `presetCycle` turned ON. |
| `transformTime` | Dimmer | How long it takes to transform/morph from one look to the next. |
| `sleep` | Switch | Turns on the sleep timer. |

## Full Example
Expand All @@ -49,19 +52,17 @@ Thing wled:wled:ChristmasTree "My Christmas Tree" @ "Lights" [address="http://19
*.items

```
Dimmer XmasTree_Master "Tree Brightness" {channel="wled:wled:ChristmasTree:masterBrightness"}
Color XmasTree_MasterControls "Christmas Tree" ["Lighting"] {channel="wled:wled:ChristmasTree:masterControls"}
Color XmasTree_Primary "Primary Color" {channel="wled:wled:ChristmasTree:primaryColor"}
Color XmasTree_Secondary "Secondary Color" {channel="wled:wled:ChristmasTree:secondaryColor"}
Color XmasTree_Solid "Christmas Tree" ["Lighting"] {channel="wled:wled:ChristmasTree:solidColor"}
String XmasTree_FX "FX" <text>{channel="wled:wled:ChristmasTree:fx"}
String XmasTree_Palette "Palette" <colorwheel> {channel="wled:wled:ChristmasTree:palettes"}
String XmasTree_Presets "Preset" <text> {channel="wled:wled:ChristmasTree:presets"}
Dimmer XmasTree_Speed "FX Speed" <time> {channel="wled:wled:ChristmasTree:speed"}
Dimmer XmasTree_Intensity "FX Intensity" {channel="wled:wled:ChristmasTree:intensity"}
Switch XmasTree_PresetCycle "presetCycle" <time> {channel="wled:wled:ChristmasTree:presetCycle"}
Dimmer XmasTree_PresetDuration "presetDuration" <time> {channel="wled:wled:ChristmasTree:presetDuration"}
Dimmer XmasTree_PresetTime "presetTransformTime" <time> {channel="wled:wled:ChristmasTree:presetTransformTime"}
Dimmer XmasTree_TransformTime "presetTransformTime" <time> {channel="wled:wled:ChristmasTree:transformTime"}
Switch XmasTree_Sleep "Sleep" <moon> {channel="wled:wled:ChristmasTree:sleep"}
```
Expand All @@ -70,20 +71,20 @@ Switch XmasTree_Sleep "Sleep" <moon> {channel="wled:wled:ChristmasTree:sl

```
Text label="XmasLights" icon="rgb"{
Switch item=XmasTree_Master
Slider item=XmasTree_Master
Switch item=XmasTree_MasterControls
Slider item=XmasTree_MasterControls
Colorpicker item=XmasTree_MasterControls
Switch item=XmasTree_Sleep
Colorpicker item=XmasTree_Primary
Colorpicker item=XmasTree_Secondary
Colorpicker item=XmasTree_Solid
Colorpicker item=XmasTree_Secondary
Selection item=XmasTree_FX
Selection item=XmasTree_Palette
Selection item=XmasTree_Presets
Default item=XmasTree_Speed
Default item=XmasTree_Intensity
Switch item=XmasTree_Sleep
Default item=XmasTree_Intensity
Default item=XmasTree_PresetCycle
Default item=XmasTree_PresetDuration
Default item=XmasTree_PresetTime
Default item=XmasTree_TransformTime
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ public class WLedBindingConstants {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = new HashSet<ThingTypeUID>(
Arrays.asList(THING_TYPE_WLED));

// config//
// Configs
public static final String CONFIG_ADDRESS = "address";
public static final String CONFIG_POLL_TIME = "pollTime";

// String channels
public static final String CHANNEL_MASTER_BRIGHTNESS = "masterBrightness";
// Channels
public static final String CHANNEL_MASTER_CONTROLS = "masterControls";
public static final String CHANNEL_PRIMARY_COLOR = "primaryColor";
public static final String CHANNEL_SECONDARY_COLOR = "secondaryColor";
public static final String CHANNEL_SOLID_COLOR = "solidColor";
public static final String CHANNEL_PALETTES = "palettes";
public static final String CHANNEL_PRESETS = "presets";
public static final String CHANNEL_PRESET_DURATION = "presetDuration";
public static final String CHANNEL_PRESET_TRANS_TIME = "presetTransformTime";
public static final String CHANNEL_TRANS_TIME = "transformTime";
public static final String CHANNEL_PRESET_CYCLE = "presetCycle";
public static final String CHANNEL_FX = "fx";
public static final String CHANNEL_SPEED = "speed";
Expand Down
80 changes: 44 additions & 36 deletions src/main/java/org/openhab/binding/wled/internal/WLedHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ private void processState(String message) {
updateStatus(ThingStatus.ONLINE);
}
if (message.contains("<ac>0</ac>")) {
updateState(CHANNEL_MASTER_BRIGHTNESS, OnOffType.OFF);
updateState(CHANNEL_MASTER_CONTROLS, OnOffType.OFF);
} else {
masterBrightness = new BigDecimal(getValue(message, "<ac>")).divide(new BigDecimal(2.55),
RoundingMode.HALF_UP);
updateState(CHANNEL_MASTER_BRIGHTNESS, new PercentType(masterBrightness));
updateState(CHANNEL_MASTER_CONTROLS, new PercentType(masterBrightness));
}
if (message.contains("<ix>0</ix>")) {
updateState(CHANNEL_INTENSITY, OnOffType.OFF);
Expand Down Expand Up @@ -193,68 +193,76 @@ private String createColorHex(HSBType hsb) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
switch (channelUID.getId()) {
case CHANNEL_PRIMARY_COLOR:
case CHANNEL_MASTER_CONTROLS:
sendGetRequest("/win");
}
return;
return;// no need to check for refresh below
}
logger.debug("command {} sent to {}", command, channelUID.getId());
switch (channelUID.getId()) {
case CHANNEL_MASTER_BRIGHTNESS:
case CHANNEL_MASTER_CONTROLS:
if (command instanceof OnOffType) {
if (OnOffType.OFF.equals(command)) {
sendGetRequest("/win&T=0");
sendGetRequest("/win&TT=500&T=0");
} else {
sendGetRequest("/win&T=1");
sendGetRequest("/win&TT=2000&T=1");
}
} else if (command instanceof IncreaseDecreaseType) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendGetRequest("/win&A=~10");
if (masterBrightness.intValue() < 240) {
sendGetRequest("/win&TT=2000&A=~15"); // 255 divided by 15 = 17 levels
} else {
sendGetRequest("/win&TT=2000&A=255");
}
} else {
sendGetRequest("/win&A=~-10");
if (masterBrightness.intValue() > 15) {
sendGetRequest("/win&TT=2000&A=~-15");
} else {
sendGetRequest("/win&TT=2000&A=0");
}
}
} else {
} else if (command instanceof HSBType) {
if ((((HSBType) command).getBrightness()) == PercentType.ZERO) {
sendGetRequest("/win&TT=500&T=0");
}
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);
} else {// should only be PercentType left
masterBrightness = new BigDecimal(command.toString()).multiply(new BigDecimal(2.55));
sendGetRequest("/win&A=" + masterBrightness);
sendGetRequest("/win&TT=2000&A=" + masterBrightness);
}
break;
case CHANNEL_SOLID_COLOR:
// gets passed onto primaryColor, after exit any FX, full brightness on master.
sendGetRequest("/win&FX=0&A=255&TT=1");
return;
case CHANNEL_PRIMARY_COLOR:
if (command instanceof OnOffType) {
logger.info("OnOffType commands not supported unless you use masterBrightness channel");
return;
logger.info("OnOffType commands should use masterControls channel");
} else if (command instanceof HSBType) {
primaryColor = new HSBType(command.toString());
sendGetRequest("/win&CL=" + createColorHex(primaryColor));
return;
} else if (command instanceof IncreaseDecreaseType) {
logger.info("IncreaseDecrease commands not supported unless you use the masterBrightness channel");
return;
logger.info("IncreaseDecrease commands should use masterControls channel");
} else {// Percentype
primaryColor = new HSBType(primaryColor.getHue().toString() + ","
+ primaryColor.getSaturation().toString() + ",command");
sendGetRequest("/win&CL=" + createColorHex(primaryColor));
}
// this is here for when the command is Percentype and not HSBtype//
primaryColor = new HSBType(
primaryColor.getHue().toString() + "," + primaryColor.getSaturation().toString() + ",command");
sendGetRequest("/win&CL=" + createColorHex(primaryColor));
break;
return;
case CHANNEL_SECONDARY_COLOR:
if (command instanceof OnOffType) {
logger.info("OnOffType commands not supported unless you use masterBrightness channel");
return;
logger.info("OnOffType commands should use masterControls channel");
} else if (command instanceof HSBType) {
secondaryColor = new HSBType(command.toString());
sendGetRequest("/win&C2=" + createColorHex(secondaryColor));
return;
} else if (command instanceof IncreaseDecreaseType) {
logger.info("IncreaseDecrease commands not supported unless you use the masterBrightness channel");
return;
logger.info("IncreaseDecrease commands should use masterControls channel");
} else {// Percentype
secondaryColor = new HSBType(secondaryColor.getHue().toString() + ","
+ secondaryColor.getSaturation().toString() + ",command");
sendGetRequest("/win&C2=" + createColorHex(secondaryColor));
}
// this is here for when the command is Percentype and not HSBtype//
secondaryColor = new HSBType(secondaryColor.getHue().toString() + ","
+ secondaryColor.getSaturation().toString() + ",command");
sendGetRequest("/win&C2=" + createColorHex(secondaryColor));
break;
return;
case CHANNEL_PALETTES:
sendGetRequest("/win&FP=" + command);
break;
Expand Down Expand Up @@ -303,7 +311,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
sendGetRequest("/win&PT=" + bigTemp);
break;
case CHANNEL_PRESET_TRANS_TIME:
case CHANNEL_TRANS_TIME:
if (OnOffType.OFF.equals(command)) {
bigTemp = new BigDecimal(0);
} else if (OnOffType.ON.equals(command)) {
Expand Down
51 changes: 28 additions & 23 deletions src/main/resources/ESH-INF/thing/thing-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
<description>A WLED string of LEDs</description>
<category>Lightbulb</category>
<channels>
<channel id="masterBrightness" typeId="masterBrightness"/>
<channel id="masterControls" typeId="masterControls"/>
<channel id="primaryColor" typeId="primaryColor"/>
<channel id="primaryWhite" typeId="primaryWhite"/>
<channel id="secondaryColor" typeId="secondaryColor"/>
<channel id="solidColor" typeId="solidColor"/>
<channel id="secondaryWhite" typeId="secondaryWhite"/>
<channel id="presets" typeId="presets"/>
<channel id="presetDuration" typeId="presetDuration"/>
<channel id="presetTransformTime" typeId="presetTransformTime"/>
<channel id="transformTime" typeId="transformTime"/>
<channel id="presetCycle" typeId="presetCycle"/>
<channel id="palettes" typeId="palettes"/>
<channel id="fx" typeId="fx"/>
Expand All @@ -37,11 +38,11 @@
</config-description>
</thing-type>

<channel-type id="masterBrightness">
<item-type>Dimmer</item-type>
<label>Master Brightness</label>
<description>Changes the brightness of all effects/presets.</description>
<category>DimmableLight</category>
<channel-type id="masterControls">
<item-type>Color</item-type>
<label>Master Controls</label>
<description>Allows you to exit FX mode and use the LEDS like a normal light.</description>
<category>ColorLight</category>
<tags>
<tag>Lighting</tag>
</tags>
Expand All @@ -50,28 +51,29 @@
<channel-type id="primaryColor">
<item-type>Color</item-type>
<label>Primary Color</label>
<description>Allows you to change the color of the globe.</description>
<description>Allows you to change the primary color used in FX.</description>
<category>ColorLight</category>
<tags>
<tag>Lighting</tag>
</tags>
</channel-type>

<channel-type id="primaryWhite">
<item-type>Dimmer</item-type>
<label>Primary White Brightness</label>
<description>Changes the brightness of the primary white LED.</description>
<category>DimmableLight</category>
</channel-type>

<channel-type id="secondaryColor">
<item-type>Color</item-type>
<label>Secondary Color</label>
<description>Allows you to change the color of the globe.</description>
<description>Allows you to change the secondary color used in FX.</description>
<category>ColorLight</category>
</channel-type>

<channel-type id="solidColor">
<item-type>Color</item-type>
<label>Solid Color</label>
<description>Allows you to exit any FX and set the LEDS to a single solid color.</description>
<category>ColorLight</category>
<tags>
<tag>Lighting</tag>
</tags>
<channel-type id="secondaryWhite">
<item-type>Dimmer</item-type>
<label>Secondary White Brightness</label>
<description>Changes the brightness of the white LED.</description>
<category>DimmableLight</category>
</channel-type>

<channel-type id="palettes">
Expand Down Expand Up @@ -286,12 +288,14 @@
<item-type>Dimmer</item-type>
<label>Preset Duration</label>
<description>Time before moving to the next preset.</description>
<category>Time</category>
</channel-type>

<channel-type id="presetTransformTime">
<channel-type id="transformTime">
<item-type>Dimmer</item-type>
<label>Preset Transform Time</label>
<description>Time it takes to change/fade from one preset to the next.</description>
<description>Time it takes to change/fade from one look to the next.</description>
<category>Time</category>
</channel-type>

<channel-type id="speed">
Expand All @@ -310,6 +314,7 @@
<item-type>Switch</item-type>
<label>sleep</label>
<description>Sleep mode: Lower the level of light and turn off after set time.</description>
<category>Time</category>
</channel-type>

<channel-type id="presetCycle">
Expand Down
Loading

0 comments on commit 20eba86

Please sign in to comment.