I want to give a try to jython rules. I installed the automation plugin and also folloed the instructions posted here.
When reaching the verification step with the hello_world.py, I get an error in the log
2021-01-24 23:15:04.069 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/personal/hello_world.py'
2021-01-24 23:15:07.647 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab/automation/jsr223/python/personal/hello_world.py
2021-01-24 23:15:12.121 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/personal/hello_world.py': ImportError: No module named joda in <script> at line number 6
I have not customized configuration.py (except for the email address), nor set EXTRA_JAVA_OPTS (according to this).
So, what am I missing?
FYI, the addition error appears at the start - see below.
Thanks!
Max
2021-01-24 23:08:17.452 [WARN ] [jython.startup ] -
*******************************************************************************
Jython version: 2.7.2.final
Operating system: Linux
OS Version: 5.4.83-v7l+
Java vendor: Azul Systems, Inc.
Java VM name: OpenJDK Client VM
Java runtime name: OpenJDK Runtime Environment
Java runtime version: 11.0.9+11-LTS
configuration.py installed: True
sys.path: /etc/openhab/automation/lib/python
/var/lib/openhab/cache/org.eclipse.osgi/263/0/bundleFile/Lib
__classpath__
__pyclasspath__/
*******************************************************************************
2021-01-24 23:08:17.459 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py'
2021-01-24 23:08:19.845 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NullPointerException: null
at org.openhab.binding.mqtt.generic.MqttChannelTypeProvider.derive(MqttChannelTypeProvider.java:132) ~[?:?]
at org.openhab.binding.mqtt.homeassistant.internal.discovery.HomeAssistantDiscovery.publishResults(HomeAssistantDiscovery.java:197) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
2021-01-24 23:08:21.802 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 8
With openhab 3 you no longer need to modify the EXTRA_JAVA_OPTS. The error you are seeing is because the helper libraries have not been upgraded to work with OH3 yet, but there is an open Pull Request #376 with a version that works.
thanks for pointing out to the issue - I am not sure if I want to wait for the official release or going for the cutting edge⦠I am not a big fan of DSL rules
@Max77 I finally migrated to OH3 with the Jithon helper libs workaround one week ago. No issues so far. I have 70 things, around 700 items and around 100 Jithon rules. There is only one DSL rule remaining (timeLinePicker).
@Max77 the changes required to get the libraries working on OH3 are actually quite small. Iβve done previous work on the Helper Libraries and went over Jimβs work and fixed a few things that were missed (that PR contains those updates). I have been running that version ever since with no issues, you should not be concerned about stability.
Next (small?) issue - I have tried the hello_world.py as instructed
"""
This script uses a decorated cron rule that will generate logs every 10s and can be used to test your initial setup.
"""
from core.rules import rule
from core.triggers import when
@rule("Jython Hello World (cron decorators)", description="This is an example cron triggered rule using decorators", tags=["Test tag", "Hello World"])# description and tags are optional
@when("Time cron 0/10 * * * * ?")
def hello_world_cron_decorators(event):
hello_world_cron_decorators.log.info("Hello World!")
and I can see the rule is triggered by the cron event (in 10s +/- 2ms )
2021-01-27 22:55:31.362 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPadMax_Location' changed...
2021-01-27 22:55:40.372 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Time_cron_0_10_27eeb05e60ea11ebb38bdca63251b192_28834f4060ea11ebbc57dca63251b192' of rule '8377f5bd-38a0-4ab7-887f-40965cc56b74' is triggered.
2021-01-27 22:55:40.375 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule '8377f5bd-38a0-4ab7-887f-40965cc56b74' is executed.
2021-01-27 22:55:50.374 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Time_cron_0_10_27eeb05e60ea11ebb38bdca63251b192_28834f4060ea11ebbc57dca63251b192' of rule '8377f5bd-38a0-4ab7-887f-40965cc56b74' is triggered.
2021-01-27 22:55:50.378 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule '8377f5bd-38a0-4ab7-887f-40965cc56b74' is executed.
But why I do not see any βHello World!β message? Am I missing something? I have looked to the different OH logging capabilities, but no explanation came to my mind.
Now I can start working with JS223 rules - they seem the right way to get access to semantic data (as compared to DSL rules) and achieve what I want to do