I have searched all forum for what I’m trying to do.
But I have a hard time grasping what is written here on the forum and converting it to my own rules.
Basically this is the idea.
I have 2 locks, when both locks are open more than 5 minutes I want to turn on my xiaomi gateway light to color red.
If one lock is locked within those 5 minutes I want to cancel the above timer.
However, if the timer has fired because the locks are open more than 5 minutes and I lock one lock.
I want to fire a timer that turns the color red to green and hold the green for 1 minute before turning off.
And sub sequentially, if one lock is locked and I lock the other lock, I want nothing to happen.
I have two ITEM switches AR5xReedSwitch_Timer1 and AR5xReedSwitch_Timer2.
This is my rule file
var Timer AR5xReedSwitch_Timer1 = null
var Timer AR5xReedSwitch_Timer2 = null
rule "door lock warn after 5 min open"
when
Item AR50ReedSwitch received update or
Item AR51ReedSwitch received update
then
if (AR50ReedSwitch.state==OPEN && AR51ReedSwitch.state==OPEN) {
logInfo("Demo","rule 1 started")
if (AR5xReedSwitch_Timer2 !== null) {
logInfo("Demo","rule 1 started and a timer 2 was found SETTING RED")
AR5xReedSwitch_Timer2.cancel()
AR5xReedSwitch_Timer1=createTimer(now.plusMinutes(1)) [|
logInfo("Demo","timer 1 ran, and 2 was cancelled before")
Xiaomi1GatewayBrightness.sendCommand(100)
Xiaomi1GatewayColor.sendCommand(new HSBType(new DecimalType(1), new PercentType(100), new PercentType(100))) ]
}
else
logInfo("Demo","timer 2 was null and setting RED")
AR5xReedSwitch_Timer1=createTimer(now.plusMinutes(1)) [|
logInfo("Demo","timer 1 ran")
Xiaomi1GatewayBrightness.sendCommand(100)
Xiaomi1GatewayColor.sendCommand(new HSBType(new DecimalType(1), new PercentType(100), new PercentType(100))) ]
}
end
rule "cancel timers if one or two locks are closed"
when
Item AR50ReedSwitch changed to CLOSED or
Item AR51ReedSwitch changed to CLOSED
then
if (AR5xReedSwitch_Timer1 === null) {
if (AR5xReedSwitch_Timer2 !== null) {
logInfo("Demo","there was no timer 1 but there is a timer 2")
}
else
logInfo("Demo","there was no timer 1 but there is NO timer 2")
}
else if (AR5xReedSwitch_Timer1 !== null) {
logInfo("Demo","timer 1 is active but cancels now. Setting GREEN")
AR5xReedSwitch_Timer1.cancel()
Xiaomi1GatewayColor.sendCommand(new HSBType(new DecimalType(100), new PercentType(100), new PercentType(1)))
AR5xReedSwitch_Timer2=createTimer(now.plusMinutes(1)) [|
logInfo("Demo","timer 2 is ran and timer 1 was cancelled")
Xiaomi1GatewayBrightness.sendCommand(0) ]
}
end
I get errors like these.
I do not understand why some timers seems to be running even if they are not running etc.
20:38:22.541 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘door lock w
arn after 5 min open’: An error occurred during the script execution: Could not
invoke method: org.eclipse.smarthome.model.script.actions.Timer.cancel() on inst
ance: AR5xReedSwitch_Timer2 (Type=SwitchItem, State=NULL, Label=null, Category=n
ull)
@rlkoshak, sorry to disturb you, but in all the similar threads, you’ve been the solution to almost every answer