What a great Idea! Home intruders in the US will likely knock to see if someone is home. Light goes on, whoop, someone might be home - they’re out of there!
Good work.
Maybe add a slight delay [option] to turn the light on? That way we can emulate a person’s reaction time to the knock.
EDIT: Bravo on writing in last state into the code to make sure the app doesn’t inadvertently turn off a light if it was already on. I wish some of the built in ST apps did this too.
I have a garage door, with sensor and companion LFM-20. These are not automated, although I can control it if need be. I installed Light on on Knock, and accidentally selected the LFM-20 instead of the light. So, knock on the garage door, IT OPENS!! Not the security feature I was looking for! I discovered it trying to show off how cool it is to knock on the door and have the light come on. OOPS.
preferences {
section("Control these lights..."){
input "lights", "capability.switch", multiple: true
}
section("Turning on when there's movement..."){
input "accel", "capability.accelerationSensor", title: "Where?"
}
section("Delay turning on to simulate human response..."){
input "delayStartSeconds", "number", title: "Seconds:"
}
section("And then off when it's light or there's been no movement for..."){
input "delayStopMinutes", "number", title: "Minutes:"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
unschedule()
initialize()
}
def initialize() {
subscribe(accel, "acceleration", accelHandler)
}
def accelHandler(evt) {
log.debug "$evt.name: $evt.value"
if (evt.value == "active") {
if (true) {
log.debug "turning on lights due to motion with $delayStartSeconds seconds delay"
runIn(delayStartSeconds, turnOnLights, [overwrite: false])
}
state.motionStopTime = null
}
else {
state.motionStopTime = now()
if(delayStopMinutes) {
runIn(delayStopMinutes*60, turnOffMotionAfterDelay, [overwrite: false])
} else {
turnOffMotionAfterDelay()
}
}
}
def turnOnLights() {
lights.on()
state.lastStatus = "on"
}
def turnOffMotionAfterDelay() {
log.trace "In turnOffMotionAfterDelay, state.motionStopTime = $state.motionStopTime, state.lastStatus = $state.lastStatus"
if (state.motionStopTime && state.lastStatus != "off") {
def elapsed = now() - state.motionStopTime
log.trace "elapsed = $elapsed"
if (elapsed >= ((delayStopMinutes ?: 0) * 60000L) - 2000) {
log.debug "Turning off lights"
lights.off()
state.lastStatus = "off"
}
}
}
Definitely going to keep going with making stuff like this (slight mod in this case, thanks Mr. Norris). I think this is an excellent burglar deterrent.
I added more lights to it to emulate movement in the house:
/**
* Accelerometer Light
*
* Author: Chuck Norris, modified by Slonob
*
*/
definition(
name: “XLR8 Light Plus”,
namespace: “slonob”,
author: “The Norris, Jarrod Stenberg”,
description: “Turns on lights when a knock is detected. Can delay turning on multiple lights to simulate someone being home. Turns lights off when it becomes light or some time after motion ceases.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance@2x.png”
)