Can anyone help with this use case?
I would like to have @copyninja 's iComfort app turn away mode “on” after a period of motion inactivity (say 1 hour), and turn away mode back off when motion is sensed. This (in my opinion) would be a killer use/app - essentially providing the presence functionally of nest but with multiple sensors and Lennox’s variable load capacity to boot.
I have an app that I use to turn lights on/off right now that I would like to modify - just need some direction (I’m not a programmer … but I can (barely) take other peoples work and revise it to make it work for my purposes).
Any help is appreciated.
I guess to start, what would I need to write so that I can change the mode to “away” in @copyninja iComfort app?
/**
* Turn light on with motion for x minutes on motion
*
* Written by Aaron Herzon
*
* 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:
*
* http://www.apache.org/licenses/LICENSE-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.
*
*/
definition(
name: "Nightlight (Dimmable)",
namespace: "TC",
author: "TC",
description: "Dimmable Nightlight",
category: "Safety & Security",
iconUrl: "http://cdn.marketplaceimages.windowsphone.com/v8/images/c7615463-1173-4d2a-a239-9f1b956a53aa?imageType=ws_icon_small",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
//todo: replace icon with something appropriate.
preferences {
section("Select Motion Sensor(s) you want to Use") {
input "motions", "capability.motionSensor", title: "Motion Detector", required: true, multiple: true
}
section("Select Dimmers you want to Use") {
input "switches", "capability.switchLevel", title: "Dimmer Switches", required: false, multiple: true
}
section ("Set Brightness for motion-triggered light and on time after motion stops") {
input "BrightLevelStr", "number", title: "Motion-Sensed Level %", required: true,
defaultValue: "100"
input "DelayMinStr", "number", title: "Bright Delay After Motion Stops, minutes", required: true,
defaultValue: "5"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
log.debug "initialize()"
state.BrightLevel = BrightLevelStr as Integer
if (state.BrightLevel == 100) {
state.BrightLevel = 99
}
state.DelayMin = DelayMinStr
subscribe(motions, "motion.active", handleMotionEvent)
subscribe(motions, "motion.inactive", handleEndMotionEvent)
subscribe(location, "mode", modeChangeHandler)
}
def handleMotionEvent(evt) {
log.debug "Motion detected..."
unschedule(turnLightsOff)
if (state.lightIsOn) {
log.debug "... light already on (do nothing)"
}
else {
switches?.setLevel(state.BrightLevel)
state.lightIsOn=true
log.debug "...turning lights on"
}
}
def handleEndMotionEvent(evt) {
log.debug "Motion stopped..."
if (state.lightIsOn) {
runIn((state.DelayMin*60), turnLightsOff)
}
}
def turnLightsOff() {
log.debug "turnLightsOff()"
switches?.setLevel(99)
switches?.setLevel(0)
state.lightIsOn=false
}
def modeChangeHandler(evt) {
log.debug "Mode Changed... turn state.light off"
state.lightIsOn=false
runIn((state.DelayMin*60), turnLightsOff)
}