[request] Statefull triggers

It would be really nice to have trigger conditions that remember the previous state of the trigger value, and can trigger a rule when a threshold is crossed.

For example, I currently have rules to open and close my blinds when the illuminance reading on a sensor goes above or below a given threshold:

Currently, the only trigger that works is to trigger the rule every time the illuminance reading changes. Since the sensor reports every 5 minutes, this means that the rule runs every 5 minutes. To get the behavior I want I have to keep track of the previous illuminance value in a variable.

It would be very convenient if I could define triggers like "Illuminance of Upstairs Window Multisensor rises above 400" and "Illuminance of Upstairs Window Multisensor drops below 400" so I don't have to keep track of the previous reading explicitly within the rule logic.

Maybe I'm not understanding you. Why can't you use those as triggers?

12%20PM

When you press Done, this is what the trigger looks like. Isn't this what you want?

17%20PM

As far as I can tell, "becomes" is just bad wording on those triggers. It's really "is". The rule will trigger each time the sensor reports a value as long as that value is greater than the target. That's not what I want. I want it to trigger once, when the value transitions from less than the target to greater, and not trigger again until the value drops back below the target.

The Illuminance device IS sending a report. Every 5 mins. Hiding the compare doesn't change the work the hub has to do. You do it in the Rule or the Hub does it 'under the covers' -- I don't see what is gained by burying the event handing.

1 Like

You can use a Private Boolean in the rule to ensure it fires only once when Illuminance > 400

Trigger Rule 1:

Illuminance > 400

Actions Rule 1:

IF Private Boolean False: Exit Rule
IF (Illuminance > 400) THEN
    Set Private Boolean False
    Do Stuff
END-IF

Trigger Rule 2:

Illuminance < 400

Actions Rule 2:

Set Private Boolean True for Rule 1

@csteele It doesn't change the work the hub has to do. I picked a simple example, but I have rules where hiding the state in the trigger would make them much easier to read and reason about.

@aaiyar That's fairly similar to the private variable approach I'm using. The early-return is a bit nicer than the if conditions I have though.

Except it doesn't need to keep track of the previous illuminance using a variable. So even though it is broken into two rules, it should be faster.

1 Like