Predicate as trigger

Hello
I have some rules with predicate. This rules have also different triggers, But I want also as soon as my predicate evaluation is true to trigger the rule actions. I try today to add as trigger the value for predicate, but it seems that trigger is faster than changing the predicate evaluation for the
rule.

Is anyway to make predicate also a trigger?
Is anyway to delay the triggering until the evaluation of predicate has done for a rule?

Thanks
(I know other solutions ..., I only want to know if above is possible)

Maybe my caveman understanding here isn't correct, but it helps me to think of a predicate being a sleep / wake gate for the rule... If my predicate is true, then my rule is awake/"live" and it'll run when its trigger condition is met. If my predicate is false, then then my rule is asleep/dormant and it'll ignore the trigger condition even when its met.

Rules do not need to have a predicate condition, but they do always need a trigger.

ETA - since predicates rolled out a while back, I've been using them more & more... I'd say ~2/3 of my rules now use a predicate, but they aren't ever a requirement. There's always more than one way to skin a cat!

2 Likes

You could have the same conditions be a trigger, but that won't get you what you want. The Predicate's evaluation must have yielded true before the rule is triggered for the rule to even be triggered in the first place. So if the same condition is in both, and the Predicate was false, it won't be true until after the event that would trigger it has happened. It will not have been true so it will not have triggered. Then it would become true, and a subsequent event might trigger it.

If this is the circumstance you are dealing with, you'd have to make the conditions used for the Predicate into a Conditional Action in the rule instead. The rule would be triggered irrespective, then the conditions tested, etc.

1 Like

Yes this is my understanding also, but when come's the moment of predicate becoming true :slight_smile:
t1 - predicate changing
t2 - predicate change try to trigger rule but predicate still false
t3 - rule triggable

can t3 make a switch with t2 :slight_smile:

oh I was too fast I was answer to previous comment :frowning:

No. You have to also consider the opposite side of the coin, where an event triggers a rule (with Predicate true before the event) and the event itself causes the Predicate to become false. That complexity had to be sorted out one way or the other.

So the way it works is the Predicate must already be true at the moment of the possible trigger event (which is why it is called a Predicate). In short, the Predicate conditions are tested after the trigger either happens or not.

Thanks

I hate to nitpick here on a technical point having nothing to do with the thread's topic, but this is actually not the case.

I have several rules that are "subroutines" to other rules which call them. They have no triggers defined. Why would I do this? Rules can get corrupted on rare occasions and have to be deleted and recreated. I sometimes break up lengthy rules into subrules just to minimize how much I'd have to recreate if a rule got corrupted.

6 Likes

Good point!

1 Like

That was a question I had. I wanted a rule which was just a predicate and an action, but was wondering whether a trigger was necessary. Something like: "If A & B & C is TRUE, do X". Sounds like that does work.

Hubitat is an event driven system.

1 Like

I haven't done much with predicate conditions, but I don't think that would work. You still need an event, not a state of being, to trigger the rule evaluation. In my comment above, "calling" the rule from another rule is such an event.

1 Like

It will work if you triggers your rule from other rules :slight_smile:
I have a hub variable for heating on or off. Is good as predicate because it will change only few times per year. I have a bunch of rules for thermostats with it as predicate - do not want them to run when heating is off
None of them has any trigger because I have one rule polling each 3 minutes which will call a lot of outer rules
My initial question was related to this example because I wanted the rules to be triggered also when my heating variables is changing.
That was not possible so I made a rule trigger by my variable where I wait first a second and than I call the other rules

Exactly what I said (twice).

Just talk in circles :innocent:

Thanks. OK, so I need three rules instead of one.

If A & B is TRUE, If C, then do X.
If A & C is TRUE, If B, then do X.
If B & C is TRUE, If A, then do X.

you can also have a trigger like A or B or C was changed and the in action do your ifs
you can even add a variable to rule initilaly false

If A & B is TRUE, If C, then do variable = true
If A & C is TRUE, If B, then do variable = true.
If B & C is TRUE, If A, then do variable = true

and than if variable = true do x