PaperUI Rules vs HABmin

Hi All,

I am loving some of the features of OpenHab2, but one issue I am struggling is with Rules.

So at first, I wanted to make rules, but PaperUI’s system seems limited.
I could not figure out how to control OR and AND, and neither how to check for time ranges.

On the other hand, habmin, has this complex power with a UI, but rules defined in paper UI do not show up in Habmin.

Can both rules co-exist?
Is it better to use just one of the systems?

Thanks.

PaperUI and habmin are interfaces to configure things and items, and while some functionality may exist in there, neither of them is recommended or meant to be used to create/maintain rules.
You can use any text editor (create files /etc/openhab2/rules/XXX.rules) if you know what you’re doing, but the recommended way is to use the VS Code Extension to create rules. [Before openHAB 2.2, the recommended tool was the ESH Designer. It is still available, too.]

Just to elaborate, there is an Experimental Rules Engine that you can use in PaperUI to create Rules. But it is named “Experimental” for a reason, it is a work in progress and there is little documentation available. You can try to use it but there will not be much help available to you if you do.

HABmin is also a work in progress and I don’t think the Rules development part is fully working right now.

However, in the Experimental Rules:

  • The “When…” section lets you list the events when the rule should trigger. These are all OR meaning if any one of these events occurs, the Rule may trigger.

  • Because the “when” clause is based on events, it doesn’t make sense to define time ranges here.

  • The “but only if…” clause lets you list the conditions under which the Rule should execute. Each condition is an AND, meaning all of the conditions must evaluate to true for the Rule to execute. Like I said before, the engine is not complete so there doesn’t appear to be an easy to use way to test for time ranges here. You will have to implement that test in JavaScript using the “a given script evaluates to true”.

Shame, some simple trials shows it works well.

Currently I want to turn-on the house lights when my mobile device is online AND it happens to be between a certain time-range.

So it would be good if I could evaluate the time expression when the mobile-device-online-status state changes.
Any suggestions on how to implement that?

Thanks guys!

Using the experimental Rules Engine then:

When Item state changes to ON

only if Script returns true and implement a test if the current time is between your two times (I don’t do much JavaScript so can’t help much with that)

Then choose the appropriate behavior and/or implement the body of your rule in a JavaScript.

If using the Rules DSL, start by looking at some examples on the forum (there is a whole category). In particular look at [Deprecated] Design Pattern: Time Of Day which will show you how to keep track of times of day in a centralized manner for use in your other rules.

Then your rule would look something like:

rule "turn on house lights"
when
    Item MobileOnline changed to ON
then
    if(TimeOfDay.satate.toString == "EVENING") {
        // turn on the lights code goes here
    }
end

If you’re feeling adventurous you can try out Flows Builder - a visual designer for the new rules engine.
Shamelessly plugging my stuff here, but it was supposed to help with these kinds of use cases.

:warning: That being said I would also recommend sticking to the proven, battle-tested DSL rule engines for now though. There are some unresolved issues with the new engine.

Anyways, that’s how you could do it:

  • With an intermediate item (could be a Switch or a String), and “when it is a fixed time of day” triggers. No coding required in this case

Perhaps not exactly what you wanted, but you get the idea. Note that you could also make the rules directly in Paper UI too, but they might be easier to maintain together in Flows Builder.

  • With a “if a given script evaluates to true” and some Javascript as @rlkoshak suggested:

image

You have to keep in mind you can’t use “return” statements in the condition’s script, instead the script’s “return value” is the evaluation of the last statement.

Here the Flows Builder can help you because editing scripts is far easier than with Paper UI with autocompletion for basic Javascript types including Date (its most useful feature IMO), so that’s how you would code your script:

Good luck! :slight_smile: