Hi there!
I’m using Steve Bates lovely Jython scripting repository for openHAB 2.x
I have noticed when using the StartupTrigger that 50% of the times the script executes twice when I save the py-file. When that happens and it runs for the first time the code below crashes. (See log) When it’s only running a single time, it works perfect.
from org.eclipse.smarthome.model.persistence.extensions import PersistenceExtensions
from openhab.rules import rule, addRule
from openhab.triggers import StartupTrigger
@rule
class MyTestRule(object):
def getEventTriggers(self):
return [
StartupTrigger()
]
def execute(self, modules, inputs):
self.log.info('Running')
self.log.info(PersistenceExtensions.lastUpdate(ir.getItem('AmbientLight_Backyard')).toDateTime())
addRule(MyTestRule())
Log:
2018-02-06 13:45:48.298 [INFO ] [ort.shared.ScriptedAutomationManager] - removeAll added handlers
2018-02-06 13:45:48.300 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'testa.py'
2018-02-06 13:45:48.309 [INFO ] [ort.shared.ScriptedAutomationManager] - removeAll added handlers
2018-02-06 13:45:48.309 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'testa.py'
2018-02-06 13:45:48.310 [INFO ] [sboh2j.MyTestRule ] - Running
2018-02-06 13:45:48.311 [ERROR] [.automation.core.internal.RuleEngine] - Failed to execute rule 'MyTestRule-9affd619-b564-4533-ac38-b0c2fe88474f': Fail to execute action: 1
2018-02-06 13:45:48.317 [INFO ] [sboh2j.MyTestRule ] - Running
2018-02-06 13:45:48.320 [INFO ] [sboh2j.MyTestRule ] - 2018-02-06T13:45:25.124+01:00
I can’t figure out how to solve this. Any ideas someone?