Delay for Intrusion Alert in SHM - Success!

I had to bang my head against this for a while, but I successfully applied a 20-second delay before Smart Home Monitor will issue an intruder alert. It required tweaking a couple of SmartApps, as I explain below. But the result works. And I’m pretty proud of it–even if it is a Rube Goldberg sequence. Here is a basic summary for those of you equipped to handle it. (Specific implementation details are further below):

(1) All of the Open/Close sensors are configured to trigger a Virtual Switch (“S1”)
(2) S1 shuts off after 20 seconds (you could set any number of seconds)
(3) When S1 turns off, it triggers another Virtual Switch (“S2”)
(4) S2 activates motion on a Virtual Motion Sensor
(5) SHM alarm monitors for motion on only the Virtual Motion Sensor
(6) Both S2 and Virtual Motion Sensor turn off/reset after a few minutes.

Note that if you wanted a “real” motion sensor to also trigger a SHM intruder alert, you could run a parallel automation so that the motion sensors would also turn on S1 in step 1.

I needed this because we’re using a smart lock. We have it configured using IFTTT integration so that when it locks, it arms the SHM system, and when it unlocks, it disarms the SHM system. I will post separately about how we did that. (We wanted to use the lock’s keypad for arm/disarm because we spend a lot of time at our neighbors’ homes–we would register as “present” even if we’re in someone else’s backyard).

But the trouble is that when unlocking and opening the front door using the lock’s keypad, we would sometimes trigger the alarm. I guess the disarm routine hadn’t completed by the time the open/close sensor was triggered. Needed a short buffer to prevent false alarms.

Step 1: (All of the Open/Close sensors are configured to trigger a Virtual Switch (“S1”))

