Rule Machine: IF mode changed from A to B?

I didn't say it wouldn't work...I said I don't think it will work.

And try and be a little ruder next time. Jeez.

Why do you have the second Cancel wait?
image
That one....
You can only have one wait schedule per rule, so the 2nd is automatically canceled. Also, you can't change from mode Day to Mode Day. That wouldn't be an event so I don't believe that is actually needed.

Also, since Mode has changed, I saw a second instance of the rule running. When I added a delay in, I got a pop error.

So, I would use this method with caution and make sure it's a very short rule.

I prefer to be explicit.

No, but if you would use additional pairs of transitions this is explicit and clear.

As I mentioned from the beginning, these types of rules require extra care, make sure to not end up operating on the same data at the same time. If the rule is structured as I did, I would consider any pop errors RM bugs that would need fixing or additional work around.

I suggested this method as an alternative to virtual devices and global variables. The reason I brought it up is because it is a seldom discussed type of method and it lends itself to relatively "clean" rules.

2 Likes

Because of the pifalls you can run into, like the one that I saw. I am merely pointing that out as a possible side effect. That way, no one who reads this can say they weren't warned about what to look out for.

1 Like

There’s so much out of context chatter going on here that I can’t tell if anyone helped you.

Just in case, here is a screenshot of me attempting something similar.

2 Likes

But that will fire whenever the mode changes from A to B,C or D....not just A to B.

Rule 1
If mode change to A turn on virtual switch
Else, wait 5sec turn off virtual switch

Rule 2
If mode change to B and virtual is on
Do your stuff

??
The 5 seconds gives rule 2 time to run, then reset the virtual switch

1 Like

mark.cockcroft suggestion in one rule

Trigger:
    Mode becomes *changed*

Action:
IF (Mode=A) On VirtualSwitch
IF (Mode=B AND VirtualSwitch=ON) THEN
    Do stuff
END-IF
IF (NOT Mode=A) Off VirtualSwitch
2 Likes

Else if mode B?
And a end if at the end?

Everyone's a critic :laughing:

First and last IFs are simple conditions, no END-IF used.
Could use ELSE-IF for the first two conditional actions.

So true! :stuck_out_tongue_winking_eye:

That won't work because the virtual will also be on if the mode changes to C then B.

Yea if the mode changes within 5 seconds
A c b in under 5 you got me

I don't understand. If Mode IS A your turn on the virtual switch. Then if mode switches to C. Then if mode switches to B, the switch is still on so the rule will be triggered. Unless you write another rule to turn the virtual switch off if mode is not A and Not B. So, now you're up to 3 rules.

Or you could just write one rule to populate 2 variables, current_mode and previous_mode. :slight_smile:

Trigger:  Mode changes.

Action:
Set variable previousMode = currentMode
IF Mode is A THEN
     Set currentMode to A
ELSE IF Mode is B THEN
    Set currentMode to B
ELSE IF Mode is C THEN
    Set currentMode to C

etc. etc.  

Then you have two global variables of currentMode and previousMode to use in as many rules as you want.

Virtual switch will turn off as per the else under it

Anyway @pseudonym improved my version

Life has a way of happening. @bcopeland pegged the concept. I've not claim the expertness, but add this for your consideration.

  1. I wouldn't necessarily need to check A->B always, so a bool seems appropriate while keeping an eye to what last mode happened should I decide to begin checking again.

  2. I would expect times where other events/modes could happen that I don't particularly care about influencing the net A->B, i.e., include a means to overlook certain modes.

  3. Included a means to change horses. A->B rode hard, could allow riding C->D into the sunset without whet rewrite or adding new and more rule hurdles to clear.

Ideally, a couple pictures may better my rambling words...

The "evil deed" globals...

My kingdom for a horse (sans wait for a vogue KISS).

Tip of my hat to @Cobra 's Super tiles for proof of concept.

Edit: And oops. The RM snapshot doesn't show flipping a nested virtual switch ON following Set GDoThis. That would be one means of subsequent RM trigger to process the recorded A->B...

1 Like

I have absolutely no idea what this is all about. But I very much enjoyed reading it (Dirty Underwear, Loo, etc.) lol :grin: :smiley: :laughing:

2 Likes

Just noting, since I happened across this thread, the new Required Expression in the updated Rule Machine makes it easy to trigger on an A->B transition.