Loosely following @rlkoshak’s Journey to Jython #1, I keep failing to get ‘basic’ functions to work in Jython such as to send a mail and notify myself via Telegram.
I followed the install instructions for the helper libraries.
Basic .py script execution works but I have the vague feeling I missed something essential during setup because both issues seem to be related to library location, scoping or similar.
(Mail and telegram binding both are installed in OH2.5)
from core.actions import Mail
already chokes at the beginning:
2019-12-16 20:57:17.042 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/battery.py': ImportError: cannot import name Mail in <script> at line number 5
telegram = actions.get("telegram", "telegram:telegramBot:nnnnnnnnn") telegram.sendTelegram("Hello *World* " + u"\U0001F44D")
2019-12-16 20:43:23.004 [ERROR] [jython.battery monitor ] - Traceback (most recent call last): File "/etc/openhab2/automation/lib/python/core/log.py", line 51, in wrapper return fn(*args, **kwargs) File "<script>", line 50, in battery_check AttributeError: 'NoneType' object has no attribute 'sendTelegram' 2019-12-16 20:43:23.025 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule '2b49105b-692b-427c-90f4-ecfb34c446f6':
It also does not make a difference to have this at the beginning (from someone this code works for)
from core.jsr223 import scope from core.jsr223.scope import actions
Any ideas? I start feeling silly.
PS: stumbling across this and browsing the docs as a normal user, I came across several binding docs pages with examples. But they’re all in rules DSL.
I think we would need to complement all of them with Python equivalent ? (JS or Groovy I think is not so important as it isn’t all too much used)