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) function

    items

    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


Log in to reply
 

Suggested Topics

  • 22
  • 3
  • 5
  • 135
  • 19
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts