Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wled] Abstract json api for better segment support #11509

Merged
merged 16 commits into from
Nov 20, 2021
34 changes: 20 additions & 14 deletions bundles/org.openhab.binding.wled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,47 @@ For additional segments, you can add them manually and set the `segmentIndex` co
|-|-|-|-|
| `address`| The full URL to your WLED device. Example is `http://192.168.0.2:80` | Y | |
| `pollTime`| How often in seconds you want the states of the LED fetched in case you make changes with a non openHAB app, web browser, or the light is auto changing FX or presets. | Y | 10 |
| `segmentIndex` | The index number to the LED segment you wish these channels to control. Leave on -1 if you do not know what a segment is. | Y | -1 |
| `segmentIndex` | The index number to the LED segment you wish these channels to control. Leave on 0 if you do not know what a segment is. | Y | 0 |
| `saturationThreshold` | Allows you to use a colorpicker control linked to the `masterControls` channel to trigger only using the pure white LEDs instead of creating fake white light from the RGB channels. Try setting the value to 12 or leave this on 0 for RGB strings. | Y | 0 |

## Channels

| Channel | Type | Description |
|-|-|-|
| `masterControls` | Color | Gives you control over the WLED like it is any normal light. Tag this control for Alexa or Google/Nest to change the lights instantly to any colour, brightness or on/off state that you ask for regardless of what mode the light is in. |
| `masterControls` | Color | Gives you control over the WLED segment like it is any normal light. Tag this control for Alexa or Google/Nest to change the lights instantly to any colour, brightness or on/off state that you ask for regardless of what mode the light is in. |
| `segmentBrightness` | Dimmer | Allows you to Dim and turn the entire segment ON and OFF. |
| `primaryColor` | Color | The primary colour used in FX. |
| `primaryWhite` | Dimmer | The amount of white light used in the primary colour if you have RGBW LEDs. |
| `primaryWhite` | Dimmer | The amount of white light used in the primary colour. Only available if you have RGBW LEDs. |
| `secondaryColor` | Color | The secondary colour used in FX. |
| `secondaryWhite` | Dimmer | The amount of white light used in the secondary colour if you have RGBW LEDs. |
| `secondaryWhite` | Dimmer | The amount of white light used in the second colour. Only available if you have RGBW LEDs. |
| `tertiaryColor` | Color | The third colour used in FX. |
| `tertiaryWhite` | Dimmer | The amount of white light used in the third colour. Only available if you have RGBW LEDs. |
| `palettes` | String | A list of colour palettes you can select from that are used in the FX. |
| `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 that you can select from. |
| `presetCycle` | Switch | Turns ON/OFF the automatic changing from one preset to the next. |
| `presetDuration` | Number:Time | How long in seconds it will display a preset for, before it begins to change from one preset to the next with `presetCycle` turned ON. |
| `presets` | String | A list of presets that you can select from and will display -1 when no presets are running. |
| `playlists` | String | A list of playlists that you can select from and will display -1 when none are running. |
| `presetCycle` | Switch | Turns ON/OFF the automatic changing from one preset to the next. Only in V0.12.0 and older firmwares. |
| `presetDuration` | Number:Time | How long in seconds it will display a preset for, before it begins to change from one preset to the next with `presetCycle` turned ON. Only in V0.12.0 and older firmwares. |
| `transformTime` | Number:Time | How long in seconds it takes to transform/morph from one look to the next. |
| `sleep` | Switch | Turns on the sleep or 'night light' timer which can be configured to work in many different ways. Refer to WLED documentation for how this can be setup. The default action is the light will fade to OFF over the next 60 minutes. |
| `syncSend` | Switch | Sends UDP packets that tell other WLED lights to follow this one. |
| `syncReceive` | Switch | Allows UDP packets from other WLED lights to control this one. |
| `mirror` | Switch | Mirror the effect for this segment. |
| `reverse` | Switch | Reverse the effect for this segment. |
| `liveOverride` | String | A value of "0" turns off, "1" will override live data to display what you want, and "2" overrides until you reboot the ESP device. |
| `grouping` | Number | The number of LEDs that are grouped together to display as one pixel in FX. Use metadata to display a list widget slider. |
| `spacing` | Number | The number of LEDs that will not light up in between FX pixels. Use metadata to display a list widget slider. |

## Rule Actions

This binding has a rule Action `savePreset(int presetNumber)` which can save the current state of the WLED string into a preset slot that you can specify.
Currently 1 to 16 are valid preset slots.
This binding has two rule Actions `savePreset(int presetNumber)` and `savePreset(int presetNumber, String presetName)` which can save the current state of the WLED string into a preset slot that you can specify.

In Xtend rules, you can use the Actions like this.

```
getActions("wled", "wled:wled:XmasTree").savePreset(5)
getActions("wled", "wled:wled:XmasTree").savePreset(5,"Flashy Preset")
```

## Sitemap Example
Expand All @@ -68,7 +76,7 @@ If you use the ADMIN>MODEL>`Create equipment from thing` feature you can use the
```
Text label="XmasLights" icon="rgb"{
Switch item=XmasTree_MasterControls
Slider item=XmasTree_MasterControls
Slider item=XmasTree_SegmentBrightness
Colorpicker item=XmasTree_MasterControls
Switch item=XmasTree_SleepTimer
Colorpicker item=XmasTree_PrimaryColor
Expand All @@ -77,9 +85,7 @@ If you use the ADMIN>MODEL>`Create equipment from thing` feature you can use the
Selection item=XmasTree_Palettes
Selection item=XmasTree_Presets
Default item=XmasTree_FXSpeed
Default item=XmasTree_FXIntensity
Default item=XmasTree_PresetCycle
Selection item=XmasTree_PresetDuration mappings=[2 ='2 seconds', 10='10 seconds', 30='30 seconds', 60='60 seconds']
Default item=XmasTree_FXIntensity
Selection item=XmasTree_TransformTime mappings=[0='0 seconds', 2 ='2 seconds', 10='10 seconds', 30='30 seconds', 60='60 seconds']
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,30 @@ public void setThingHandler(@Nullable ThingHandler handler) {
@RuleAction(label = "save state to preset", description = "Save a WLED state to a preset slot")
public void savePreset(
@ActionInput(name = "presetNumber", label = "Preset Slot", description = "Number for the preset slot you wish to use") int presetNumber) {
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.");
}
}

@RuleAction(label = "save state to preset", description = "Save a WLED state to a preset slot")
public void savePreset(
@ActionInput(name = "presetNumber", label = "Preset Slot", description = "Number for the preset slot you wish to use") int presetNumber,
@ActionInput(name = "presetName", label = "Preset Name", description = "Name for the preset that you wish to use") String presetName) {
WLedHandler localHandler = handler;
if (presetNumber > 0 && localHandler != null) {
localHandler.savePreset(presetNumber);
if (localHandler != null) {
localHandler.savePreset(presetNumber, presetName);
}
}

public static void savePreset(@Nullable ThingActions actions, int presetNumber) {
public static void savePreset(@Nullable ThingActions actions, int presetNumber, String presetName) {
if (actions instanceof WLedActions) {
((WLedActions) actions).savePreset(presetNumber);
((WLedActions) actions).savePreset(presetNumber, presetName);
} else {
throw new IllegalArgumentException("Instance is not a WLED class.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,27 @@ public class WLedBindingConstants {

// Channels
public static final String CHANNEL_MASTER_CONTROLS = "masterControls";
public static final String CHANNEL_SEGMENT_BRIGHTNESS = "segmentBrightness";
public static final String CHANNEL_PRIMARY_COLOR = "primaryColor";
public static final String CHANNEL_SECONDARY_COLOR = "secondaryColor";
public static final String CHANNEL_THIRD_COLOR = "tertiaryColor";
public static final String CHANNEL_PRIMARY_WHITE = "primaryWhite";
public static final String CHANNEL_SECONDARY_WHITE = "secondaryWhite";
public static final String CHANNEL_THIRD_WHITE = "tertiaryWhite";
public static final String CHANNEL_PALETTES = "palettes";
public static final String CHANNEL_PRESETS = "presets";
public static final String CHANNEL_PLAYLISTS = "playlists";
public static final String CHANNEL_PRESET_DURATION = "presetDuration";
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";
public static final String CHANNEL_INTENSITY = "intensity";
public static final String CHANNEL_MIRROR = "mirror";
public static final String CHANNEL_REVERSE = "reverse";
public static final String CHANNEL_GROUPING = "grouping";
public static final String CHANNEL_SPACING = "spacing";
public static final String CHANNEL_LIVE_OVERRIDE = "liveOverride";
public static final String CHANNEL_SLEEP = "sleep";
public static final String CHANNEL_SYNC_SEND = "syncSend";
public static final String CHANNEL_SYNC_RECEIVE = "syncReceive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private String sendGetRequest(String address, String url) {
properties.put(Thing.PROPERTY_MAC_ADDRESS, macAddress);
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, firmware);
return DiscoveryResultBuilder.create(thingUID).withProperty(CONFIG_ADDRESS, address[0])
.withProperty(CONFIG_SEGMENT_INDEX, -1).withLabel(label).withProperties(properties)
.withProperty(CONFIG_SEGMENT_INDEX, 0).withLabel(label).withProperties(properties)
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).build();
}

Expand Down
Loading