(@garyd9, I thought it best to take this out of the Fibaro thread in order not to get too far off topic.)
Here is my issue:
I have several (4) Fibaro motion sensors and one Aeotec motion sensor. I would like to be able to have the motion sensors trigger certain dimmer switches with motion and turn off after a set period of time after no more motion is detected.
Here is the code I am using:
[code]
definition(
name: “Motion Sensor Dimmer On/Off”,
namespace: “”,
author: “”,
description: “Turn on some lights with motion if not already on”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
section(“Select the motion sensor…”) {
input “motion1”, “capability.motionSensor”, title: “Which?”, required: true, multiple: false
}
section("Select the switches to control...") {
input "switches", "capability.switchLevel", title: "Which?", required: true, multiple: true
}
section("Select the dimmer level...") {
input "level", "number", title: "Level?", required: true
}
section("Select the number of minutes after to turn off") {
input "minutes", "number", title: "Minutes?", required: true
}
}
def installed() {
// log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
// log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}
def initialize() {
subscribe(motion1, “motion.active”, motionOnHandler)
subscribe(motion1, “motion.inactive”, motionOffHandler)
}
def motionOnHandler(evt) {
unschedule(switchesOff)
state.switchOff = true
for(mySwitch in switches) state.switchOff = state.switchOff && (mySwitch.currentValue(“switch”) == “off”)
if(state.switchOff) switches.setLevel(level)
}
def motionOffHandler(evt) {
if(state.switchOff) {if(minutes>0) runIn(minutes*60,switchesOff) else switches.off()}
}
def switchesOff() {
switches.off()
} [/code]
Problems:
-
Continued motion did not appear to reset the timer for the light to turn off. For example, I would be in my kitchen, and as intended, the kitchen lights would turn on. I set the app to turn the kitchen lights off 10 minutes after motion stopped. What would frequently happen is that 10 minutes after the light turned on, the light would turn off, even rgough I was still in the room moving around @garyd9 suggested adding “unschedule(switchesOff)” which was done.
-
Now however, the lights will not turn off and remain on once triggered.
Possible complicating factors:
- Multiple sensors triggering a single switch. For example, I have a sensor above both doors that lead into a hallway. When motion is detected, the light in the hall is to turn on for two minutes, then turn off. Not sure if having two apps that control the same switch makes a difference, but I am just throwing that out there. It’d be nice if I could ID multiple sensors i.e., if motion detected on hallway sensor A or hallway sensor B, turn on hall light at X percent until 2 minutes after no motion on sensor A or sensor B is detected. I’d also LOVE it if the app would allow a bypass of the dimmer setting to 100% if a switch is manually pushed. For example, turn on to 1% if motion, but if switch is pushed, turn on to 100%.
2.???
I have NO programming experience, so I’m am relying on simple logic to troubleshoot, and the helpfulness of forum members. I’m also not beholden to that app I am using but did struggle to find another that would let me set light values to 1% and not just 10%, 20% etc.