I’m running OpenHAB 2.2 stable on Ubuntu on a (mini) PC. I recently decided to port my existing DSL rules to JSR223 scripting. First I decided I wanted to use ECMAscript since I’m more familiar with Javascript and since it’s enabled by default but I quickly realized there are more sample scripts in Jython/Python and apparently more users favor Python over ECMAscript. Having said that, I’m running into an issue where after I restart OpenHAB, some libraries/modules apparently haven’t been loaded yet, causing errors in the startup sequence op OpenHAB. It also prevents my scripts/rules from being initialized altogether after a fresh restart. Whenever I force a reload of a certain script by ‘touching’ the script file, all goes well…
This is the error I keep getting during the startup of OpenHAB.
Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/test.py': NameError: name 'SimpleRule' is not defined in <script> at line number 4
I created a very simple test script that has no other dependencies other than the ‘RuleSimple’ and ‘RuleSupport’ preset for testing purposes.
scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")
class MyRule(SimpleRule):
def __init__(self):
self.triggers = [
Trigger("MyTrigger", "core.ItemStateUpdateTrigger",
Configuration({ "itemName": "TestString1"}))
]
def execute(self, module, input):
events.postUpdate("TestString2", "some data")
automationManager.addRule(MyRule())
I’ve seen a few users posting similar problems to this community, but I haven’t seen a single solution been posted yet. I even tried to upgrade to the OpenHAB-2.3 nightly build but aside from the fact that it did not resolve this particular issue, it also introduced some errors with my existing DSL rule scripts so I was quick to revert back to 2.2 stable.
Can anyone shed some light on this issue for me or help me find a workaround? A workaround (so it seems) would be to run a shell script that ‘touches’ the .py script files after startup to force a refresh, but this seems like a rarther dirty solution to me…
Thanks!