I have a huge problem with a rule.
The code is this:
import org.openhab.model.script.actions.Timer
var Timer timer_bad
rule "Heizung Bad ausschalten"
when
Item heizung_1 received update ON
then
timer_bad = null
timer_bad = createTimer(now.plusMinutes(30)) [|
sendCommand(heizung_1, OFF)
timer_bad = null
]
end
When heizung_1 receive an update my heaeter shall heat 30 minutes and then it shall turn off. But what happens is, it turns off after some minutes or it don’t turn off.
Do someone know what’s wrong?
Note that an Item can receive lots of updates to the same state. Since you do not check to see if timer_bad already has a Timer running you might be setting up multiple timers.
Setting timer_bad to null does not cancel the timer.
First thing to try is change your rule trigger to received command ON which will only trigger the rule when it is explicetly commanded. That will eliminate the first potential problem.
The second thing to try is to check whether you already have a running Timer and if so just reschedule that one, or cancel that one and create a new one.
NOTE: to properly format code put three backticks before and after the code
unfortunately it’s still not running safe. When I make a check and include 5 minutes only (I do not want to wait always 30 minutes) in the code it runs. But when I use my heater in the evening with the down displayed 30 minutes it don’t turn off the heater. Can it be an other problem. Manual turn on and off runs 100%.
Here the present code:
var Timer timer_bad
rule "Heizung_Bad_ausschalten"
when
Item heizung_1 received command ON
then
if(timer_bad != null && !timer_bad.hasTerminated){
timer_bad.reschedule(now.plusMinutes(30))
}
else {
timer_bad = createTimer(now.plusMinutes(30), [|
sendCommand(heizung_1, OFF)
timer_bad = null
]
)
}
end
This is less than ideal because if you send the ON command while it is sleeping that command will essentially be ignored (not really but the end result will look like it is ignored).
You could go down the path of turning on and off the heater based on some other events such as temperature or time relative to sunrise or sunset.
It’s really crazy. I had a look into the events.log and see that the item themselves run:
2016-07-10 00:57:41 - heizung_1 received command ON
2016-07-10 00:57:41 - heizung_1 state updated to ON
But there is no hint to the rule. The item get the update to ON but the rule seems not to start. But why? Is there a reason that prevent to start the rule?
By the way, if I use like proposed the sleep order, do openhab run furthermore or do it prevent all other rules etc.