openhab-scripters / openhab-helper-libraries Goto Github PK
View Code? Open in Web Editor NEWScripts and modules for use with openHAB
License: Eclipse Public License 1.0
Scripts and modules for use with openHAB
License: Eclipse Public License 1.0
It seems that, custom Jython trigger handlers are not working with recent builds (tested with 2.4.0-M5/M6). At least OSGI and Directory triggers, do register when starting scripts are run, but rules created with said triggers fail with Missing handler error:
[INFO ] [smarthome.event.RuleStatusInfoEvent ] - 590217ff-e78e-427f-9cf4-9874d8340c79 updated: UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Missing handler 'jsr223.OsgiEventTrigger' for module
It took me a day to discover that it is not my rule but simply something is broken ;-) I think I've seen conversation somewhere on openhab forums stating, that this thingy is broken but I've do not see an issue for that.
When OH is started, any scripts under $OPENHAB_CONF/automation/jsr223/community/ are loaded and run before any script under $OPENHAB_CONF/automation/jsr223/core/, most notably jsr223/core/000_startup_delay.py.
Logs from my recent OH start:
2019-01-23 08:02:14.328 [INFO ][pool-1-thread-1][rt.internal.loader.ScriptFileWatcher] - Loading script 'community/openweathermap/owm_daily_forecast.py'
2019-01-23 08:02:27.480 [INFO ][pool-1-thread-1][rt.internal.loader.ScriptFileWatcher] - Loading script 'core/000_startup_delay.py'
2019-01-23 08:03:37.709 [INFO ][pool-1-thread-1][rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_DirectoryTrigger.py'
Possible fixes (untested):
zzz_community
community/
to a new directory immediately below jsr223
: jsr223/local/community
.So I started rewriting the docs... I will convert them to Sphinx at the same time (#42)
I have created a pull request for this and will push changes to that branch as I go. This way everyone will be able to see the changes and make corrections and improvements. Feel free to make pull requests on my branch if you have any contributions!
One of my main goals is make using this library more accessible. The current documentation is somewhat brief and technical, which is fine for me, but I know many openHAB users are not programmers beyond writing rules.
My other goal is to break up some of the larger pages (looking at you Jython Modules) and restructure the docs somewhat to make them follow a narrative (Home -> Install -> Getting Started -> Advanced). Since I will be migrating the docs to Sphinx, large pages like Jython Modules may stay a single page, but with the sidebar and chapters, will become much easier to navigate.
I also want to add examples with full explanations of how to convert existing DSL rules into rules for this library. There are already docs on how to write a rule and the 'But How Do I...' page (which I referenced often when I started converting my rules), but again they are concise. There are also concepts such as functions which differ greatly from the DSL to JSR223 which there doesn't seem to be much explanation of how to do. If one has written anything in Python before, they are fairly obvious, but for anyone just starting out I think some openHAB specific examples and explanation are needed.
Feel free to chime in with any suggestions you may have, be it on structure, examples you'd like to see, or places you think the docs need clarification
Mike
In preparation for OH JSR223-Jython growth, I would like to come up with a way to isolate the core modules/scripts from collaborative contributions, like Esper. I propose we introduce a community
package with the following directory structure...
|_ Community
|_ Esper
|_ automation
|_ jsr223
|_ community
|_ esper
|_ components
|_ 000_Esper.py
|_ esper_example.py
|_ lib
|_ python
|_ community
|_ esper
|_ Kodi
|_ automation
|_ jsr223
|_ community
|_ kodi
|_ example_kodi_script.py
|_ lib
|_ python
|_ community
|_ kodi
|_ configuration.py.sample
|_ Core
|_ automation
|_ jsr223
|_ community
|_ core
|_ components
|_ 000_startup_delay.py
|_ personal
|_ jython
|_ lib
|_ python
|_ community
|_ core
|_ personal
|_ configuration.py.sample
|_ Docs
|_ Script Examples
|_ Rule Scripts
|_ automation
|_ jsr223
|_ hello_world.py
|_ timer_example.py
One difficulty is that there may be multiple modules with the same name in the community
package, so I think the Community modules should be kept separate in the repo. For example, two contributors may have modules for Kodi named community.kodi
. Of course, any Community module could eventually be merged into the openhab
package, or it could become a separate package of its own.
Hello, i would like the idea to enhance the @when trigger for number items so that the rule only triggers when a certain condition is met.
For example:
@when("Item NumberItem changed to <10")
@when("Item NumberItem changed to >=12")
@when("Item NumberItem changed to ==15")
@when("Item NumberItem changed to 10-15") # >=10 and <=15
One of my use cases is a warning if a room gets to moist. At the moment the rule has to trigger every time and check of the condition is met like this:
@rule("rNotificationRoomTooMoist")
@when("Descendent of gUnisenHum changed")
def rNotificationRoomTooMoist(event):
if event.itemState.floatValue() > 80.0:
log.warn("Room too moist: " + event.itemName)
In my opinion this would be more elegant and furthermore it does not flood the log that much:
@rule("rNotificationRoomTooMoist")
@when("Descendent of gUnisenHum changed to > 80.0")
def rNotificationRoomTooMoist(event):
log.warn("Room too moist: " + event.itemName)
Thanks a lot :)
Describe the bug
Some examples on the page openhab2-jython/Script Examples/hello_world.py don't work.
To Reproduce
Steps to reproduce the behavior:
- RawAPICron
Error:
10-May-2019 22:30:02.680 [ERROR] [ion.module.script.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/personal/in_test/hello_world.py': TypeError: can't convert ['Test tag'] to java.util.Set in <script> at line number 24
Expected behavior
The self.log.info works.
When using the @rule decorator, the problem isn't there.
Environment (please complete the following information):
Additional context
Log entry:
10-May-2019 22:40:00.005 [DEBUG] [.smarthome.automation.core.internal.RuleEngineImpl] - The trigger 'Hello_World_Cron_Trigger' of rule '10b8239a-dcd8-4772-9ca9-a5dcb6637784' is triggered.
10-May-2019 22:40:00.008 [ERROR] [.smarthome.automation.core.internal.RuleEngineImpl] - Failed to execute rule '10b8239a-dcd8-4772-9ca9-a5dcb6637784': Fail to execute action: 1
10-May-2019 22:40:00.010 [DEBUG] [.smarthome.automation.core.internal.RuleEngineImpl] -
java.lang.RuntimeException: Fail to execute action: 1
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1207) ~[205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:1004) [205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at org.eclipse.smarthome.automation.core.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:91) [205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: org.python.core.PyException
at org.python.core.Py.AttributeError(Py.java:205) ~[?:?]
at org.python.core.PyObject.noAttributeError(PyObject.java:1013) ~[?:?]
at org.python.core.PyObject.getattr(PyObject.java:1008) ~[?:?]
at org.python.pycode.pyx50.execute$3(<script>:23) ~[?:?]
at org.python.pycode.pyx50.call_function(<script>) ~[?:?]
at org.python.core.PyTableCode.call(PyTableCode.java:167) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:307) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:198) ~[?:?]
at org.python.core.PyFunction.call(PyFunction.java:482) ~[?:?]
at org.python.core.PyMethod.instancemethod___call(PyMethod.java:237) ~[?:?]
at org.python.core.PyMethod.call(PyMethod.java:228) ~[?:?]
at org.python.core.PyMethod.call(PyMethod.java:218) ~[?:?]
at org.python.core.PyMethod.call(PyMethod.java:213) ~[?:?]
at org.python.core.PyObject._jcallexc(PyObject.java:3626) ~[?:?]
at org.python.core.PyObject._jcall(PyObject.java:3658) ~[?:?]
at org.python.proxies.builtin$RawAPICron$55.execute(Unknown Source) ~[?:?]
at org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate.execute(SimpleRuleActionHandlerDelegate.java:34) ~[?:?]
at org.eclipse.smarthome.automation.module.script.rulesupport.internal.delegates.SimpleActionHandlerDelegate.execute(SimpleActionHandlerDelegate.java:60) ~[?:?]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1199) ~[?:?]
... 7 more
Hi,
I've updated my production environment and enabled Jython.
I do see an error at startup:
2018-12-14 14:09:42.963 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/000_startup_delay.py'
2018-12-14 14:09:48.106 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/C:/OpenHAB/conf/automation/jsr223/core/000_startup_delay.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 3
All subsequent loading of scripts also fail.
I also had this error in my test setup but that was because I didn't had any items defined.
But in my production environment I have around 400 items defined...
I managed to figure out 2 workarounds:
When I restart the ruleengine after startup via
bundle:restart org.eclipse.smarthome.automation.module.script.rulesupport
everything loads perfect and the hello world script runs fine.
If I change the import on line 3 and the creation of the logger in 000_startup_delay.py back to the previous version it also works fine again.
from org.slf4j import Logger, LoggerFactory
log = LoggerFactory.getLogger("org.eclipse.smarthome.model.script.Rules")
I guess that for some unknown reason the items in my setup are not yet loaded when the startup delay script is loaded. Funny thing is that in the log I do see that all items files are loaded but maybe that doesn't mean that the items themselves are fully loaded.
This does make sense since also with the DSL rules I see errors like this at startup:
2018-12-14 14:30:44.468 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Thermostat operating mode master bedroom proxy': The name 'Proxy_Set_OperatingMode_MasterBedroom' cannot be resolved to an item or type; line 568, column 4, length 37
The above appears after the items and rules files have been loaded (and also the 000_startup_delay.py has been loaded).
Do you have any idea what the issue could be?
In the python doc REQUIRES section of owm_daily_forecast.py, the text describing where to add the scale
transformation service is wrong, it should be added to the transformation
setting, not misc
in addons.cfg.
I've been looking at moving from Jython 2.7.0 to Jython 2.7.1 (as it has built in pip
- I think - and a number of other bug fixes), and am getting the traceback as per below.
I'm happy to look at this further, but not really sure where to start - so if you have any pointers, that would be great.
I found that if I remove the ...automation/lib/python/esper/java/esper-6.1.0.jar
file, things appear to work, except for these errors (which is no surprise):
2018-10-21 10:30:45.768 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/000_components/000_Esper.py': ImportError: No module named espertech in <script> at line number 12
2018-10-21 10:30:59.616 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/000_components/100_ExampleExtensionProvider.py': ImportError: cannot import name JythonExtensionProvider in <script> at line number 1
The hello_world.py
example still works, and is logging every 10 seconds.
I'm running things just as outlined in the Docker.md
file, except with the jython 2.7.1 .bin (from http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar), with the latest snapshot (Build 1392).
2018-10-21 10:20:57.225 [ERROR] [m.espertech.esper.timer.EPLTimerTask] - Timer thread caught unhandled exception: com/espertech/esper/client/time/CurrentTimeEvent
java.lang.NoClassDefFoundError: com/espertech/esper/client/time/CurrentTimeEvent
at com.espertech.esper.core.service.EPRuntimeImpl.timerCallback(EPRuntimeImpl.java:186) ~[?:?]
at com.espertech.esper.timer.EPLTimerTask.run(EPLTimerTask.java:57) [?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: com.espertech.esper.client.time.CurrentTimeEvent
at org.python.core.SyspathJavaLoader.findClass(SyspathJavaLoader.java:128) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
... 9 more
2018-10-21 10:20:57.321 [ERROR] [m.espertech.esper.timer.EPLTimerTask] - Timer thread caught unhandled exception: com/espertech/esper/client/time/CurrentTimeEvent
java.lang.NoClassDefFoundError: com/espertech/esper/client/time/CurrentTimeEvent
at com.espertech.esper.core.service.EPRuntimeImpl.timerCallback(EPRuntimeImpl.java:186) ~[?:?]
at com.espertech.esper.timer.EPLTimerTask.run(EPLTimerTask.java:57) [?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
Hello, it would be helpful if the rule name instead of rule UID would be displayed in logging.
Now it is like this:
2018-12-09 07:04:02.917 [.event.RuleStatusInfoEvent] - 7d8c1156-54a3-4913-b85b-cb083e66cf92 updated: RUNNING
But it would be easier for reading the logs or debugging if it was like this:
2018-12-09 07:04:02.917 [.event.RuleStatusInfoEvent] - what-ever-rule updated: RUNNING
I think you already mentioned it here.
Thanks a lot :)
Describe the bug
I've run into an issue whilst trying to convert some of my DSL rules into jython rules.
I am using the following rule decorator which when parsed causes an invalid rule:
@when("Item SONYReceiverSTRDN1080_Zone1_InputSource changed to \"netService:audio?service=spotify\"")
The error given is:
(INVALID_RULE): Validation of rule 144040b7-9cc8-4db4-95b0-6ad7fbadd717 has failed! Invalid module uid: Item-SONYReceiverSTRDN1080_Zone1_InputSource-changed-to-"netService:audio?service=spotify". It is null or not fit to the pattern: [A-Za-z0-9_-]*
It appears that the library is trying to convert the when clause into a trigger uid. As my when clause contains escaped quotes (which is valid) when converted into a trigger uid it violates the given regex pattern ([A-Za-z0-9_-]*) governing valid trigger uids.
Have looked through the code briefly (and not being a python expert) I think the issue is on this line or the following lines:
To Reproduce
Steps to reproduce the behavior:
Create the following jython rule and place in the personal directory:
from core.rules import rule
from core.triggers import when
@rule("Change Sony AVR Sound Field (Spotify)", description="This is an example Item changed triggered rule using decorators", tags=["Exa$
@when("Item SONYReceiverSTRDN1080_Zone1_InputSource changed to \"netService:audio?service=spotify\"")
def hellowWorldItemUpdateDecorators(event):
hellowWorldItemUpdateDecorators.log.info(event.itemName + " hello world" )
Expected behavior
The library creates a rule with a valid trigger uid.
Environment (please complete the following information):
I for example have full permission to this repo. I believe it's better to revise the permission levels for this repo. Using proper permission levels will help prevent accidental damage to the repo.
I believe my own permissions should be restricted to make pull requests.
Would you mind adding a license to your repo such that it can be reused by others?
Thanks
When using core.items.add_item, the Items created are not created in persistent storage (they're not there after an OH restart). Same for remove_item. Adding ManagedItemProvider will resolve this.
before I create a pull request I want to ask if we can revert the init parameter order of the class ItemStateChangeTrigger
in the past it was like
class ItemStateChangeTrigger(Trigger):
def __init__(self, itemName, state=None, triggerName=None, previousState=None):
now it is
class ItemStateChangeTrigger(Trigger):
def __init__(self, itemName, previousState=None, state=None, triggerName=None):
was this a mistake or a wanted change. I ask because I have modify > 50 places.
Describe the bug
When converting a datetime value (2019-06-04T09:00:00.000+0200) to a python datetime a stack trace is logged and the python date is not returned.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A python datetime object should be returned
Troubleshooting info
I believe the error occurs on this line
return ZonedDateTime.ofInstant(value.toInstant(), ZoneId.of(value.getTimeZone().getId()))
i tried to isolate is and it seems like the error is in the part
value.getTimeZone().getId()
doesn't work as
logging.info(str(value.getTimeZone().getId())
doesn't work either.
the value of garbage_retrieval_datetime is 2019-06-04T09:00:00.000+0200 and it's type is <type 'org.eclipse.smarthome.core.library.types.DateTimeType'>
** My script **
scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")
from core.log import logging
#from core.triggers import StartupTrigger, CronTrigger
from core.triggers import CronTrigger
from core import date
from core.actions import Pushover
import datetime
from dateutil.relativedelta import relativedelta
import json
import requests
from java.util import Calendar, GregorianCalendar
class rule_notify_afvalkalender(SimpleRule):
def __init__(self):
self.triggers = [
# StartupTrigger(), # for testing
CronTrigger("0 0 19 1/1 * ? *").trigger, # cron: check every day @ 19:00
CronTrigger("0 0 21 1/1 * ? *").trigger # cron: check every day @ 21:00
]
def execute(self, module, input):
# add items empty check, if so, run the above rule
now = datetime.datetime.now()
earliest_garbage_retrieval_type = str(items.afvalkalender_earliest)
garbage_retrieval_datetime = getattr(items, earliest_garbage_retrieval_type)
logging.info (garbage_retrieval_datetime)
logging.info("before1")
garbage_retrieval_datetime_python = date.to_python_datetime(garbage_retrieval_datetime)
logging.info("after1")
delta = garbage_retrieval_datetime_python - now
logging.info("test1")
if delta.days == 0:
if earliest_garbage_retrieval_type == "afvalkalender_packages":
garbage_description = "plastic"
elif earliest_garbage_retrieval_type == "afvalkalender_paper":
garbage_description = "papier"
elif earliest_garbage_retrieval_type == "afvalkalender_greengrey":
garbage_description = "duo"
msg = "Morgenochtend wordt de " + garbage_description + "bak geleegd!"
logging.info("Posting msg: " + msg)
#Pushover.sendPushoverMessage(Pushover.pushoverBuilder(msg))
Pushover.pushover(msg, "Telefoon_prive_rick01")
automationManager.addRule(rule_notify_afvalkalender())
Environment (please complete the following information):
Additional context
Stack trace
30-May-2019 11:41:36.362 [WARN ] [.smarthome.automation.core.internal.RuleEngineImpl] - Fail to execute action: 1
org.python.core.PyException: null
at org.python.core.Py.AttributeError(Py.java:207) ~[?:?]
at org.python.core.PyObject.noAttributeError(PyObject.java:1032) ~[?:?]
at org.python.core.PyObject.__getattr__(PyObject.java:1027) ~[?:?]
at core.date$py.to_java_zoneddatetime$7(/openhab/conf/automation/lib/python/core/date.py:163) ~[?:?]
at core.date$py.call_function(/openhab/conf/automation/lib/python/core/date.py) ~[?:?]
at org.python.core.PyTableCode.call(PyTableCode.java:171) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:139) ~[?:?]
at org.python.core.PyFunction.__call__(PyFunction.java:413) ~[?:?]
at core.date$py.to_java_zoneddatetime$7(/openhab/conf/automation/lib/python/core/date.py:163) ~[?:?]
at core.date$py.call_function(/openhab/conf/automation/lib/python/core/date.py) ~[?:?]
at org.python.core.PyTableCode.call(PyTableCode.java:171) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:139) ~[?:?]
at org.python.core.PyFunction.__call__(PyFunction.java:413) ~[?:?]
at core.date$py.to_python_datetime$9(/openhab/conf/automation/lib/python/core/date.py:190) ~[?:?]
at core.date$py.call_function(/openhab/conf/automation/lib/python/core/date.py) ~[?:?]
at org.python.core.PyTableCode.call(PyTableCode.java:171) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:139) ~[?:?]
at org.python.core.PyFunction.__call__(PyFunction.java:413) ~[?:?]
at org.python.pycode._pyx61.execute$6(<script>:102) ~[?:?]
at org.python.pycode._pyx61.call_function(<script>) ~[?:?]
at org.python.core.PyTableCode.call(PyTableCode.java:171) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:308) ~[?:?]
at org.python.core.PyBaseCode.call(PyBaseCode.java:199) ~[?:?]
at org.python.core.PyFunction.__call__(PyFunction.java:482) ~[?:?]
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237) ~[?:?]
at org.python.core.PyMethod.__call__(PyMethod.java:228) ~[?:?]
at org.python.core.PyMethod.__call__(PyMethod.java:218) ~[?:?]
at org.python.core.PyMethod.__call__(PyMethod.java:213) ~[?:?]
at org.python.core.PyObject._jcallexc(PyObject.java:3644) ~[?:?]
at org.python.core.PyObject._jcall(PyObject.java:3676) ~[?:?]
at org.python.proxies.__builtin__$rule_notify_afvalkalender$61.execute(Unknown Source) ~[?:?]
at org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate.execute(SimpleRuleActionHandlerDelegate.java:34) ~[?:?]
at org.eclipse.smarthome.automation.module.script.rulesupport.internal.delegates.SimpleActionHandlerDelegate.execute(SimpleActionHandlerDelegate.java:60) ~[?:?]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1199) [205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1047) [205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1063) [205:org.eclipse.smarthome.automation.core:0.10.0.oh240]
at org.eclipse.smarthome.automation.rest.internal.RuleResource.runNow(RuleResource.java:288) [214:org.eclipse.smarthome.automation.rest:0.10.0.oh240]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [171:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [172:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [169:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [169:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [169:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [169:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [169:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76) [20:com.eclipsesource.jaxrs.publisher:5.3.1.201602281253]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [186:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [82:org.eclipse.jetty.security:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [186:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [186:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.Server.handle(Server.java:531) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at java.lang.Thread.run(Thread.java:748) [?:?]
This line generates an error in triggers.py, my guess is there needs to be a check that the inputList is not empty? Rule works when you specify to X.
@when ("Item GarageDoubleDoorIndicatorPressed_Value changed from 0")
2018-10-31 14:25:21.132 [ERROR] [omation.core.internal.RuleEngineImpl] - when: Exception [index out of range: 0]: [Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/openhab/triggers.py", line 297, in when
if inputList[0] == "to":
IndexError: index out of range: 0
Hi @steve-bate !
I want to try the set of decorators and functions you have developed for jython but, although I have tried lots of things in the last couple of hours, I haven't achieved anything yet. Can you help me? ;-)
This is my development environment:
It seems that everything is correctly setup, but if I create a demo test.py file ("/etc/openhab2/automation/jsr223/test.py") with just the following line:
from openhab.log import logging
I get the error you can see in the title:
2017-12-05 16:44:36.729 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/test.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 1
Do you have any idea about what's going on? I don't know what else I could try :(
Many many thanks for reading my message and for the code that you have contributed to this repository, it's really great!
Best regards,
Aitor
Hi @steve-bate and @spacemanspiff2007!
I know that you guys are busy, but I can't make the EchoThing example work, so any hint would be very helpful 👍
I have placed all 000_Jython*.py files (JythonBindingInfoProvider, JythonExtensionProvider, JythonItemProvider, JythonThingProvider, JythonThingTypeProvider, JythonTransform) in the /etc/openhab2/automation/jsr223/000_Components folder and I can see in openhab's log file that the files are correctly parsed. The next step was to create the 100_EchoThing.py file and, even if the file is detected by openHAB, the following error can be seeing in the log file:
2017-12-12 12:49:49.511 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/100_EchoThing.py': AttributeError: 'module' object has no attribute 'JythonThingTypeProvider' in <script> at line number 95
The 95th line is where the script tries to add the ThingTypeProvider, but the error indicates that the "openhab" module (import openhab) is not correctly fulfilled with the JythonThingTypeProvider attribute. That should be done at line 25 of the 000_JythonThingTypeProvider.py file (openhab.JythonThingTypeProvider = JythonThingTypeProvider()).
Can anyone confirm if I am the only one having the error? Can you reproduce it?
Sorry for bothering you and many thanks for your help,
Aitor
In order to make it easier for people to find and use helper libraries, I plan to rename the org to openHAB Scripters and add libraries for languages other than Python. I had originally thought creating repos for each language would be best, but I'm now pretty solidly leaning towards putting everything in the same repo. This would mean a new directory structure, but one download would get you all libraries, scripts, examples, etc. for all languages. A single repo is also likely how it would be structured if/when the helper libraries are ever moved into the OH organization.
These changes will happen soon after the lucid migration and other PRs are merged. The lucid changes will need at least one more commit, but it is currently being tested and should be merged this week. I already have @lewie on board for migrating his JS libraries and to come on as a mintainer, with support from @Confectrician. Hopefully someone will step forward for the Groovy libraries. The plan will be to create similar functionality for each of the languages.
For the name of the organization, I propose 'openHAB Scripters'. For the repo, I propose 'helper-libraries'. WDYT? Any input would be appreciated!
Proposed directory structure:
.
├── Community
│ └── An example Community script
│ └── automation
│ └── jsr223
│ ├── groovy
│ │ └── community
│ │ └── an_example__community_script
│ ├── javascript
│ │ └── community
│ │ └── an_example__community_script
│ └── python
│ └── community
│ └── an_example__community_script
├── Core
│ └── automation
│ ├── jsr223
│ │ ├── groovy
│ │ │ ├── community
│ │ │ ├── core
│ │ │ └── personal
│ │ ├── javascript
│ │ │ ├── community
│ │ │ ├── core
│ │ │ └── personal
│ │ └── python
│ │ ├── community
│ │ ├── core
│ │ └── personal
│ └── lib
│ ├── groovy
│ │ ├── community
│ │ ├── core
│ │ └── personal
│ ├── javascript
│ │ ├── community
│ │ ├── core
│ │ └── personal
│ └── python
│ ├── community
│ ├── core
│ └── personal
├── Docker
├── Docs
│ ├── groovy
│ ├── javascript
│ ├── python
│ └── README.md
└── Script Examples
├── groovy
├── javascript
└── python
triggers.py:
class StartupTrigger(Trigger):
def __init__(self, triggerName=None):
triggerName = triggerName or uuid.uuid1().hex
Trigger.__init__(self, triggerName, openhab.STARTUP_MODULE_ID, Configuration())
openhab.STARTUP_MODULE_ID
should probably be something else
Hello, for quite some time i thought about logical AND-links for triggering rules.
OR-links are already possible with successive @when decorators
@when("Item Item1 changed")
@when("Item Item2 changed")
...
but how about a corresponding @and decorator to a @when?
As one of many examples i have a rule that should notify me when a door or window was opened while i am on holiday. It triggers every time a door or window is opened:
@rule("rNotificationDoorWindowOpenedDuringHoliday")
@when("Descendent of gWindowsDoors changed to OPEN")
def rNotificationDooWindowrOpenedDuringHoliday(event):
if items.Sw_sRules_HolidayMode == ON:
# some warning
But i would prefer it would only trigger when i am away, because this would not flood the log that much:
@rule("rNotificationDoorWindowOpenedDuringHoliday")
@when("Descendent of gWindowsDoors changed to OPEN")
@and("Item Sw_sRules_HolidayMode == ON")
def rNotificationDooWindowrOpenedDuringHoliday(event):
# some warning
Whats your opinion? Thanks a lot :)
It would be good to have the ability to enter a PIN code to disarm the alarm.
I already implemented it locally, I'll try to make a PR once ideAlarm is fully migrated.
openhab-5iver commented 4 hours ago
Hello, Rick... glad to see you updated! I don't use ideAlarm, so I don't have an opinion on this. But...
(But then i decided to migrate from 2.3 to 2.4 and all the stuff stopped working :-)).
... caught my eye. Was there functionality lost in the migration, or is it just a matter of setting things up again/in a different way? (sorry if I'm polluting your enhancement request with support questions 🙄)
@ricadelic
Member Author
ricadelic commented 6 minutes ago •
Hi Scott,
no worries of hijacking this thread. If it's going to contain useful info for others, i'll create an issue for it.
The startup trigger didn't work anymore, which i used very much. I saw you fixed it, kudos to you! 💯 To get around this, I implemented a file watcher and a cron job which disabled itself. This updated an item which triggered all the other rules. This kinda replicated the startup trigger.
Also i couldn't get my regular rules working, rules were using the helpers but without the decoraters like:
class rule_scene_lights_living (SimpleRule):
def __init__(self):
self.triggers = [
StartupTrigger(),
ItemCommandTrigger("timer_rule_scene_woonkamer_new_init_hardware", command="OFF"),
ItemStateChangeTrigger("light_woonkamer_dimmer_boekenkast"),
ItemStateChangeTrigger("light_woonkamer_dimmer_vitrinekast"),
ItemStateChangeTrigger("switch_led_strip_tv_toggle", state="ON",previousState="OFF"),
ItemStateChangeTrigger("switch_groene_tl_toggle", state="ON",previousState="OFF"),
ItemStateChangeTrigger("switch_led_strip_tv_toggle", state="OFF",previousState="ON"),
ItemStateChangeTrigger("switch_groene_tl_toggle", state="OFF",previousState="ON"),
ItemCommandTrigger("number_scene_lights_living"),
ItemCommandTrigger("switch_scene_living_chill"),
ItemCommandTrigger("switch_scene_living_full")
]
def execute(self, module, input):
logging.info("RULE WOONKAMER SCENE STARTED")
so i migrated them to the @rule/@when decorators to get it working. However i had a few rules that parsed the trigger name and the command that was send. I couldn't yet find a way to get command, apart from parsing the event text and taking the last bit of the array. Because these kind of little changes, it took me a while to transfer.
if "event" in input:
trigger = str(input['event'])
if "number_scene_lights_living" in trigger:
scene_number = str(input['command'])
logging.info("Recieved command from GUI(" + str(scene_number) + ")")
elif "switch_scene_living_chill" in trigger or "switch_scene_living_full" in trigger:
if input['command'] == OFF:
scene_number = "1"
if items.timer_rule_scene_woonkamer_new_gui_set_new_scene == ON:
logging.info("timer is running, quitting script")
else:
trigger = "startup"
do_stuff()
i changed it like
if "number_ventilator_level_set_manual" in str(event):
level_gui_manual = str(event).split()[-1]
if level_gui_manual == "4":
do_stuff()
However i would rather just have the whole object available. Or know how to retrieve this information in a better way.
Well, @spacemanspiff2007 and @steve-bate , I am not sure issue #8 should be closed. I am seeing the same symptom and I have extensive items defined in .items files. Do these have to be otherwise exposed to jython ?
Running a standalone jython 2.7.1 on RPi3. Latest (or near-latest) dev build of OH2 running under Openhabian. (NB the jython 2.7.1 full distro does not install correctly on RPi3 -- fails on setuptools installation). I have following defined in /etc/default/openhab2:
EXTRA_JAVA_OPTS="-Xbootclasspath/a:/home/openhabian/jython2.7.1/jython.jar
-Dpython.home=/etc/openhab2/lib/python/:/etc/openhab2/automation/jsr223/
-Dpython.path=/etc/openhab2/lib/python/:/etc/openhab2/automation/jsr223/
-Djython.path=/etc/openhab2/lib/python/:/etc/openhab2/automation/jsr223/ "
Hi,
I am trying to write a new rule, based on an example I found here.
Openhab version:
ii openhab2 2.3.0-1
EXTRA_JAVA_OPTS="-Xbootclasspath/a:/opt/jython/jython.jar -Dpython.home=/opt/jython -Dpython.path=/etc/openhab2/automation/lib/python"
Rule extension is loaded:
[INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for python
Simply importing:
from openhab.triggers import StartupTrigger
Gives the following error:
ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/modes.py': ImportError: No module named core in <script> at line number 2
openhab module is correctly installed:
ls -l /etc/openhab2/automation/lib/python/openhab/
total 44
-rw-r--r-- 1 root root 212 Oct 6 17:05 init.py
-rw-r--r-- 1 root root 465 Oct 6 17:05 actions.py
-rw-r--r-- 1 root root 2789 Oct 6 17:05 date.py
-rw-r--r-- 1 root root 659 Oct 6 17:05 items.py
-rw-r--r-- 1 root root 2024 Oct 6 17:05 jsr223.py
-rw-r--r-- 1 root root 1287 Oct 6 17:05 log.py
drwxr-xr-x 2 root root 4096 Oct 6 17:05 osgi
-rw-r--r-- 1 root root 1393 Oct 6 17:05 rules.py
-rw-r--r-- 1 root root 2331 Oct 6 17:05 testing.py
-rw-r--r-- 1 root root 8074 Oct 6 17:05 triggers.py
Removing the import and just doing a simple:
from org.slf4j import LoggerFactory
LoggerFactory.getLogger("org.eclipse.smarthome.automation.examples").info("Hello world!")
works correctly.
Importing openhab.rules works as well:
from openhab.rules import rule, addRule
Any ideas or how I could debug this ?
Thank you
Continuation of lewie/openhab2-javascript#4 now that #94 is complete
@lewie, how would you like to proceed? Would you like me to get things copied over first, using the new directory structure, or would you prefer to do that yourself? I've already added startup delay scripts, and I have a JS OSGI library to add too.
ESH PR #6660 appears to have broken some functionality within the core.actions module. In testing, the action I found to be unavailable is ThingAction.
NotificationAction gave me some trouble, but that was because openhabCloud had uninstalled after the upgrade. It's working fine now... took a reboot after reinstalling for it to show up in core.actions.
Hi,
I started using Jython today and noticed that the hello_world.py script gives an error:
NameError: name 'LoggerFactory' is not defined in <script> at line number 5
https://github.com/OH-Jython-Scripters/openhab2-jython/blob/ffde155b9259db586a191063f187538620a6b43b/Script%20Examples/hello_world.py#L5
Changing LoggerFactory
to logging
fixes the issue.
When loading a module from a jython script, if the module has an error, the logger shows the error coming from the script and not the module in question. The line number of the error is correct but no filename is given. This is problematic for modules which load other modules.
In triggers.py, line 174 there is a when "Descendent of" which is not part of the rules DSL. I believe the "Member of" should be changed to match the behavior of "Descendent of" so that it operates on all items (items and groups) and not just items. Correct me if I am wrong.
Bug Description
When a rule call function A in a custom module, function A sets up a Timer with a function B of the same custom module, function B accesses scope, an exception is thrown "No JSR223 scope is available"
To Reproduce
custom module
from core.jsr223 import scope
from threading import Timer
import core
def executeTimed():
try:
itmState= scope.ir.getItem("ProxySwitch").state
except:
core.JythonExtensionProvider = None
import traceback
log.error(traceback.format_exc())
def setTimer(timeout):
Timer(timeout, lambda: executeTimed()).start()
rule (empty, good enough for run once)
import personal.myLib
reload(personal.myLib)
from personal.myLib import setTimer
setTimer(2)
Expected behavior
no exception is thrown
log
2019-05-17 21:09:15.779 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: personal/testScope.py
2019-05-17 21:09:17.831 [ERROR] [jsr223.jython.this.is.my.log ] - Traceback (most recent call last):
File "/openhab/conf/automation/lib/python/personal/myLib.py", line 45, in executeTimed
itmState= scope.ir.getItem("ProxySwitch").state
File "/openhab/conf/automation/lib/python/core/jsr223.py", line 28, in __getattr__
scope = get_scope()
File "/openhab/conf/automation/lib/python/core/jsr223.py", line 14, in get_scope
raise EnvironmentError("No JSR223 scope is available")
Environment (please complete the following information):
An installation script would make it easier for first-time users to setup JSR223-Jython, as well as update existing installations. It should:
I already have a script built up for manual installation of the zwave and zigbee binding, which I plan to use as a starting point.
I'd like to do a simple version check on OH startup, to compare the core package version with what is in GH and log a message. This could be done for community packages too. So far, we haven't utilized GH releases, and hopefully there is a way to tie in a script after each merge to update the core package version number and release notes, so that it is automated.
Is your feature request related to a problem? Please describe.
Reloading modules can be tricky, and it can be confusing for new users of the libraries. Modules need to be reloaded when testing changes to them.
Describe the solution you'd like
Add core.utils.reload_modules, which will reload all modules.
Continuing discussion from #120 (comment)
All files should be formatted following requirements similar to what is found in the OH Coding Guidelines...
The Jython documentation is being reworked, and this implementation can also be used for the main page of the repo and the other languages. Any decision here, should also consider the possible impact to #89.
The final decisions will go into a Coding Guidelines document in the repo.
@openhab-scripters/owners, @openhab-scripters/maintainers
The function days_between() in Core/automation/lib/python/core/date.py returns the "whole" number of days between to DateTimes.
def days_between(value_from, value_to):
'''Returns number of whole days between value_from and value_to.
Accepts any date type used by this module'''
return DAYS.between(to_java_zoneddatetime(value_from), to_java_zoneddatetime(value_to))
If I have a datetime object from yesterday at 9 AM and I compare it with a datetime today at 8 AM days_between will return 0 days. Can the function be modified so that it optionally only cares about dates. In that way I can use the function to check if a datetime was yesterday.
I'm a bit of a newbie with this stuff, so please forgive me if I've done something wrong with my install, or if this is already on somebody's radar screen.
My installation was working in build 1509. After upgrading to build 1522 (with the integrated ESH), I'm getting these errors at startup.
Is there something I need to change to resolve this?
2019-02-13 09:16:32.708 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_DirectoryTrigger.py'
2019-02-13 09:16:32.737 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/100_DirectoryTrigger.py': ImportError: No module named eclipse in <script> at line number 3
2019-02-13 09:16:32.738 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_OsgiEventTrigger.py'
2019-02-13 09:16:32.865 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/100_OsgiEventTrigger.py': ImportError: No module named eclipse in <script> at line number 5
2019-02-13 09:16:32.867 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_ShutdownTrigger.py'
2019-02-13 09:16:32.883 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/100_ShutdownTrigger.py': ImportError: No module named eclipse in <script> at line number 1
2019-02-13 09:16:32.885 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_StartupTrigger.py'
2019-02-13 09:16:32.901 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/100_StartupTrigger.py': ImportError: No module named eclipse in <script> at line number 1
2019-02-13 09:16:32.902 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonBindingInfoProvider.py'
2019-02-13 09:16:32.916 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/200_JythonBindingInfoProvider.py': ImportError: No module named eclipse in <script> at line number 1
2019-02-13 09:16:32.917 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonExtensionProvider.py'
2019-02-13 09:16:33.667 [ERROR] [.jython.core.JythonExtensionProvider] - Traceback (most recent call last):
File "<script>", line 11, in scriptLoaded
ClassNotFoundException: java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.module.script.ScriptExtensionProvider cannot be found by org.openhab.core.automation.module.script_2.5.0.201902130927
2019-02-13 09:16:33.670 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonItemChannelLinkProvider.py'
2019-02-13 09:16:33.687 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/200_JythonItemChannelLinkProvider.py': ImportError: No module named eclipse in <script> at line number 1
2019-02-13 09:16:33.687 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonItemProvider.py'
2019-02-13 09:16:33.728 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonThingProvider.py'
2019-02-13 09:16:33.748 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonThingTypeProvider.py'
2019-02-13 09:16:33.764 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonTransform.py'
2019-02-13 09:16:33.778 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/core/components/200_JythonTransform.py': ImportError: No module named transform in <script> at line number 1
I suggested to implement support for the mqtt-alarm-control-panel in the old ideAlarm branch. This is an android app that manages locking and unlocking. I really like the idea and the app and i started to implement this in ideAlarm. (But then i decided to migrate from 2.3 to 2.4 and all the stuff stopped working :-)).
We can extend it with support for https://www.hackster.io/thanksmister/mqtt-alarm-control-panel-for-home-assistant-a206cc
To be honest, i do like the implementation described on https://www.home-assistant.io/components/alarm_control_panel.mqtt/ too. If we implement such a standard, we might allow multiple front ends.
Another option is to design a standard habpanel screen which works out of the box.
By making sure we have support for a nice GUI, we have a (full) alarm system with a gui which will probably result in a higher adoption of the ideAlarm system.
What are your opinions on this?
The tags argument to core.items.add_items()
must be iterable, but the default value specified for the tags
argument to add_items()
is None
, which is not iterable. The default value should be an empty list.
I have submitted PR #69 that fixes this on my system.
The remove method requires the same string conversion that was added to the add method.
So I'm currently rewriting the Xioami smarthome .rules pattern into Jython:
https://www.openhab.org/addons/bindings/mihome/
Cubes, Motion Sensor etc are working great so far and I will contribute it to the .README if every rules working out.
But I've noticed that the Contact items are not supported or am I wrong?
Code:
#Door Sensor #1 Heizungskeller
@rule("Xiaomi Door/Window Sensor Heizungskeller")
@when("Item Door_Openstatus1 received command OPEN")
@when("Item Door_lastopened1 changed")
@when("Item Door_Openstatus1 changed from CLOSED to OPEN")
def heizungskellerLicht(event):
x = int(items["gMotionOffset"])
logXC.info("Licht im Heizungskeller: angeschalten, wird in "+str(x)+" Minuten ausgeschalten.")
sendCommand(items["Yeelights_3"], "ON")
windowTimer= Timer(x, lambda: events.sendCommand("Yeelights_3","OFF"))
Exception:
2019-01-31 20:48:47.299 [ERROR] [me.automation.jsr223.jython.triggers] - when: Exception [when: "Item Door_Openstatus1 received command OPEN" could not be parsed because "OPEN" is not a valid command for "Door_Openstatus1"]: [Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/core/triggers.py", line 309, in when
raise ValueError("when: \"{}\" could not be parsed because \"{}\" is not a valid command for \"{}\"".format(target, new_state, trigger_target))
ValueError: when: "Item Door_Openstatus1 received command OPEN" could not be parsed because "OPEN" is not a valid command for "Door_Openstatus1"
]
Am I missing something here?
Of course, I could just use the Door_lastopened1 item, but I want to use the full functionalites of the core features!
Thanks alot in advantage
Hello!
I have been scratching my head on this one... how does one get started? Just a simple step-by-step guide would be great! I am already running latest snapshot OH build, I just need to know how to get this one integrated.
Has anyone used a threading.Timer
successfully with OH 2.5.0-1512 and Jython 2.7.0?
I am not having any luck getting a thread or timer to outlive the execution of the rule starting it.
Here is the most basic test I have tried that does not work:
from threading import Timer
testtimer = None
@rule("test_timer", "test timer")
@when("Time cron 0 * * * * ?")
def rule_testtimer(event):
logging.getLogger(LOG_MODULE+".test").error("STARTING TEST TIMER")
global testtimer
testtimer = Timer(2000, lambda: logging.getLogger(LOG_PREFIX+".test").error("TEST TIMER FIRED"))
testtimer.start()
Which gives me this in the logs:
15:01:00.045 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - 797795b9-4d7f-4645-ad93-31b982e66eec updated: RUNNING
15:01:00.066 [ERROR] [ome.automation.jsr223.jython.test] - STARTING TEST TIMER
15:01:00.068 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '797795b9-4d7f-4645-ad93-31b982e66eec' is executed.
15:01:00.069 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - 797795b9-4d7f-4645-ad93-31b982e66eec updated: IDLE
and the timer never fires.
I was initially trying to spawn a child thread to do a longer fade on some dimmable lights I have, which would run most of the way through its loop the first time but die when the rule thread exited. I then tried doing the same with a timer, but its code never ran because the delay was longer than it took for the rule thread to exit. My best guess at this point is that an child threads are being GCed when the main thread finishes, but from your examples on timers it would seem this shouldn't happen.
Any suggestions or anyone else having this issue?
I have not tried java timers via direct imports or using the OH Action because I won't be able to call a instanced class method from them
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.