I’m attempting to use a function in a Python Rule. The logging and sendCommand work as expected without any functions. However, when I introduce a function (below), the Main function doesn’t seem to get executed. I’m wondering if it’s because there isn’t a trigger defined in the code? (the trigger for this rule is defined in the UI) I am using OH 5.0.3.
Any suggestions are much appreciated. -Mike
from openhab import rule
from openhab import logger
# -------------------------------------------------------
# close window function
# -------------------------------------------------------
def close_window():
logger.info("Close Window function…")
item = Registry.getItem("openwindow")
item.sendCommand("OFF")
# -------------------------------------------------------
# Main
# -------------------------------------------------------
@rule("Open/Close Window Rule")
def main(event):
logger.info("Main function …")
close_window()
In your case it is a UI defined rule. This means you must only specify the code to execute, when a trigger fires an event. like below. You can also see here that there are no extra imports for Registry, scope and logger. They are automatically imported for UI based rules.