Trigger based on changing away from a mode

Is there any way to write a trigger in Rule Machine that triggers when mode switches away from a certain mode? I don't see anything that allows this. I want to trigger actions when mode changes from Away to anything else. I could do this easily in Webcore, but I don't see any way to do this in Rule Machine.

Like this? Mine might not be the best example, because I have custom modes, but it should be similar for you.

Select capability for new Trigger Event, and I picked "Mode"

Forgot to add, you could just use "Changed" for the mode trigger, and in the rules do a conditional.

There is now! :smiley: Rule 5.0 introduced predicate conditions, which would work perfectly for your example. Let's say you want a set of rule actions to run when the mode switches from Mode X to Mode Y. In that case, you would set the rule up like this:

Trigger: Mode becomes Y (or you could select all modes besides the one below, which sounds like it might be what you really want)

Predicate Conditions: Mode is X

Actions to Run: (whatever you want)

Predicate conditions are conditions that must be true in order for the rule to trigger. The most clear use case for them is to capture specific state transitions, so it should line up well with your goal. If you're on old hub firmware or still want to do it this way for some reason, you can do this in Rule 4.x, too, but it takes a bit more work: a trigger on mode change, a local string variable to store the new mode, another to store the previous mode, a comparison (conditional) between the two, then storing the now-current mode for use with this comparison next time.


Great suggestions. These will do nicely!

GAAAH, why didn't I think of that. I still am not used to Rule 5 yet, or at least this feature.

Great suggestion, this is probably a textbook case for predicates.

1 Like

Download the Hubitat app