Random number to create a slow chase

Hi

No surprise here, yet another Rules question...

(Will someone please just charge me € for doing these?)

With the ability to scene set DMX & SPi universe', I just can't resist trying to get OpenRemote to (slowly) fire off commands to create a simple random chase.

I found this :-

import java.util.Random;

public class RandomNumber {
    private int randomNumber;

    public void begin() {
        this.randomNumber = new Random().nextInt( 100 );
    }

    public void setValue(final int value) {
        this.randomNumber = value;
    }

    public int getValue() {
        return this.randomNumber;
    }

}

And I'm wondering how best to use it to create a 6 digit HEX RGB string.

I can easily obtain an interval timer in Velbus, so triggering a rule is straight forward.

(Following is just a thought, not a working rule)

Rule "Random Chase"

When

Sensor "Interval Timer" value == "on"

Then

public class RandomNumber {
    private int randomNumber;

    public void begin() {
        this.randomNumber = new Random().nextInt( 255 );
    }

    public void setValue(final int value) {
        this.randomNumber = value;
    }

    public int getValue() {
        return this.randomNumber;
    }

}

[Something to turn the number into a HEX string]

Then

Execute.command ("RGB_Uni0", $HEX)

End

rule “-Generate random 6 digits hex”

timer(int: 0 10s) // Remove this when acting on Event, otherwise it will generate a new random every 10 seconds

when

// Event(source==“your trigger”, value==“on”) // Make sure that value is not “on” inbetween, otherwise the rule won’t trigger or you need explicitly retract the event

then

java.util.Random randomGenerator = new java.util.Random();

execute.command(“RGB_Uni0”, String.format("%06X", randomGenerator.nextInt(0x1000000)));

end

I say :slight_smile:

Thanks Michal.

I was thinking that it would be far more complex than that :slight_smile:

I'm in an installation right now that I might be able to try that out with :slight_smile:

Otherwise, I'll give it a go at home next week.

How much do I owe you now?

Cheers,

Stuart

Hi

I'm sorry, I forgot to say thank you for this.

It's been working really well :slight_smile:

I've also expanded it to a little single pixel DMX architectural light.

The only issue as that the random numbers it generates tended to be quite small, so the red elements aren't called for very often.

So I gently tweaked the code to generate 3 x 2 digit HEX values to make more use of the full RGB range.

This is the code that's working really well.

execute.command("DMX_Universal-200","pixel.api?uni=5&ordercolour=rgb&onecolour=" + String.format("%02X", randomGenerator.nextInt(0x1000000)) + String.format("%02X", randomGenerator.nextInt(0x1000000)) + String.format("%02X", randomGenerator.nextInt(0x1000000)) + "&start=1&end=1");

Thanks again,

Stuart

Hello

For those that are following this thread and are interested in seeing it in action, I made this quick and simple video of an installation I did last year.

youtu.be/_5OZvMJusUI