Need a little help with creating a rule

I've defined a global boolean variable named HomeIsSecure. I have 8 contact sensors and a z-wave door lock. I want the variable to be set to false when any of the 8 contact sensors reads "open" or when the z-wave door lock reads "unlocked". I want to set the variable to true only when all 8 contact sensors read "closed" AND the z-wave door lock reads "locked". I figure I would do this with two rules. The first rule, where it sets the variable to false is easy since it fires when ANY trigger event occurs. It's the second rule that's tripping me up. I'm fairly sure the trigger will be almost the same but I need to set it conditionally and I'm having trouble understanding the nuances of the conditions. Can anyone help?

A screenshot of what you have setup so far may help, but in the meantime... What if you had one rule that triggered on a change in any of the devices involved, then in the actions have a conditional action that assesses the state of everything and sets the variable accordingly?

Screenshots below. Tell me if it looks right to you.

Here's my rule to set insecure:


And here's my rule (and conditions) to set secure:

What you showed in the screenshots is ok, but I think where you will get tripped up is trying to include the state in your triggers when you want a number of things to be true, particularly given you can't have AND in your triggers... But that's another topic entirely...

What I was suggesting earlier was to change your triggers fire on a change in the state of any of your sensors or lock. Then inside the actions check the state of all these devices. Bit hard to demonstrate this on my phone... Does that make sense?

you may want to look into this app

not written by me, but ported by me from st

That's not half bad. Unfortunately it doesn't seem to have the ability to set a variable nor does it have triggers other than time intervals. It's got a lot of promise though. I think I'm going to start learning how to write my own apps.

The rule below is one I use that only initially only included contact sensors...it works very well. Light comes on between 9:00 PM and 2:00 AM if any of they contact sensors are open. Turns off when they are closed.

I was working on updating it this AM to include the front-door lock...kind of butchered the rule (still learning the intracacies of editing existing rules, which I find very confusing, unfortunately. This may need some adjustments to work, but I think the logic is OK...though I'm sure someone more knowledgeable on RM will revise my opinion on that. :slight_smile: I didn't get the "AND Time between ..." part right in the actions section.

This rule won't work as might be expecting it to: the "Actions to Run" will run when any trigger matches, which would be just any single sensor closing or the lock locking. I see you have "all closed" under "Manager or Create Conditions," but conditions alone do not do anything: that's just a bank, and you have to use them somewhere for them to have any effect.

I think what you want would happen if you changed your actions:

IF (Left front window, Right front window .... all closed AND Front Door Lock locked) THEN
  Set HomeIsSecure to true
END-IF

I believe this is what sburke781 was suggesting above. You could also do this in a single rule if you wanted:

Trigger events:

Left front window, Right front window,  ... any *changed*
OR
Front Door Lock *changed*

Actions to Run:

IF (Left front window, Right front window, ... all closed AND Front door lock locked) THEN
  Set HomeIsSecure to true
ELSE
  Set HomeIsSecure to false
END-IF

I do not normally advocate cramming a bunch of things into a single rule just because it looks better or you happen to "prefer" it, but this is one of those cases where I think it's easy enough and makes sense. Two rules, of course, will still work if you prefer that option.

1 Like

Exactly what I had in mind, thanks for posting it in more (and clearer) detail @bertabcd1234

OK, it seems you've written the script out by hand. I'm a programmer by profession so I'm very familiar with doing this sort of thing. How do I access this sort of functionality in the Hubitat interface?

You don't--that was just me typing out what RM would show you. :slight_smile: It must be input by way of the UI. (The alternative is writing your own app, which is indeed code, but that is a much bigger undertaking, though not too difficult after you understand the lifecycle of a Hubitat app and what its runtime environment adds on top of standard Groovy.)