[SOLVED] Put rule code into method and call it in different rules

Rules DSL doesn’t work like that. Your two best options are A simple scene management: finally a good use of scripts or Design Pattern: Separation of Behaviors.

There is also Reusable Functions: A simple lambda example with copious notes but the lambda can only be called from the same .rules file and it is not thread safe.

Depending on the nature of the Rule, you might be able to centralize all your Dimmers or whatever into one single Rule. See Design Pattern: Associated Items.

Finally, you can write your Rules in Python to begin with. See https://openhab-scripters.github.io/openhab-helper-libraries/index.html.

1 Like