# Motion Sensor Does not send Inactive status

**URL:** <https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254>\
**Category:** General Discussion\
**Tags:** smartapp, motionsensor, hubv2, developers\
**Created:** [June 13, 2016, 2:44am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254 "2016-06-13T02:44:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_B](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jonathan_b/32/129122_2.png) [@Jonathan\_B](https://community.smartthings.com/u/Jonathan_B)\
**Post date:** [June 13, 2016, 2:44am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254/1 "2016-06-13T02:44:31Z")

</div>

Hello all,  
I am just getting into the smartthings stuff and wanted to try my hand at creating a smartapp. Anyways this is very similar to what they do in the tutorial but mine doesn’t seem to be working. Long story short when my motion sensor goes inactive it does not send that event so that I can act upon it.

Below is my code:

```
preferences {
    section("When there's movement...") {
        input "motion1", "capability.motionSensor", title: "Where?", multiple: true
    }
    section("Turn on a light...") {
        input "switch1", "capability.switchLevel", multiple: true
    }
    section("Dimmer value in Day mode...") {
        input "dimmerDay", type: "number", title: "Dimmer value (1-99) for day mode", required: true
    }
    section("Dimmer value in Night mode...") {
        input "dimmerNight", type: "number", title: "Dimmer value (1-99) for night mode", required: true
    }
    section("Turn off light after...") {
        input "delay", type: "number", title: "Delay (in minutes) before turning off lights (0 is off)", required: true
    }
}

def turnOffRequests = 0

def installed()
{
    subscribe(motion1, "motion", motionHandler)
}

def updated()
{
    unsubscribe()
    subscribe(motion1, "motion", motionHandler)
}

def motionHandler(evt) {
    log.debug evt.value
    if (evt.value == "active")
    {
        log.debug "Calling motionActive"
        motionActive()
    }
    else if (evt.value == "inactive")
    {
        log.debug "Calling motionInactive"
        motionInactive()
    }

}

def motionActive (){
    if (switch1.currentSwitch.contains("off"))
    { 
        sendNotificationEvent("Motion detected, turning on lights")
        def currMode = location.mode // "Home", "Away", etc.
        if (currMode == "Day")
        {
            log.debug "Light is off and mode is " + currMode + " so setting to " + settings.dimmerDay + "%"
            switch1.setLevel(settings.dimmerDay)
        }
        else
        {
            log.debug "Light is off and mode is " + currMode + " so setting to " + settings.dimmerNight + "%"
            switch1.setLevel(settings.dimmerNight)
        }
    }
    else
    {
        sendNotificationEvent("Motion detected but light is already on, doing nothing")
    }
}

def motionInactive() {
    if (settings.delay != 0)
    {
        turnOffRequests = turnOffRequests + 1
        sendNotificationEvent("Turning off lights in ${settings.delay} minutes.")
        def delaySeconds = settings.delay * 60
        runIn(delaySeconds, turnOff)
    }
}

def turnOff() {
    log.debug "turnOffRequests = " + turnOffRequests
    if (turnOffRequests == 1)
    {
        switch1.setLevel(0)    
    }
    turnOffRequests = turnOffRequests - 1    
}

```

Thanks,  
Jon

---

<div class="post-metadata">

**Author:** ![tonesto7](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tonesto7/32/114859_2.png) [@tonesto7](https://community.smartthings.com/u/tonesto7)\
**Post date:** [June 13, 2016, 2:46am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254/2 "2016-06-13T02:46:58Z")

</div>

You’re not alone I’m seeing the same exact issue

---

<div class="post-metadata">

**Author:** ![Jonathan\_B](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jonathan_b/32/129122_2.png) [@Jonathan\_B](https://community.smartthings.com/u/Jonathan_B)\
**Post date:** [June 13, 2016, 2:50am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254/3 "2016-06-13T02:50:05Z")

</div>

Thanks for the reply. At least I know that I am not the only one and not crazy!

---

<div class="post-metadata">

**Author:** ![JDRoberts](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jdroberts/32/56577_2.png) [@JDRoberts](https://community.smartthings.com/u/JDRoberts)\
**Post date:** [June 13, 2016, 2:57am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254/4 "2016-06-13T02:57:06Z")

</div>

Tagging @jody.albritton

---

<div class="post-metadata">

**Author:** ![Jonathan\_B](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jonathan_b/32/129122_2.png) [@Jonathan\_B](https://community.smartthings.com/u/Jonathan_B)\
**Post date:** [June 13, 2016, 4:05am UTC](https://community.smartthings.com/t/motion-sensor-does-not-send-inactive-status/50254/5 "2016-06-13T04:05:08Z")

</div>

> [@Jonathan\_B](#):
>
> def turnOffRequests = 0

I figured out my issue. Apparently I am not allowed to do the above. Found it in the documentation, now everything seems to be working as I expected.

Thanks,  
Jon
