From 55ed9ba4c2d499d5a1de98ff55ce6a61e9c22277 Mon Sep 17 00:00:00 2001 From: Ben Chadwick Date: Mon, 10 Dec 2018 11:03:53 -0500 Subject: [PATCH 1/2] initial HSL replacement code --- README.md | 2 ++ .../com/bwssystems/HABridge/hue/ColorDecode.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b6b491a..3c5596e 100644 --- a/README.md +++ b/README.md @@ -489,6 +489,8 @@ For the items that want to have a date time put into the message, utilize ${time Color has been added as a replacement control and the available values are ${color.r}, ${color.g}, ${color.b} which are representations of each color as 0 - 255. There are hex equivalents as well as ${color.rx}, ${color.gx}, ${color.bx} and ${color.rgbx} as 2 place hex representations except for rgbx which is a six place hex representation. +Color can also be replaced with ${color.hsl} which will output a string in the Hue/Saturation/Brightness comma-delineated format, useful for many devices under OpenHAB. The format will be a 0-360 hue value, a 0-100 saturation value, and a 0-100 brightness value, separated by commas. (Such devices usually accept either a full HSB value in that format, or a single ${intensity.percent} value for the dimming value, send as raw text in a POST request.) + Special handling for milights is included and is handled by ${color.milight:x}. The usage for that is as follows: udp://ip:port/0x${color.milight:x} where x is a number between 0 and 4 (0 all groups, 1-4 specific group). The group is necessary in case the color turns out to be white. The correct group on must of course be sent before that udp packet. Note that milight can only use 255 colors and white is handled completely separate for the rgbw strips, so setting temperature via ct with milight does something but not really the desired result diff --git a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java index 86421de..2ff2f7a 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.awt.Color; import org.slf4j.Logger; @@ -20,6 +21,7 @@ public class ColorDecode { private static final String COLOR_GX = "${color.gx}"; private static final String COLOR_BX = "${color.bx}"; private static final String COLOR_RGBX = "${color.rgbx}"; + private static final String COLOR_HSL = "${color.hsl}"; private static final Pattern COLOR_MILIGHT = Pattern.compile("\\$\\{color.milight\\:([01234])\\}"); public static List convertCIEtoRGB(List xy, int brightness) { @@ -197,8 +199,18 @@ public class ColorDecode { if (request.contains(COLOR_RGBX)) { request = request.replace(COLOR_RGBX, String.format("%02X%02X%02X", rgb.get(0), rgb.get(1), rgb.get(2))); notDone = true; - } - + } + + if (request.contains(COLOR_HSL)) { + float[] hsb = new float[3]; + Color.RGBtoHSB(rgb.get(0),rgb.get(1),rgb.get(2),hsb); + float hue = hsb[0] * (float) 360.0; + float sat = hsb[1] * (float) 100.0; + float bright = hsb[2] * (float) 100.0; + request = request.replace(COLOR_HSL, String.format("%f,%f,%f", hue, sat, bright)); + notDone = true; + } + Matcher m = COLOR_MILIGHT.matcher(request); while (m.find()) { int group = Integer.parseInt(m.group(1)); From 56481f3f727db96635cb9d8c5c2caeeb07ac6e93 Mon Sep 17 00:00:00 2001 From: Ben Chadwick Date: Mon, 10 Dec 2018 11:08:53 -0500 Subject: [PATCH 2/2] indentation and typo correction --- README.md | 2 +- src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c5596e..6de1d38 100644 --- a/README.md +++ b/README.md @@ -489,7 +489,7 @@ For the items that want to have a date time put into the message, utilize ${time Color has been added as a replacement control and the available values are ${color.r}, ${color.g}, ${color.b} which are representations of each color as 0 - 255. There are hex equivalents as well as ${color.rx}, ${color.gx}, ${color.bx} and ${color.rgbx} as 2 place hex representations except for rgbx which is a six place hex representation. -Color can also be replaced with ${color.hsl} which will output a string in the Hue/Saturation/Brightness comma-delineated format, useful for many devices under OpenHAB. The format will be a 0-360 hue value, a 0-100 saturation value, and a 0-100 brightness value, separated by commas. (Such devices usually accept either a full HSB value in that format, or a single ${intensity.percent} value for the dimming value, send as raw text in a POST request.) +Color can also be replaced with ${color.hsl} which will output a string in the Hue/Saturation/Brightness comma-delineated format, useful for many devices under OpenHAB. The format will be a 0-360 hue value, a 0-100 saturation value, and a 0-100 brightness value, separated by commas. (Such devices usually accept either a full HSB value in that format, or a single ${intensity.percent} value for the dimming value, sent as raw text in a POST request.) Special handling for milights is included and is handled by ${color.milight:x}. The usage for that is as follows: udp://ip:port/0x${color.milight:x} where x is a number between 0 and 4 (0 all groups, 1-4 specific group). The group is necessary in case the color turns out to be white. The correct group on must of course be sent before that udp packet. Note that milight can only use 255 colors and white is handled completely separate for the rgbw strips, so setting temperature via ct with milight does something but not really the desired result diff --git a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java index 2ff2f7a..ad9a3af 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java @@ -209,7 +209,7 @@ public class ColorDecode { float bright = hsb[2] * (float) 100.0; request = request.replace(COLOR_HSL, String.format("%f,%f,%f", hue, sat, bright)); notDone = true; - } + } Matcher m = COLOR_MILIGHT.matcher(request); while (m.find()) {