Check/Correct Contact Sensors

Trying to write a rule a check door & window contact sensors and report status (Either "all closed" or identify which are open). The rule is triggered thru Alexa by a virtual lock.

2 things that I'm struggling with:
*For some reason, when a contact sensor is left open, I'm not getting a message telling me so.

*I would like to add a wait command if any are found open, (to pause the rule until the door(s) or window(s) are closed). ...then once the contact sensors are all closed, report "All closed" and proceed with the rule.

I've been mining for answers thru the documentation and this forum and I can't seem to get it.
Could someone please help...

2 Likes

Unfortunately, you can't speak which contacts aren't closed using %device%.

I also think you might need 2 rules:
Rule 1 checks the contacts and reports any ope and if they are enables rule 2
Rule 2 watches your contacts and speaks when all are closed after being enabled.

Rule 1:
trigger:
Whatever you want to trigger off of

2 variables:
OpenContacts string
Open contactscount number

Action


Set private boolean rule 2 to true

Rule 2:

Thanks for taking the time...
Though easier said than done... I never used variables or private boolean.

Do I set a local variable (string) for each contact sensor like this?

...or

I think @Cobra may be bringing his apps back to HE soon, and he wrote and app called Message Central that can do what you want.

Count to 0
OpenContacts to blank

The code then adds/concatenates when an open contact is found.

Okay... THANKS! I'll pursue.

This can be done using an HSM custom rule, like this:

I pretty much replicated the example provided. I tested it with a door open and it identified it. I then closed the door and it reported everything as closed.

However, when ran again, it seems to be caught in a loop, still announcing the back door is open, when in fact, it is closed.

Rule Test-1 and a snapshot of the included variable:

Rule Test-2:

...and the loop grows. Now it repeats itself 5 times. I guess it adding to the variable.

I just wanted to have a "Good Night" rule that would check everything before setting the HSM. That way, I could easily correct any open contacts. It seems when catching an open contact in HSM, I have to cancel HSM, correct the contact, them arm again. A little bit of a pain that I was hoping to avoid.

Napalmcsr provided a great example that seems perfect for me. However, I probably just don't have something configured right with the variables or private boolean.

Can you show the trigger for the checking rule

Also rule 1 needs to run on the private Boolean for rule 2

And in rule 1 you need to set open contact count to 0 And open contacts to “”

Trigger for Rule 1

When I set the PB for Rule 2. it asked what rules it applied to. I selected rule 2 (the one that the PB was created in).

The Open "Contactcount" was set to "0" initially but changed to "1" when caught in the loop.
...and the "OpenContacts" string filed was left blank initially. It too changes when it is ran.

It seems like the both variables should be reset to their original value ("0" and empty). along with the PB. It's value has changed too.

I reset the variables in Rule 1 and will try to figure out how to reset the PB in Rule 2. It seems to be stuck in "False" and I guess should be "True" ??

Redoing the PB now... Should I set the PB false for both Rule 1 and Rule 2?

For rule 2 the PB needs to be set to false

then in rule 1 at the end add an action Set PB on Rule 2 to true

in Rule 1 the PB is not used

Once again- Thank you for taking the time. I have to call "UNCLE"... After spending hours, I just can't make it work. I'm sure its my lack of understanding.

However, I did come up with a work around that works for me. I'll merge it into my "Good Night" routine and it will help flag open contacts before shutting down the house and arming HSM.

no problem, if you care to try again just flag me down... Or wait for Cobra's app.