Create a virtual switch in the developer environment (“IDE”). Go to the IDE --> login --> My Locations --> Home (or wherever) --> My Devices --> New Device --> Name [S1 or whatever you want] --> Label [same] --> Zigbee Id [blank] --> [Device Network Id [whatever you want] --> Type [Simulated Switch] --> Location [home (or wherever] --> Hub [wherever] --> Group [blank] --> Create.

In the App, configure the open/close sensors to turn S1 on and off. You can do this in either Automatons/Routines or in the SmartApp for Lights & Switches --> Smart Lights --> New Lighting Automation.

Step 2: (S1 shuts off after 20 seconds (you could set any number of seconds))

I used the Power Allowance SmartApp Template, but I had to modify it to run in seconds rather than minutes.In the IDE, go to My SmartApps–> New SmartApp --> From Template --> All Categories --> Power Allowance. Copy that code. The click the “From Code” tab at the top and paste the code into the box. Every place in the code that you see the word, minutes, change it to “seconds.” And delete the multiplier of “* 60” a few lines from the bottom. Click Create --> Save --> Publish --> To Me.

In the app, go to Marketplace --> SmartApps --> My Apps (at the bottom) --> Power Allowance. Set the trigger switch to be S1, and set it to turn off in 20 seconds.

Credit to the community: I got this daisy-chain idea from user JDRoberts at this thread: Delay the State of a Switch?.

Step 3: (When S1 turns off, it triggers another Virtual Switch (“S2”))

In the IDE, create another virtual switch. Same process as Step 1. Let’s call it S2.
In the App, go to Smart Apps --> Lights & Switches --> Smart Lights --> New Lighting Automation.Set it to control S2, and have it set to turn S2 on when S1 is turned off.

Step 4: (S2 activates motion on a Virtual Motion Sensor)

In the IDE, create a virtual motion sensor that will be used to trigger the alarm when S2 is turned on. Same basic steps as creating a virtual switch.

Then, also in the IDE, create another smartapp from code using the “trigger a motion sensor” stuff found at the bottom of this thread: How to trigger an event on another device (possibly virtual?).

But this code is not perfect for these purposes. As written, this code only turns motion on for a very brief second before immediately resetting, which is not long enough to trigger the alarm. And if you remove the ability reset entirely, it you can’t reset your motion event on the virtual motion sensor (see Step 6). So you need to modify the code. From line 59 until the end, here are my changes–paste them over what is in the version you copy from github:

def installed() {
log.debug “Installed with settings: ${settings}”

on()
off()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
on()
    off()

}

def on() {
log.debug "subscribe"
subscribe(theswitch, “switch.on”, onHandler)
}

def off() {
log.debug "subscribe"
subscribe(theswitch, “switch.off”, offHandler)
}

def onHandler(evt){
log.debug "onHandler called: $evt"
themotion.active()
}
def offHandler(evt){
log.debug "offHandler called: $evt"
themotion.inactive()
}

After making these changes, click Create --> Save --> Publish --> To Me.

Then go to the App on your device. Smart Apps --> Motion Sensor Activation. Set it the switch to S2 and the Sensor to be the Virtual Motion Sensor you created.

Step 5: (SHM alarm monitors for motion on only the Virtual Motion Sensor))

Go back to the SHM Dashboard, Click the little gear to enter the Configure settings–>Security. Set your monitoring modes to use only the Virtual Motion Sensor(s) you have created. Note that if you are using real motion sensors and want them to have the same delay, you can just create another lighting/switch automation to turn on S1, only one that is triggered by your chosen motion sensors.

Step 6: (Both S2 and Virtual Motion Sensor turn off/reset after a few minutes.)
This is one of the reasons why we changed the code–the motion needs to be active for long enough to trigger the alarm, but it needs to also turn off after a certain amount of time. The code was modified to turn the motion back off when the switch is deactivated. You could also code a delay directly into the smartapp, but I’m not a coder and don’t know how to do that. Instead, I applied another automation in SmartApps You could use the Power Allowance App that you created (operating on a number of seconds), or you could use Smart Apps --> Lights & Switches --> Smart Lights --> New Lighting Automation and use the “Power Allowance” trigger that is built in there. Remember that this latter version is operating on a number of minutes. Set it for something like 3 minutes. After that amount of time, the S2 virtual switch will turn off and the virtual motion sensor will deactivate.

Edit–credit to the original author of the code:

  • Copyright 2015 James Houghton
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  • [I am a new user an cannot link–but there was a link here to Apache 2.0]
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.

And while we’re at it, I’ll say same goes for my modified/derivative version-- copyright 2016 by Peter Surdo. Apache 2.0 License terms apply.

5 Likes

Thanks. That seems more elegant.

At least now all the threads about setting a delay have two answers right here.

I am new to ST, but I did try to find rules engine and had the impression it wasn’t available anymore.I’m going to go play with Core next, I guess.

Turns out a new version of CoRE was released earlier today.

@El.Zurdo
Welcome to the community and the addiction!
I just want to say awesome job jumping in full force and finding a solution to the problem, and then taking the time to write up a detailed report to share with others to use.

If you have questions, feel free to ask… This community is asked finding new ways to take ST to the next level. And if you can’t find it in a search, ask, it’s probably been asked already, but the forum has a horrible search function.

Rule machine was an outstanding tool that filled s bad need in the ST environment. There were a lot of growing pains after the V2 release and the developer had a falling out. He then decided to abandon the project and left.

@ady624 stepped in and repaired the void caused by the rule machine developer. He created a rule engine that makes rule machine look like a cute little toy.

So, if you’re looking to do some amazing things, jump in there and see what home automation can really do!

Has anyone done this with CoRE? I’m just getting started with it and cant get the logic right.

well i tried to follow the directions, was unsuccessful. It trips the alarm every-time. I even went back and did it again. Looks like it turns on s1, then after delay s2 and immediately virtual motion. alarm trips.
There were some settings that were unclear like to turn it off again. in the smart lighting. etc.

help would be appreciated.

Thanks for the instruction seems easy but how does it integrate with shm as I use scout to monitor.

My cables are buried and I have 2 back ups… Cellular and sat phone.

Just to be safe a 4hr battery back up on critical components plus the generator that’s wired in.

Depending on where you live in the US, it can be just as bad. One of my coworkers had that issue with his setup, where after a few false alarms he got a pretty stern warning from the local precinct.

I haven’t had this problem. Sounds like your system isn’t disarming by the time virtual motion is triggered. Make sure you’re set for “S1 On → S1 Off after daley, triggering S2 to come on → S2 turns on virtual motion.” That’s your delay. As for disarming, make sure that the routine disarms the monitor at the same time that S1 turns on. And maybe try different delays to see if disarm is getting hung up or something. I’m currently set for a 5-second delay and our alarm gets a false alarm every once in a great while.

Yup. The Smart Home Monitor that plugs into Scout will monitor for open sensors or motion. You can use the dummy contact in Core. Or, if you already have the virtual motion sensor installed from the DME setup in the original post, you can use the “Motion Sensor Activation” smart app to have the siren or some other triggered switch to turn it on.

Thank you for this! Is there anyway to pass through CoRE a variable of the name of which contact sensor originally tripped? It seems like in this setup, SHM would only show the virtual contact as the point of intrusion. I only ask as an alternative to setting every intrusion sensor up with its own virtual equivalent.

Thanks again! This is ok because I only really need the delay for my front door to eliminate someone entering the correct access code but SHM triggering an intrusion before recognizing the code is correct.

Hey everyone, thanks for the replies and methods. I have been sick with bad cold or something so haven’t been trying to work on this but will soon.

The variable you are looking for is called $currentEventDevice - you can’t pass it to SHM but you can send a notification from CoRE to let you know which device. You can also save the matching device list in a condition into a variable of your choice (you name the variable whatever you want) in case several devices are tripped. CoRE will provide a comma separated list of all devices matching the condition. Then use that to send a notification to yourself.

Correct, but while setting the virtual sensor to open (to trigger SHM) he can also send a notification with which underlying physical device is tripped. At the same time (ie after the wait/delay)

1 Like

I am having problem. Using IDE I created a virtual open/close sensor with type = Zwave Door/Window Sensor (also tried Simulated Contact Sensor). I followed the instructions here but when I go to this part:

Using ZZ Dummy contact…
—> Wait 15 seconds … could do this.
----> Open … how?? When I go to “Add task” I get all sorts of options but no Open or Close…

I like this idea and will give it a try. The only issue I have with it is that, in my experience, I tend to get SHM alerts quicker than I get CoRE notifications (if at all). I don’t think that is a CoRE issue, I think it is a SmartApp issue. I’ve had things that trigger just fine when done by a built-in routine but doing the exact same thing in CoRE may be delayed several minutes or hours if they ever run (my outdoor lights come to mind)

Great help so far. I have the delay set up but don’t know how to set it up so it doesn’t activate alarm once I disarm the system.

If you mean the siren device, the siren should be set to turn on when there is an intrusion (have a virtual switch trigger it), and off when the system is disarmed (Core piston can be triggered by “Smart Home Monitor changes to Disarmed”) and/or when the mode changes to home (can be done in the “Automate Lights & Switches” SmartApp).