A timer executes a series of actions after its delay
but how can I have the opposite:
a series of actions that execute during the time of a timer and stop only at the end of this timer
val timer Mytimer = createTimer(now.plusSeconds(60), [|
//do something during the time of 60 seconds
//do something
]) // stop
In fact, no matter " what to do "… my question is how to have a routine that will run for a duration ‘x’.
In fact, I’m trying to do the opposite of what a timer does when it stops running for for a duration ‘x’
I found a subterfuge:
Using a switch that I put ON, then using a timer that will put this Swith OFF once the tempo is over.
And then using a rules that is triggered by a Cron every 30 seconds, which runs as long as the Switch.state is ON
rule "Simulation ON"
when
Item Start_Sw received command ON //Trigger Start
then
Exec_Sw.sendCommand(ON)
val timer timer_Exec = createTimer(now.plusMinutes(XXX), [|
Exec_Sw=sendCommand(OFF) //Stop
])
}
end
rule "Simulation en cours"
when
Time cron "0/30 0/1 * 1/1 * ? *" //every 30 secondes
then
if ( Exec_Simul.state == OFF) { return }
//do something
end
In fact precision is not a problem … this rule (“Simulation ON”) is used to trigger a simulation of presence at a certain time, to which I add a random delay and which must execute a random time (between 2 values)
rule "Simulation ON"
when
//Time cron "0 43 20 ? * * *" // Start after 20h43
then
if (Simulation.state == ON ){
val Integer Tempo = rand.nextInt(40+5)+17 // Tempo between 17 & 40 min
//Start at = 20h43 + Tempo
val timer timer_Start = createTimer(now.plusMinutes (Tempo), [|
// wait for decallage Start
])
Exec_Simul.sendCommand(ON)
val Integer Duration= rand.nextInt(80+10)+150 // duration between 2h30 & 3h10
val timer timer_Duration = createTimer(now.plusMinutes(Duration), [|
Exec_Simul=sendCommand(OFF)
timer_Duration = null
])
}
end
then as long as the Simul.sendCommand Switch is on “ON” I execute a presence simulation sequence
rule "Simulation en cours"
when
Time cron "0 0/48 * 1/1 * ? *" //every 48 minutes
//Item Exec_Simul received command ON
then
if ( Exec_Simul.state == OFF) { return }
// do presence simulation sequence
end