Hi,
I want to use a small Python script as rule condition. Unfortunately it’s not clear for me how I can control that it evaluates to true or not. Can I just return an exit code using the exit() function?
Thank you.
Hi,
I want to use a small Python script as rule condition. Unfortunately it’s not clear for me how I can control that it evaluates to true or not. Can I just return an exit code using the exit() function?
Thank you.
In the python readme.md in the last “Simple rule” example, you can see how conditions are used. One time it is just a state condition and the other time it is a script based condition. As you can see there is no return or exit code. Just the condition like Registry.getItem('Item2').getState() = scope.ON
Thank you, but with simple equality sign this statement would be an assignment, not an equality check. But as the full line is `ItemScriptCondition(“Registry.getItem(‘Item2’).getState() = scope.ON”)` it might work. But the example isn’t a simple inline script I was referring to.
thanks for the hint, I just copied from my readme
and there was a typo. It is fixed in this commit
maybe you mean something like this
from openhab import rule
from openhab.triggers import ItemScriptCondition, GenericCronTrigger
@rule(
triggers = [
GenericCronTrigger("*/5 * * * * ?"),
],
conditions = [
ItemScriptCondition("""
def check():
return True
check()
""")
]
)
class Test():
def execute(self, module, input):
print("Test")
or
from openhab import rule
from openhab.triggers import ItemScriptCondition, GenericCronTrigger
@rule(
triggers = [
GenericCronTrigger("*/5 * * * * ?"),
],
conditions = [
ItemScriptCondition("""
from custom import check
check()
""")
]
)
class Test():
def execute(self, module, input):
print("Test")