Using the python dir() function I was able to figure it out:
First tipp: Placing the code outside the execute() function while testing gives much more informative error messages (this code is executed when the file is loaded).
One Problem was, that âItemRegistryâ is not defined, I had to use just âirâ
Sometimes the following seems to work too, sometimes it fails. I have not figured out why it i
events.postUpdate(Washing_Machine_State, newState)
events.sendCommand(LED_Halle_Flur_Betrieb, OFF)
I have a similar error trying to access the state of an item.
According to the documentation, we can use the following methods:
items["My_Item"]
# or after importing anything within the ``core`` package
items.My_Item
# or
ir.getItem("My_Item").state
This is a simplified version of my code:
from core.rules import rule
from core.triggers import when
@rule("(Py) LivingRoom MotionSensor changed")
@when("Item LivingRoom_Motion received update ON")
def livingroom_motion(event):
livingroom_motion.log.info(items["LivingRoom_AmbientLight"]) // Works
livingroom_motion.log.info(items.LivingRoom_AmbientLight) // Error :frowning:
However, if try to use the second method I get this error
20:20:53.453 [ERROR] [.(Py) LivingRoom MotionSensor changed] - Traceback (most recent call last):
File â/opt/openhab2/conf/automation/lib/python/core/log.pyâ, line 51, in wrapper
return fn(*args, **kwargs)
File ââ, line 13, in livingroom_motion
AttributeError: âorg.openhab.core.automation.module.script.internalâ object has no attribute âLivingRoom_AmbientLightâ
20:20:53.453 [ERROR] [re.automation.internal.RuleEngineImpl] - Failed to execute rule â0bdd9b15-2ea8-42c3-9bc8-ddf9e04adf7aâ: Fail to execute action: 1
20:20:53.453 [DEBUG] [re.automation.internal.RuleEngineImpl] -
java.lang.RuntimeException: Fail to execute action: 1
at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1199) ~[213:org.openhab.core.automation:2.5.0.201907050304]
at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:995) [213:org.openhab.core.automation:2.5.0.201907050304]
at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:91) [213:org.openhab.core.automation:2.5.0.201907050304]
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 core.rules$py.execute$4(/opt/openhab2/conf/automation/lib/python/core/rules.py:52) ~[?:?]
at core.rules$py.call_function(/opt/openhab2/conf/automation/lib/python/core/rules.py) ~[?:?]
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.core.rules$_FunctionRule$16.execute(Unknown Source) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate.execute(SimpleRuleActionHandlerDelegate.java:34) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.internal.delegates.SimpleActionHandlerDelegate.execute(SimpleActionHandlerDelegate.java:60) ~[?:?]
at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1191) ~[?:?]
⊠7 more
Does anyone know if an extra thing is needing to use this second alternative?