This page last changed on Jul 31, 2015 by robnas.

Hello,

I want to convert the value of the colourpicker(HEX) to this format: R,G,B
i know the colourpicker give values like: FF0000 (for colour red) and it must be converted with comma's to: 255,0,0

i have this script:

public static Color hex2Rgb(String colorStr)
{
    return result[0] Color(
            Integer.valueOf( colorStr.substring( 0, 2 ), 16 ),
            Integer.valueOf( colorStr.substring( 2, 4 ), 16 ),
            Integer.valueOf( colorStr.substring( 4, 6 ), 16 ) );
}


rule "color-picker value"
when
CustomState(source == "virtualColorSens", $rgb:value)
then
execute.command("kleurenkiezer-ring", hex2rgb($rgb)[0]);
end

but is doesnt work, any sugestions?

Hi Rob,

Richard Turner very kindly wrote a rule for me to test the colour picker with 3 Velbus dimmer channels.

It works really well, so much so that I've adapted it a little to use with 3 separate colour pickers and 9 dimmer channels. 3 x RGB.
Then once again so that 1 more colour picker sets all 9 channels.

Richard has given me permission to share his work publicly.

Please let me know how get on with it.

Good luck.

Stuart

Rule to convert Colour picker into VMB4DC
dimmer commands

Where "186-Ch1R-on", "186-Ch2G-on" & "186-Ch3B-on" are simple 'Dimmer_Level' commands for 3 VMB4DC dimmer channels and "RGB_Status" is the Virtual status command the Colour Picker is sending its value to.


package org.openremote.controller.protocol;

global org.openremote.controller.statuscache.CommandFacade execute;

import java.util.*;
rule "RGB To 3 Channels" when

  $evt:Event( source == "RGB_Status", $val : value)

then

  String valStr = $val.toString();
  
  if (valStr != null && valStr.length() == 6) {
  
      // Split colour into RGB
      String rStr = valStr.substring(0,2);
      String gStr = valStr.substring(2,4);
      String bStr = valStr.substring(4,6);
      
      // Convert hex values to int
      Integer r = Integer.parseInt(rStr, 16);
      Integer g = Integer.parseInt(gStr, 16);
      Integer b = Integer.parseInt(bStr, 16);

      // Convert 0-255 value to 0-100
      r = (int)Math.round(((double)r / 255d) * 100);
      g = (int)Math.round(((double)g / 255d) * 100);
      b = (int)Math.round(((double)b / 255d) * 100);

      execute.command( "186-Ch1R-on", r.toString() );

      execute.command( "186-Ch2G-on", g.toString() );

      execute.command( "186-Ch3B-on", b.toString() );
  }
end

Okay, I give up.

I've tried 10 times to get this code tag to work.

What am I doing wrong?

This text file contains the rule code :-

Http://www.MDAR.co.UK/dl/rule1.txt

Sept 2015,
HAR!

I used a noformat tag and it worked.

Posted by mdar at Aug 03, 2015 22:58

Hi Stuart,

i will check the code and let you know thanks. your code needs to begin and with

Unknown macro: { code }

package org.openremote.controller.protocol;

global org.openremote.controller.statuscache.CommandFacade execute;

import java.util.*;
rule "RGB To 3 Channels" when

  $evt:Event( source == "RGB_Status", $val : value)

then

  String valStr = $val.toString();
  
  if (valStr != null && valStr.length() == 6) {
  
      // Split colour into RGB
      String rStr = valStr.substring(0,2);
      String gStr = valStr.substring(2,4);
      String bStr = valStr.substring(4,6);
      
      // Convert hex values to int
      Integer r = Integer.parseInt(rStr, 16);
      Integer g = Integer.parseInt(gStr, 16);
      Integer b = Integer.parseInt(bStr, 16);

      // Convert 0-255 value to 0-100
      r = (int)Math.round(((double)r / 255d) * 100);
      g = (int)Math.round(((double)g / 255d) * 100);
      b = (int)Math.round(((double)b / 255d) * 100);

      execute.command( "186-Ch1R-on", r.toString() );

      execute.command( "186-Ch2G-on", g.toString() );

      execute.command( "186-Ch3B-on", b.toString() );
  }
end
Posted by robnas at Aug 04, 2015 11:58

Stuart,

it works, i had to combine the red, green and blue value into one string.

My full project is to control the ambilight hyperion via openremote:

full project: http://www.instructables.com/id/DIY-Ambilight-with-Hyperion-Works-with-HDMIAV-Sour/

you can control it by an standard hyperion app in the appstore, but you can also change colour via a raw telnet command like:

 {"color": [255,0,0], "command": "color", "priority": 100} 

(more info about commands: https://github.com/tvdzwan/hyperion/issues/316 & https://github.com/tvdzwan/hyperion/wiki)
send this command via openremote to the raspberry's ip and to port 19444, it will change to the colour red (255,0,0) see http://www.color-hex.com/color/ff0000

Using colourpicker to change colour:
create a sensor which receives the colourpicker commands like FF0000

add this to your rules:

package org.openremote.controller.protocol;

global org.openremote.controller.statuscache.CommandFacade execute;

import java.util.*;

rule " color-picker value " 
when
  $evt:Event( source == "virtualColorSens", $val : value)
then

  String valStr = $val.toString();
  
  if (valStr != null && valStr.length() == 6) {
  
      // Split colour into RGB
      String rStr = valStr.substring(0,2);
      String gStr = valStr.substring(2,4);
      String bStr = valStr.substring(4,6);
      
      // Convert hex values to int
      Integer r = Integer.parseInt(rStr, 16);
      Integer g = Integer.parseInt(gStr, 16);
      Integer b = Integer.parseInt(bStr, 16);


execute.command("kleurenkiezer-ring", r.toString()  + "," + g.toString()  + "," + b.toString());
}
end

this script will convert the FF0000 value to 255,0,0 and send it to $param in the telnet command.
create a telnet command called "kleurenkiezer-ring"
fill in the raspberry's ip and port (standard is 19444)
use this command:

null|{"color": [${param}], "command": "color", "priority": 50}

it now sends the colourpickers value to the hyperion server

Posted by robnas at Aug 04, 2015 14:51

Hi Rob,

It's great to know the code has helped.

Good luck with the rest of your design.

Cheers

Stuart

Posted by mdar at Sep 08, 2015 17:10
Document generated by Confluence on Jun 05, 2016 09:32