Konnected motion sensors - delay configuration

Anyone know if its possible to add a re-trigger delay to a Konnected motion sensor? The immediate resetting of my motions sensors makes it a challenge to use them as part of my automation's.

The driver is here:

Is it possible to add a delay configuration parameter here? Hope @nate might be able to help.

I did exactly zero testing (so use the warranted caution), but something like this seems like it should work. :slight_smile:

/**
 *  Konnected Motion Sensor (Modified: Inactive Delay)
 *
 *  Copyright 2018 Konnected Inc (https://konnected.io)
 *
 *  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.
 *
 */
metadata {
  definition (name: "Konnected Motion Sensor", namespace: "konnected-io", author: "konnected.io", mnmn: "SmartThings", vid:"generic-motion") {
    capability "Motion Sensor"
    capability "Sensor"
  }

  preferences {
    input name: "normalState", type: "enum", title: "Normal State",
      options: ["Normally Closed", "Normally Open"],
      defaultValue: "Normally Closed",
      description: "Most motion sensors are Normally Closed (NC), meaning that the circuit opens when motion is detected. To reverse this logic, select Normally Open (NO)."
    input name: "inactiveDelay", type: "enum", title: "Delay before \"inactive\" event",
      options: [[0:"None"],[5:"5 seconds"],[10:"10 seconds"],[15:"15 seconds"],[20:"20 seconds"],[30:"30 seconds"],[45:"45 seconds"],[60:"1 minute"],[90: "1.5 minutes"],[120:"2 minutes"],[180:"3 minutes"]]
  }
}

String isClosed() {
  normalState == "Normally Open" ? "active" : "inactive"
}

String isOpen() {
  normalState == "Normally Open" ? "inactive" : "active"
}

// Update state sent from parent app
void setStatus(state) {
  String stateValue = state == "1" ? isOpen() : isClosed()
  if (stateValue == "active") {
    sendEvent(name: "motion", value: "active")
    unschedule("setInactive")
    log.info "${device.label} is active"
  }
  else {
    Integer delay = (settings.inactiveDelay ? (settings.inactiveDelay as Integer) : 0)
    if (delay) {
      runIn(delay, "setInactive")    
      log.info "${device.label} will be set to inactive in $delay seconds"
    }
    else {      
      sendEvent(name: "motion", value: "inactive")    
      log.info "${device.label} is inactive"
    }
  }
}

void setInactive() {
  sendEvent(name: "motion", value: "inactive")
}

This adds a preference to set the delay before the "inactive" event, so set that to some value and hit "Save Preferences," otherwise it should work the same as the original driver.

1 Like

Awesome! The added delay looks to be working.

Wow. Thanks.

And thanks @tedrpi for thinking of this. I am using a konnected motion sensor and I just get many triggers from it. Usually two every time it fires and yes it goes inactive way too quickly. I was actually going to add an RC to the input but here again is a great example of fixing HW problems in SW.

I will definitely give this a try.

You might need an unscheduled in there if you are already in your runin and it triggers motion again.

1 Like

Good catch! I've edited the above.

1 Like

Download the Hubitat app