Rule Takes VERY long time to load

Try that. Could be that the nextInt() function only accept integers

            PartyLights.members.forEach[ light |
                light.sendCommand(ThreadLocalRandom::current().nextInt(361) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness.intValue - MinBrightness.intValue) + MinBrightness.intValue))
            ]

It runs, but takes a minute or two to load, while the other way takes less than 10 seconds to load.

This is what I have decided to use for now, since it loads very fast and works perfectly:

rule "Party"
when
    Item Party changed to ON or
    System started
then
    if (triggeringItem === null) {
        Party.postUpdate(OFF)
        logInfo("info", "Loaded model 'party.rules'")
        return;
    }
    Bedroom.sendCommand(OFF)
    Hallway.sendCommand(OFF)
    Kitchen.sendCommand(OFF)
    Livingroom.sendCommand(0)
    createTimer(now.plusSeconds(1), [ | DiscoBall_Switch.sendCommand(ON) ])
    createTimer(now.plusSeconds(3), [ |
        Livingroom_Sync.sendCommand(ON)
        Livingroom.postUpdate(100)
        val Rand = new java.util.Random
        while (Party.state == ON) {
            PartyLights.members.forEach[ light |
                light.sendCommand(Rand.nextInt(360) + ",100," + (Rand.nextInt(1 + 65 - 15) + 15))
            ]
            Thread::sleep(900)
        }
        Livingroom.sendCommand(0)
        Hallway.sendCommand(OFF)
        DiscoBall_Switch.sendCommand(OFF)
        Thread::sleep(1000)
        Livingroom_Temperature.sendCommand(84)
        Livingroom.sendCommand(100)
    ])
end

I am starting to think that it could have been the use of int that was causing the load times all along. :confused:

I have seen strong evidence that the use of primitives is a major cause of slow loading times, particularly on Rpis. I was glad to see that was the first suggestion on the thread.

This also adds good evidence to that being the culprit.

It would really be helpful if you filled an issue on the ESH repo referring to this thread. I think this thread is the suggest evidence so far that primitives are the problem.

1 Like

@BigRedBrent

Check out this syntax for generating random number by: @Jo_C
In: Looking for Software utilities. like chrono, timer,

+1

@BigRedBrent please file it and let us know the number please once you did, we’re collecting important issues to track them.

I can probably guess what you mean by the ESH repo, but I don’t want to make a mistake. Since you obviously know what and where it exactly is, please give me the link to the issues section where I may open up an issue.

To be honest, I never would have found that link. But thanks to you I can now assume that this is the correct link:

While I fear this one is not the only one lurking it’s at least a starting point that can be used for further analysis.
I opened https://github.com/openhab/openhab-core/issues/451 and hope some knowledgeable core developer is willing to take on it.

1 Like