I cannot explain this strange behaviour:
In the setup obove the timer is in testTimer.py the function inside the lambada is implemented in myLib.py
This way it works
When move the timer initialisation into a fuction in myLib.py it behaves different:
in lib/python/personal/myLib.py
def timerOff(itm, timeout):
from core.log import logging, LOG_PREFIX
from threading import Timer
log = logging.getLogger(LOG_PREFIX + ".this.is.my.log")
Timer(timeout, lambda: turnOFF(itm)).start()
log.info("timer initiated! item : " + str(itm))
return None
def turnOFF(itm):
from core.jsr223 import scope
from core.log import logging, LOG_PREFIX
log = logging.getLogger(LOG_PREFIX + ".this.is.my.log")
log.info("Before sendCommand")
scope.events.sendCommand(itm,"OFF")
log.info("After sendCommand")
return None
in jsr223/personal/testTimer.py
import personal.myLib
reload(personal.myLib)
import personal.myLib
from threading import Timer
from core.log import logging, LOG_PREFIX
from personal.myLib import myLog, timerOff, turnOFF
log = logging.getLogger(LOG_PREFIX + ".this.is.my.log")
events.sendCommand("ProxySwitch","ON")
#Timer(10, lambda: turnOFF(ir.getItem("ProxySwitch"))).start()
timerOff(ir.getItem("ProxySwitch"), 3)
log.info("timer initiated")
the log output
2019-05-16 19:34:30.987 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'personal/testTimer.py'
2019-05-16 19:34:31.173 [INFO ] [jsr223.jython.this.is.my.log ] - timer initiated! item : ProxySwitch (Type=SwitchItem, State=ON, Label=Proxy Switch, Category=null)
2019-05-16 19:34:31.182 [INFO ] [jsr223.jython.this.is.my.log ] - timer initiated
2019-05-16 19:34:31.186 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: personal/testTimer.py
2019-05-16 19:34:34.178 [INFO ] [jsr223.jython.this.is.my.log ] - Before sendCommand
scope.events.sendCommand(itm,“OFF”) never executes
if I switch to Timer(10, lambda: turnOFF(ir.getItem(“ProxySwitch”))).start()
#events.sendCommand("ProxySwitch","ON")
Timer(3, lambda: turnOFF(ir.getItem("ProxySwitch"))).start()
the log is
2019-05-16 19:37:53.997 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'personal/testTimer.py'
2019-05-16 19:37:54.160 [INFO ] [jsr223.jython.this.is.my.log ] - timer initiated! item : ProxySwitch (Type=SwitchItem, State=ON, Label=Proxy Switch, Category=null)
2019-05-16 19:37:54.168 [INFO ] [jsr223.jython.this.is.my.log ] - timer initiated
2019-05-16 19:37:54.171 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: personal/testTimer.py
==> /openhab/userdata/logs/events.log <==
2019-05-16 19:37:57.220 [ome.event.ItemCommandEvent] - Item 'ProxySwitch' received command OFF
2019-05-16 19:37:57.236 [vent.ItemStateChangedEvent] - ProxySwitch changed from ON to OFF
2019-05-16 19:37:57.256 [.event.RuleStatusInfoEvent] - 972e18bb-1b66-45cb-99f6-fe89c8801684 updated: RUNNING
2019-05-16 19:37:57.263 [ome.event.ItemCommandEvent] - Item 'ProxySwitchText' received command Proxy gone to OFF
2019-05-16 19:37:57.269 [.event.RuleStatusInfoEvent] - 972e18bb-1b66-45cb-99f6-fe89c8801684 updated: IDLE
2019-05-16 19:37:57.293 [vent.ItemStateChangedEvent] - ProxySwitchText changed from Proxy gone to ON to Proxy gone to OFF
==> /openhab/userdata/logs/openhab.log <==
2019-05-16 19:37:57.177 [INFO ] [jsr223.jython.this.is.my.log ] - Before sendCommand
2019-05-16 19:37:57.194 [INFO ] [jsr223.jython.this.is.my.log ] - Before sendCommand
2019-05-16 19:37:57.210 [INFO ] [jsr223.jython.this.is.my.log ] - After sendCommand
2019-05-16 19:37:57.239 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger 'Item-ProxySwitch-changed' of rule '972e18bb-1b66-45cb-99f6-fe89c8801684' is triggered.
2019-05-16 19:37:57.261 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule '972e18bb-1b66-45cb-99f6-fe89c8801684' is executed.
No guess why tis is this way