Caveat: Noobie to everything openHAB but learning.
Pi2/openHAB 1.71 - Demo working fine
Installed Jython at /opt/jython
java -jar /opt/jython/jython.jar -v
Takes about 10 seconds to execute and this is output:
import: ‘exceptions’ as org.python.core.exceptions in builtin modules
import: ‘sys’ as sys in builtin modules
import: ‘errno’ as org.python.modules.errno in builtin modules
import: ‘posix’ as org.python.modules.posix.PosixModule in builtin modules
import: ‘MemoryHistory’ as java class
import: ‘_sre’ as org.python.modules._sre in builtin modules
import: ‘_codecs’ as org.python.modules._codecs in builtin modules
import: ‘array’ as org.python.modules.ArrayModule in builtin modules
import: ‘_functools’ as org.python.modules._functools._functools in builtin modules
import: ‘StringBuilder’ as java class
import: ‘ByteBuffer’ as java class
import: ‘CharBuffer’ as java class
import: ‘Charset’ as java class
import: ‘IllegalCharsetNameException’ as java class
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot™ Client VM (Oracle Corporation)] on java1.8.0
Type “help”, “copyright”, “credits” or “license” for more information.
but the rule never executes.
Do I have to put something somewhere else? I’m assuming when openHAB logs 21:25:51.389 [INFO ] [o.c.j.i.e.scriptmanager.Script:84 ] - Loading Script testrule.py
then openHAB found the rule.
If you don’t see Jython being listed, then the jython JAR file was not found. This is usually a classpath issue. When the rule file is loaded, you’ll see something like:
Rather than call the jar file with the -jar option, I add that jar to the classpath and add org.eclipse.equinox.launcher.Main to the end of the command line, like the example in the wiki:
Started over with a clean openhab install and python now works.
Also used this github_test
A lot of gotchas for me which others may not notice.
This will help in porting much of my python code.
Thanks much for your kind assistance.
It seems when I make a change to my Python code {openhab}scripts/*.py that I have to restart the server. Is there anyway to reload the changed script for execution without the length process of restarting?
Yes to DEBUG monitoring of logs.
If I change a py file, I’ll see this in logs but then it never executes again. 2015-12-21 15:22:57.901 [DEBUG] [.c.j.i.e.s.ScriptUpdateWatcher] - ENTRY_DELETE: UpdateThermostats.py 2015-12-21 15:22:57.906 [DEBUG] [.j.i.engine.RuleTriggerManager] - Removed scheduled cron job 'UpdateThermostats.py#org.python.proxies.__builtin__$UpdateThermostats$1@80bf48#0 0/38 * 1/1 * ? *'
For example, say I simply change the CRON frequency from 38 minutes to 2 minutes. It will never execute again until restart. (Just to be clear, the script will run every 2 minutes on next restart.)
Try running the command: touch updateThermostats.py. I’ve found that the JSR223 binding is a little less forgiving of the file saving dance that editors such as vim do when writing to a file than the normal OH rules engine.
Thanks so much, Rob! It’s odd that it noticed the file changed and deleted the entry and never reloaded but the touch command saves me a lot of time over restarting the server.
Update: touch causes it to load and execute but not always with the changes. For example, I changed some DEBUG log statements by commenting them out with # and after a save and touch, they still executed. Maybe there’s some kind of samba problem for me.