How to set contact state from the contact sensor which detected a vibration


This is my first post, so apologies if it’s a basic question! I’ve coded a simple rule which reports if a vibration is detected on a window/door. It uses a list of all such devices in my home and saves the name of the device so I can use it later for reporting.

However, I’d also like to record the state of the contact sensor so I can only issue a notification if the window/door stays closed (attempted breakin) rather than opens within say 2s (genuine entry). This is where I’m stuck.

I assume that I need to type in the relevant code here but am not sure how I query the contact state, considering it didn’t trigger the vibration event:

I couldn’t find what I wanted via the list of variables.



I don’t have a vibration sensor, so this is off the top of my head. Does your sensor expose vibration with the “stays” parameter.? I’m thinking you may not need a variable. Trigger the rule on vibration stays for 2 seconds then in the flow, do an IF the window is not open. The concept is that you only want the rule to trigger if you get 2 seconds of vibration. If you do, then you want to test to see if the window is open or closed to discern tampering as opposed to the window being opened.

Thanks Bry. It’s a good suggestion but assumes that there would be sustained vibration for 2s. I want to trigger on a quick knock but only if I don’t then open the door/window. By default, each time I open the window, my open rule is triggered correctly and I’m notified, but I also get a notification of a knock detected. This means that if a thief tries to force a window briefly without success, I’ll still get early warning.

I think it’s just a matter of approach. You want to trigger each time, but then filter regarding notification using an IF in the Flow, based on the totality of the circumstances. Just because a rule triggers does not mean you must be notified.

So maybe, trigger on any vibration. Then in the Flow, Waiit x seconds (to see if you open the window), then IF window is not open THEN notify ELSE do nothing.

Sorry, I wasn’t being very clear but what you’re describing is exactly what I want to do. However, the part I’m stuck on is being able to detect if the window is open. If I was to write one rule per window then it would be easy as I could select the said window, look for the contact sensor state, etc. However, when using this method for multiple sensors I just get presented with a list and have to select one sensor. I want to automatically select the same sensor from that list that triggered the event and I couldn’t see how to do that. Hence I wanted to use the designName var that I’d set to query the contact status of that sensor:

So in effect, where “Select Device” presented a list and I selected my office window for this purpose, what I want to do is say: <select window/door which triggered the vibration>.

This brings me full circle to my original post where I was trying to set the contactStatus var of the device which triggered the vibration for later use, but I couldn’t do that as I don’t know the syntax or where to find it.

That makes sense. So back to variables, context variables, actually.

Take a look at this post where @josh describes their use.

There’s not currently a way to dynamically select a source device based on a variable or other dynamic information.

The closest feature requests are probably the following if you want to cast a vote:

I was originally thinking you could query the SmartThings API directly using an HTTP Action and the triggering device ID to get the state of a different attribute from the triggering device, but it looks like we don’t currently expose the device ID in the event context. If that’s a workaround you think you would be interested in, I would be happy to expose that additional property.

Hi Josh,

I will have to look into using that http method but it sounds like a good workaround. Hence please go ahead and expose that additional property if you have time.