Need help creating my first complex rule

The sequence of events is read bottom to top in the logs. You are wanting multiple conditions to be true but just checking to trigger the rule if one thing is true. Set the trigger to changed and the conditional check to be motion active and boolean a condition.

I know. The rule triggers 1:04:22.776 and changes the PB to false a fraction of a second later. The rule triggered again at 1:05:07.358, and checked the value of the PB, which was somehow True even though it had been set to false about a minute before.

But regardless, at this point I don't think using a PB will help anyway with what I want.

Think of the Boolean as only a true false variable because that's all it really is. Use the value of the boolean as a condition for your rule in combination with another trigger such as your motion sensor.

image

I used and not and reversed the logic to cover for conditions that the boolean is not initialized.

FWIW, Private Boolean should always be "initialized," and RM makes you set a default value for any global or local variable too. The default value of PB is true (this may be surprising, but it makes sense with a brief history lesson: PB was originally a very naive "restriction" on a rule where you could make it not run if false, so you wanted it to be true if you didn't ever use it or care about its existence--before the days of conditionals, action ordering, and other things you now find in Rule 4.0).

Back to @waterboysh's rule: how are you setting Private Boolean? Your action wording looks different than I'd expect, which would be something like this if you do Set Private Boolean, Run/Pause/Cancel Rules > Set Private Boolean True and choose This Rule:
image
I don't know off the top of my head what action might get you "Rule Bololean True:", but could the problem be that you aren't actually setting it?

Possibly not selecting "This Rule" checkbox when specifying the boolean.

This is exactly how I did it.

I'm definitely selecting "this rule"

EDIT: I know I selected "this rule" but for whatever reason when I went to edit the action, it wasn't selected, so I re-selected it and now it shows like in @bertabcd1234's screenshot. Will test the rule in a little bit.

1 Like

Your rule looks different from the screenshot I posted. Yours says Rule Boolean False: and mine shows Set Private Boolean and I think this is from using a conditional action instead of set private boolean.

Select action to run
Select action to add
Set Private Boolean, Run/Cancel/Pause Rules
Select which action
Set Private Booleans True or False
Set Private Booleans True or False for these rules
This Rule

The only other issue I see is the wait for no motion in his bedroom. If he's fast like my little midgets of doom he may beat your rule to the bathroom depending on distance and motion sensor timeout.

All right. Fixed the issue with setting the PB.

However, checking it as a condition does not stop the first instance of the rule from halting and a new instance starting. I color coded it here. Yellow is the first instance. Green is the second instance. The yellow never gets to finish because when the trigger happens (motion in the bedroom) it kills the existing instance of the rule and starts a new instance. The private boolean doesn't affect that at all.

Correct the boolean is only a variable set the trigger to change and put motion active as the conditional along with the boolean to start the rule. Rule skips if its set to other. Booleans dont stop additional rules from running which is why you need to include it as a conditional check to start the action. You can't use it in the trigger because it doesn't allow This and this... Just This or this.

image

Can we re-visit @lewis.heidrick idea of 2 separate triggers? I think 2 simple rules > 1 convoluted rule. I was going down the pathway of Cancel Waits and it was just not cooperating.

Bedroom Rule

  • Motion triggers the lights on, cancels any potential impending lights-off actions, and enables the Bathroom Rule's PB.
  • Wait for end of motion event at which point 30 second timers will queue up Lights Off and disabling Bathroom PB so you dont trigger it later yourself.

Bathroom Rule

  • Only triggers if the Bedroom rule enabled it by PB.
  • Cancels any lights-off queued up by the Bedroom rule.
  • You dont even need the ELSE branch after you nix the logging.

1 Like

I want to try this, but I'm not sure how to initialize the PB for rule 2b. When I create the conditional check, the value seems to default to what I check for.

It initially defaulted to true when I created the rule like you show, so I assumed the PB will initialize to true.

image

So I thought I just need to reverse the PB logic you have (set 2b to false at the beginning of 2a) so I changed it to check to false and it changed the current value of the PB to False to match.

image

If possible, it's easiest to write your rules to assume PB starts as true (since it does indeed). However, if you're already structured the rule such that an initial value of "False" is necessary, the easiest way to do that might be to create a "temporary" rule consisting of just one action: Set Private Boolean False on the other rule. No trigger needed. Click "Done" to save the rule after making it, then go back into this rule and click "Run Actions" (won't appear until you've saved it the first time via "Done") to run your actions, which will set PB to false on that other rule. Delete this rule if you want, or even keep it around if you think you'll need it to "reset" things again in the future.

What I'm saying is that this wasn't the case for me. The screenshots I posted are from me creating the rule. You know how in a conditional statement, it shows you the current value of what it's checking? If I change it to check for false, the current value changes to false. If I set it to check for True, the current value changes to True.

Hmm, not sure what to say about that. It sounds like you might have another rule that interacts with this one. Is it possible that it set PB on this rule while you were editing it?

You can manually (without needing to create a conditional just to do this) check the value of the rule's PB from the "App Status" (gear/cogs icon page for that app/child app). Under "Application State", look for the variable called private. Here's mine in a brand new rule:

image

Triggering 2a sets 2b True on motion and False after 30 seconds no motion. Are the timers just triggering while you edit the rule?

The rule will continue to "run" (or more precisely since Hubitat apps aren't really "running" all the time: "will continue to execute previously scheduled jobs and wake up in response to event subscriptions") while editing, so if those were already in place, then yes. In possibly related news, clicking "Done" (or "Update Rule," which basically does the same without exiting the app) will erase any existing scheduled jobs (which in RM terms would usually be a pending wait or delayed action, cancelable or not); simply exiting the rule (which is actually OK--your edited actions are saved after editing them) will not. Maybe some combination of that could explain everything?

Yeah, I don't know what was going on with the PB switching on me like that. Anyway, setting it up as 2 rules seems to work better. It's working. I don't know if I would consider that more simple or not.

Thanks everyone for the help and suggestions.

2 Likes

I usually consider two simpler rules better than one complex rule, but to some extent, it's a matter of opinion. (What's not an opinion is that a single rule with a bunch of mostly unrelated triggers is a bad idea as, rarely, truly concurrent execution can happen and cause problems.)

In the old days, as a response to someone's hesitance to create more than one rule to solve a problem, people used to say, "Rules are free." In the present day, multiple rules are necessary less often; what you now see in Rule 4.0, where the actions are basically an ordered script where you can create (and nest) conditionals to create arbitrary complex rules, was not always there. But I still think it's a good idea sometimes. :slight_smile:

2 Likes