This page last changed on Mar 02, 2015 by robnas.


does anyone know how to convert decimal to hex in a rule?
i made a slider with a range sensor from value 1 to 31, that value is $h, i want to send it to a tcp command.
my catalina.out log says:

ERROR 2015-02-26 17:30:21,268 : Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
ERROR Controller Definition File Watcher for Default Deployer: Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
ERROR 2015-02-26 17:30:21,269 : Rule Compilation error Type mismatch: cannot convert from Object to int
hex cannot be resolved
ERROR Controller Definition File Watcher for Default Deployer: Rule Compilation error Type mismatch: cannot convert from Object to int
hex cannot be resolved
Rule Compilation error : Rule name='snelheid wifi rgb controller1'
org/openremote/controller/protocol/ (7:952) : Type mismatch: cannot convert from Object to int
org/openremote/controller/protocol/ (9:1019) : hex cannot be resolved


rule "snelheid wifi rgb controller1"
CustomState ( source == "snelheid.rgb1", $h: value )
int Val=$h;
String Hex=Integer.toHexString(Val);
log(String.format("%.1f", hex));
execute.command("output", hex);

I guess the // in front of all your lines is for formatting reasons within the forums. To avoid this, please enclose your code between {code} tags.
As a general comment on your code, the rules body are Java and Java is case sensitive, so Hex does not equal hex, hence the error reported by the rules compiler.

In your rule, $h will be a string that contains the decimal value.
You should thus parse it to an int, then format it to an hex value to give to the command to execute.
So something like (not tested)

int val = Integer.parseInt($h);
String hexValue = Integer.toHexString(val);
execute.command("output", hexValue);
Posted by ebariaux at Mar 02, 2015 19:51


Thanks for the tip I changed the code above

the code looks correct it's part of code for a led rgb controller ( wifi 370 controller)

I found this code and would like to control it via a rule:




import javafx.scene.paint.Color;

public class Wifi370 {

    public static void main(String argv[]) throws Exception {

        final byte[] greenMsg = colour(Color.MEDIUMAQUAMARINE);

        final byte[] redMsg = colour(Color.CORAL);

        final byte[] blueMsg = colour(Color.ALICEBLUE);

        InetAddress group = InetAddress.getByName("");

        try (Socket clientSocket = new Socket(group, 5577)) {

            DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

            outToServer.write(control((byte) 0x23));

            do {

                outToServer.write(preset((byte) 0x25, (byte) 150));


                for (int i = 0; i < 10; i++) {








            } while (true);




     Combining Multiple Commands into one TCP packet

     We didn't throughly test this, but the WiFi Controller seemed quite happy when we concatenated multiple commands

     into one TCP packet instead of sending two. i.e. to set the colour mode and turn OPEN on, sending the following

     packet should suffice:

     56 ff 00 ff aa cc 23 33



     I think it should be possible to do what you want to do using the custom mode of the controller. In this mode,

     you can set the sequence of colours that you want the controller to cycle through. Most of the detail is in the

     "custom colour mode" section of the post, so I'll just post an overview of what I think the method should be.

     To fade from colour A to colour B, the sequence of commands could be:

     Set custom colour mode sequence to A, B, B, B, ... [99 rA gA bA (rB gB bB)x15 16 3a ff 66]

     The initial colour A, is set so that LEDs start on the current colour (this might not be necessary)

     The reason for having multiple B colours, is to give you time to pause the sequence after the colour has changed.

     I can't remember if there is any other way to stop looping.


     Start playback of the sequence [cc 20 33]

     Wait some time

     Stop the sequence [cc 21 33]



     * Colour Ring Mode


     * This is the simplest mode and simply sets the colour of the LEDs to the

     * sent RGB colour. The command consists of five bytes: a header, a three

     * byte colour code and a footer byte:


     * 0x56 - header RR - RED value GG - GREEN value BB - BLUE value 0xaa -

     * footer


     * e.g.: 56 00 ff 00 aa -> sets the LEDs to GREEN


    private static byte[] colour(Color c) {

        final byte[] msg = {(byte) 0x56, (byte) (c.getRed() * 255), (byte) (c.getGreen() * 255), (byte) (c.getBlue() * 255), (byte) 0xaa};

        return msg;


I have a rule which will get the hex value of the colour picker and would send it to the code above. The value has to be received by this line "private static byte[] colour" I believe. Do you know a method?

Posted by robnas at Mar 02, 2015 20:54
Document generated by Confluence on Jun 05, 2016 09:35