Problem with simple rule

Hello,

I have a simple rule, which causes troubles. Spend some time verifying syntax, trying different variations.
But the it doesn’t work properly. Any idea why? Thank you in advance!

The rule:

var Timer waitTimer = null

rule "TV Relay OFF"
when
Item SmartTV received update or
Item gTrig received update
if (SmartTV.state==OFF) {
waitTimer = createTimer(now.plusMinutes(10)) [| sendCommand(sonoff01, OFF) ]
}
end    

Error message:

2017-04-03 20:08:36.476 [ERROR] [org.quartz.core.ErrorLogger ] - Job (DEFAULT.2017-04- 03T20:08:36.458+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | { sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>) } ] threw an exception. ...

Add “then”:

rule "TV Relay OFF"
when
Item SmartTV received update or
Item gTrig received update
then
     if (SmartTV.state==OFF) {
           waitTimer = createTimer(now.plusMinutes(10)) [| sendCommand(sonoff01, OFF) ]
     }
end

Thanks for the support!
In fact, I had “then” in my rule, only by troubleshooting and removing the code to find out what exactly is causing problems deleted “then”.

Not sure why but it seems that createTimer triggers the error message in OH2.
I’ve added import org.openhab.model.script.actions.Timer which doesn’t help.

Additionally, the rule is running in the loop without being triggered. Totally confused :slight_smile:

2017-04-05 23:15:01.456 [ItemStateChangedEvent     ] - sonoff01 changed from ON to OFF
2017-04-05 23:16:00.587 [ItemCommandEvent          ] - Item 'sonoff01' received command OFF
2017-04-05 23:17:00.652 [ItemCommandEvent          ] - Item 'sonoff01' received command OFF
2017-04-05 23:18:00.651 [ItemCommandEvent          ] - Item 'sonoff01' received command OFF
2017-04-05 23:19:00.656 [ItemCommandEvent          ] - Item 'sonoff01' received command OFF

Any suggestions are welcome!

you should post all items related (sonoff01, smarttv,gtrig).
also, add some log messages in the rule so you know when which part is executed.

Find out the problem - it was in Item SmartTV received update line.
Apparently, the Network binding is pinging SmartTV item which is receiving the update and triggering the rule every time.
Changing Item SmartTV received update to Item SmartTV changed to OFF solved the problem.

Thanks!