Skip to content

Commit

Permalink
[espmilight] Add color channels ability to trigger white LEDs (openha…
Browse files Browse the repository at this point in the history
…b#11047)

* Add white shortcut for sat threshold


Signed-off-by: Matthew Skinner <matt@pcmus.com>

* Fix compiler warnings.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
  • Loading branch information
Skinah authored and thinkingstone committed Nov 7, 2021
1 parent 9197d7f commit f02414a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.mqtt.espmilighthub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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"));
Expand All @@ -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);
Expand All @@ -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"));
Expand Down Expand Up @@ -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) {
Expand All @@ -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()) + "}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
<default>32</default>
</parameter>

<parameter name="whiteThreshold" type="integer" required="true" min="-1" max="99">
<label>White Threshold</label>
<description>Saturation values at or below this value on a RGBW color control will trigger the white mode. -1 will
disable
this feature.
</description>
<default>6</default>
</parameter>

<parameter name="favouriteWhite" type="integer" required="true" min="153" max="370">
<label>Favourite White</label>
<description>When a shortcut triggers white mode, use this for the colour white.</description>
Expand Down Expand Up @@ -101,7 +110,8 @@

<parameter name="whiteThreshold" type="integer" required="true" min="-1" max="99">
<label>White Threshold</label>
<description>RGBW saturation changes, will trigger the white mode. -1 will disable this feature.
<description>Saturation values at or below this value on a RGBW color control will trigger the white mode. -1 will
disable this feature.
</description>
<default>12</default>
</parameter>
Expand Down

0 comments on commit f02414a

Please sign in to comment.