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.