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
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
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
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.