Is V_RGB Supported in OpenHAB?
-
Hi,
Is it possible to send a hex value (ff0000) with type 40 (V_RGB) from OpenHAB? Or is it possible to create a custom item with type 40?
I want the message sent to look like this: 8;1;1;0;40;ffc550
Cheers
-
Hi
Openhab and the MySensors binding use the HSTtype format (hue, saturation, brightness) for color information.
The binding automatically converts the HSBtype to the MySensors format of RRGGBB.
So you need to use the HSBType fromRGB(int R, int G, int B) functionitems
Color Mock_RGB_LED "Mock RGB LED (HSB) " (test254) { channel = "mysensors:rgbLight:gatewayWIFI3:Mock_RGB_LED:rgb" } String test_RGB_HexString "Test Color RGB hexS [0x%s]" (test254) Number test_RGB_Red " Test Colour Red [%s]" (test254) Number test_RGB_Green " Test Colour Green [%s]" (test254) Number test_RGB_Blue " Test Colour Blue [%s]" (test254)
Rules
val String filename = "rgb-light.rules" rule "System startup" when System started then /*Initial value of colors*/ if (test_RGB_Red.state == NULL) test_RGB_Red.postUpdate(0) if (test_RGB_Green.state == NULL) test_RGB_Green.postUpdate(0) if (test_RGB_Blue.state == NULL) test_RGB_Blue.postUpdate(0) end rule "Test Colour Channels RGB to Mysensors" when Item test_RGB_Red changed or Item test_RGB_Green changed or Item test_RGB_Blue changed then val int r = (test_RGB_Red.state as Number).intValue val int g = (test_RGB_Green.state as Number).intValue val int b = (test_RGB_Blue.state as Number).intValue logInfo(filename, "Input Conversion: r:" + r + " g:" + g + " b:" + b) var HSBType hsb = HSBType.fromRGB(r, g, b) logInfo(filename, "Input Conversion: hsb" + hsb) Mock_RGB_LED.sendCommand(hsb) end rule "RGB Hex -> HSB" when Item test_RGB_HexString received update then var rgb = test_RGB_HexString.state.toString var r = Integer::parseInt(rgb.substring(0, 2), 16) var g = Integer::parseInt(rgb.substring(2, 4), 16) var b = Integer::parseInt(rgb.substring(4, 6), 16) logInfo(filename, "Input Conversion: r" + r + " g" + g + " b" + b) var HSBType hsb = HSBType.fromRGB(r, g, b) logInfo(filename, "Input Conversion: hsb" + hsb) Mock_RGB_LED.sendCommand(hsb) end /* I find this most useful for testing the node the Node */ rule "Test Colour Channels RGB to Mysensors" when Item test_RGB_Red changed or Item test_RGB_Green changed or Item test_RGB_Blue changed then var int r = (test_RGB_Red.state as Number).intValue var int g = (test_RGB_Green.state as Number).intValue var int b = (test_RGB_Blue.state as Number).intValue logInfo(filename, "Input Conversion: r:" + r + " g:" + g + " b:" + b) var HSBType hsb = HSBType.fromRGB(r, g, b) logInfo(filename, "Input Conversion: hsb" + hsb) Mock_RGB_LED.sendCommand(hsb) end
-
Thank you @hard-shovel! It works. It doesn't store the value between reboots but I guess that's a different topic which I will look into.
Cheers
3 out of 3
Suggested Topics
-
Boxes and Enclosures
Enclosures / 3D Printing • 29 Mar 2014, 21:02 • PITP2 31 Aug 2014, 19:27 -
OH3, RPi3, GPIO-NRF24 gateway. MySensors binding (ETH or MQTT?)
OpenHAB • 30 Sept 2021, 10:24 • perIpI 1 Oct 2021, 09:19 -
openhab binding mysensors
OpenHAB • 14 Mar 2021, 18:44 • MDS 15 Mar 2021, 21:56 -
OH2.5.9 / ethernet gateway / autodiscovery?
OpenHAB • 20 Oct 2020, 15:31 • Stefferd 22 Oct 2020, 13:38 -
openHAB 2.2 binding
OpenHAB • 18 Jul 2017, 12:49 • TimO 23 Dec 2020, 14:32 -
OH3 Serial Gateway Problem
OpenHAB • 15 Feb 2022, 09:48 • seppi9 22 Feb 2022, 13:44