A few comments on your rule code that have nothing to do with your original question but which might improve it or your OH’s overall performance. These are not intended to be critiques, just suggestions.
You can trigger the rule on Item auto received command ON and drop the if(auto.state == ON) in the rule. You really should trigger something like this with a command instead of an update for logical consistency.
What is conta? I assume it is a global variable but there is no clue as to when or how it gets set in this code.
Thread::sleep longer than 300 msec are strongly discouraged. A better approach is to use Timers.
I don’t understand why this code is in a loop at all. All of the Lights are set to the same color value each time through the loop. What is driving the loop? Is there some other way you can trigger a rule based on an event to reset the light’s color instead of looping?
If you have any other rules that care about time of day I recommend adopting the Time of Day DP.
It is usually better practice to use the sendCommand methods instead of the sendCommand Actions. For example:
SL_INGRESSO_1.sendCommand(“67;78;100”)
Since you set the lights all to the same color, you should define the color as a val so if you decide to tweak the color later you can do so in only one place.
Since you set the lights all to the same color, you should add them all to a Group:Color Lights and send the command to the Group. The command will be forwarded to all the members of the Group.
Given the comments above, your Rule could look something like the following (note, I don’t know enough details to implement the removal of the loop so below implements something equivalent). This uses the Time of Day DP and Expire Based Timers DP.
New Items
Group:Color Lights
Switch Ciclo_Timer { expire="1m,command=OFF" }
Number conta
NOTE: I’ve moved conta to an Item instead of a global var, still don’t know what it does or how it gets populated
val dayColor = "67;78;100"
rule "ciclo"
when
Item auto received command ON
then
if(vTimeOfDay.state == "DAY") {
Lights.sendCommand(dayColor)
Ciclo_Timer.sendCommand(ON)
}
end
rule "ciclo Timer"
when
Item Ciclo_Timer received command OFF
then
Lights.sendCommand(dayColor)
if(auto.state == ON && conta.state as Number == 0 && vTimeOfDay.state == "DAY") {
Ciclo_Timer.sendCommand(ON)
}
end
rule "conta"
when
Item conta changed
then
if(conta.state as Number != 0) Ciclo_Timer.postUpdate(OFF)
end