JSR223 Jyton and Canceling Timers

I’ve successfully been able to upgrade to the latest snapshot and enable JSR233 support which is VERY exciting. I’ve just not been interested in trying to script out rules in the old way as it was too limiting and cumbersome. Thank you for enabling this!

I’m confident that this is something simple but I can’t seem to figure it out. All I want to do is cancel a trigger or really a timer that is running. In the old way… “myrtles.rules” you would simply store a reference and then cancel it:

//define a variable to store it
timer = null

//and within a rule

timer = createTimer(now.plusSeconds(10), [ |
      logInfo("FILE", "Timer expired - Bill Murray is the best!")
      timerTest = null

// eventually if you were done with it...

Now with Jython, I’ve not been able to cancel a timer or trigger that’s been created. Dig through the API a bit as well. Any help would be appreciated.

Docs: http://docs.openhab.org/configuration/jsr223.html#event_operations
Docs w/ examples: https://github.com/eclipse/smarthome/wiki/Scripted-Rule-Support


class myRule(SimpleRule):
    def execute(self, module, inputs):
        print "Hello World from Jython"
sRule = myRule()

sRule.setTriggers([Trigger("aTimerTrigger", "timer.GenericCronTrigger", Configuration({"cronExpression": "0/15 * * * * ?"}))])


In the above I’ve saved off a reference to the Trigger, to the sRule.setTriggers(… and attempted to call cancel(), cancel or anything else and nothing works.

Please see my post here on how to create and cancel a timer with OH2/Jython:

Yes! Of course - use all the standard Python stuff… Well that makes life so much easier. Thanks for pointing this out. The linked example worked like a charm.