Use Timer in script?

Hi, trying to find an example of using a Timer in script.

What I want to do is execute several commands with a little delay.
I can do it in rules, but i want the code in a script so I can use it in multiple rules

my working rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
var Timer timer

rule “rPoolOff”
when
Item Pool_Master changed from ON to OFF
then
sendCommand(Pool_Heating, OFF)
// wait until heater has cooled down
timer = createTimer(now.plusSeconds(60)) [|sendCommand(Pool_Circulation, OFF) ]
end

tnx in advance

You just need something like:

callScript(“automation_Active.script”)

in your THEN clause.

Script is:

var Number automationActiveDimmer

automationActiveDimmer=100
while(automationActiveDimmer > 0 {
    automationActiveDimmer=automationActiveDimmer-20
    sendCommand(di_LIGHT_LivingRoom_rf,automationActiveDimmer)
    Thread::sleep(2000)
}
You cannot feed arguments or environmental imports to the rule --- it has to be self-contained.

You mean you cannot feed arguments or environmental imports to the script.

OK
so “Thread::sleep(xxx)” is the right thing to use in scripts ?

tnx for the answers

/taisto

It should work in a script. If it doesn’t, try java.lang.Thread::sleep(xxx).

Thread::sleep(2000) Does work as originally posted.