# \[OBSOLETE\] Garage Door Sunset Monitor

**URL:** <https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050>\
**Category:** Community Created SmartApps\
**Tags:** smartapp\_alerts, smartapp\_garage, smartapp\_security\
**Created:** [May 17, 2016, 12:00am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050 "2016-05-17T00:00:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [May 17, 2016, 12:00am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/1 "2016-05-17T00:00:20Z")

</div>

Hi everyone,

I’ve designed a SmartApp that I’d like to share, the Garage Door Sunset Monitor:

> <https://github.com/nicjansma/smart-things/blob/master/smartapps/nicjansma/garage-door-sunset-monitor.src/garage-door-sunset-monitor.groovy>

This app was inspired by a couple other great projects:

- [MSA-762: Garage Door Watchdog by SmartThings · Pull Request #396 · SmartThingsCommunity/SmartThingsPublic · GitHub](https://github.com/SmartThingsCommunity/SmartThingsPublic/pull/396/files)
- [GitHub - rogersmj/st-door-alert-after-dark: SmartThings SmartApp for alerting you if doors are open after dark](https://github.com/rogersmj/st-door-alert-after-dark)

But I was looking for something a bit different.

The Garage Door Sunset Monitor is designed to notify you if your garage door (or any other contact sensor) is open after dark, or some other preset times.

Features:

- You can monitor any number of doors
- You can monitor based on sunset/sunrise (+/- X minutes), or, at specific times of the day
- You can decide how long the doors can be open before you’re alerted

I’ve been using the app for a while at my home and it has been working reliably.

Please let me know if you use it!

---

<div class="post-metadata">

**Author:** ![jlv](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jlv/32/104336_2.png) [@jlv](https://community.smartthings.com/u/jlv)\
**Post date:** [May 17, 2016, 12:51am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/2 "2016-05-17T00:51:22Z")

</div>

Ah, I was going to work on something like this soon!

---

<div class="post-metadata">

**Author:** ![pmusselman](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@pmusselman](https://community.smartthings.com/u/pmusselman)\
**Post date:** [May 22, 2016, 9:01pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/3 "2016-05-22T21:01:30Z")

</div>

This thing is amazing. Is it possible to have a switch activated if the threshold is reached? For example, I have some cameras in my garage where it would be nice to turn the switch on the controls the cameras and off when clearde. Thanks! You guys make me really come back to ST because of the craftsmanship in your work! That s to all smartapp community authors! Where can I donated?

---

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [May 23, 2016, 12:01am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/4 "2016-05-23T00:01:57Z")

</div>

@pmusselman Glad it helps! You should be able to update the app to turn on/off switches when the alarm fires. You’ll want to have a preference for `capability.switch` and then just turn it `.on()`. Let me know if you can’t get it going!

---

<div class="post-metadata">

**Author:** ![mccabeio](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/mccabeio/32/15002_2.png) [@mccabeio](https://community.smartthings.com/u/mccabeio)\
**Post date:** [September 12, 2016, 8:16pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/5 "2016-09-12T20:16:00Z")

</div>

Awesome. I’m going to give it a try.

For clarification, how do you setup a time check if you don’t want to use Sunset. Say I want to do 9 PM every night. Is that possible and how do you set it in the smart app? Thanks.

---

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [September 12, 2016, 10:24pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/6 "2016-09-12T22:24:33Z")

</div>

Yep! You should be able to do a time-based system easily. Here’s one of my other apps that has time preferences:

> <https://github.com/nicjansma/smart-things/blob/master/smartapps/nicjansma/home-alone.src/home-alone.groovy>

---

<div class="post-metadata">

**Author:** ![brumster](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/brumster/32/35212_2.png) [@brumster](https://community.smartthings.com/u/brumster)\
**Post date:** [November 8, 2016, 8:17am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/7 "2016-11-08T08:17:11Z")

</div>

@nicjansma ,

I use the “Garage Door Sunset Monitor” and have had a couple of false positive notifications.

Here’s the details from this morning:

```
2016-11-08 5:38:04.918 AM GMT
DEVICE Door - Garage Roller contact is open

2016-11-08 5:38:06.101 AM GMT
Alert: Its sunset and Door - Garage Roller is open for 30 minutes Push (OK)

2016-11-08 5:38:54.442 AM GMT	
DEVICE contact	closed Door - Garage Roller contact is closed 

2016-11-08 5:43:06.038 AM GMT
OK: Door - Garage Roller closed Push (OK)

```

Any ideas what might be causing it? As you can see from the contact sensor details above the door was open for less than 60 seconds.

Cheers.

---

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [November 17, 2016, 2:57am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/8 "2016-11-17T02:57:01Z")

</div>

Hi @brumster – what do you have “Alert Thresholds” set to? 30 minutes?

How many doors do you have? If you have more than one, I think I’ve spotted a bug in the code.

---

<div class="post-metadata">

**Author:** ![brumster](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/brumster/32/35212_2.png) [@brumster](https://community.smartthings.com/u/brumster)\
**Post date:** [November 17, 2016, 6:16am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/9 "2016-11-17T06:16:41Z")

</div>

Thanks for getting back to me @nicjansma

Threshold set to 30. Only now door installed.

---

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [November 23, 2016, 2:33pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/10 "2016-11-23T14:33:49Z")

</div>

@brumster OK, if you have only one door then I’m not sure where the bug would be.

Mind sharing the device logs at all? Might help us determine what’s going on.

---

<div class="post-metadata">

**Author:** ![brumster](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/brumster/32/35212_2.png) [@brumster](https://community.smartthings.com/u/brumster)\
**Post date:** [November 28, 2016, 6:45am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/11 "2016-11-28T06:45:10Z")

</div>

Let me see if it does it again and when it does I’ll give you the full break down. Thx.

---

<div class="post-metadata">

**Author:** ![ebright](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@ebright](https://community.smartthings.com/u/ebright)\
**Post date:** [February 27, 2017, 4:08am UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/12 "2017-02-27T04:08:16Z")

</div>

I noticed this issue too so I debugged the code. I think the problem is that the state.threshold is not reset if the door closes before the threshold is met. So made this change to checkdoors(). I have not tested this code yet but I will in the next few days

```
def checkDoors() {
    // if we're doing Time of Day monitoring, see if this is within the times they specified
    if (monitoringType == "Time of Day") {
        def currTime = now()
        def eveningStartTime = timeToday(startMonitoring)
        def morningEndTime = timeToday(stopMonitoring)

        state.monitoring = currTime >= eveningStartTime.time || currTime <= morningEndTime.time
    }

    log.info "checkDoors: Should we check? $state.monitoring"

    if (!state.monitoring) {
        return
    }

    doors?.each { door ->
        def doorName = door.displayName
        def doorOpen = checkDoor(door)

        log.debug("checkDoors: Door $doorName: $doorOpen, previous state: " + state.opened[doorName])

        if (doorOpen == "open" && !state.opened[doorName]) {
            // previously closed, now open
            state.threshold = state.threshold + 5
            log.debug("checkDoors: Door was closed, is now open. Threshold check: ${state.threshold} minutes (need " + threshold + "minutes)")

            if (state.threshold >= threshold) {
                log.debug("checkDoors: Door has been open past threshold, sending an alert")

                send("Alert: It's sunset and $doorName is open for $threshold minutes")
                state.opened[doorName] = true
            }
        } else if (doorOpen == "closed" && state.opened[doorName]) {
            // previously open, now closed
            log.debug("checkDoors: Door had been previously open, is now closed")

            send("OK: $doorName closed")

            state.opened[doorName] = false
            state.threshold = 0
        } else if (doorOpen == "closed"){
            // Door closed before threshold, reset threshold
            log.debug("checkDoors: Door closed before " + threshold + " threshold. Threshold check: ${state.threshold} minutes (threshold reset to 0)")
            state.threshold = 0
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![nicjansma](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nicjansma/32/24441_2.png) [@nicjansma](https://community.smartthings.com/u/nicjansma)\
**Post date:** [March 2, 2017, 6:09pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/13 "2017-03-02T18:09:19Z")

</div>

Great catch Eric! Would you be able to open a PR? [https://github.com/nicjansma/smart-things](https://github.com/nicjansma/smart-things)

---

<div class="post-metadata">

**Author:** ![kmccb](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/kmccb/32/181673_2.png) [@kmccb](https://community.smartthings.com/u/kmccb)\
**Post date:** [January 26, 2018, 7:57pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/14 "2018-01-26T19:57:32Z")

</div>

New user question… Do I just log in to [https://graph.api.smartthings.com](https://graph.api.smartthings.com), click on “My SmartApps” \> New SmartApp" \> From Code \> Paste your GitHub code \> Click Create \> Click Publish?

Then it should show up in the ST app? That’s what I did and it’s not showing up…

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![WB70](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/wb70/32/95668_2.png) [@WB70](https://community.smartthings.com/u/WB70)\
**Post date:** [January 26, 2018, 8:18pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/15 "2018-01-26T20:18:34Z")

</div>

> [@kmccb](#):
>
> New user question… Do I just log in to [https://graph.api.smartthings.com](https://graph.api.smartthings.com), click on “My SmartApps” \> New SmartApp" \> From Code \> Paste your GitHub code \> Click Create \> Click Publish?

Always login to [https://account.smartthings.com](https://account.smartthings.com) and then it will redirect you to your correct shard (url).

This is more than likely why you can’t see it in Marketplace. After you logout / login with the above url, note the shard you are redirected to (more than likely not graph.api…). If you don’t see the SmartApp there, then recreate it again and publish for you. Then it will show in Marketplace.

---

<div class="post-metadata">

**Author:** ![kmccb](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/kmccb/32/181673_2.png) [@kmccb](https://community.smartthings.com/u/kmccb)\
**Post date:** [January 26, 2018, 9:01pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/16 "2018-01-26T21:01:53Z")

</div>

Thank you!! That worked!!

---

<div class="post-metadata">

**Author:** ![WB70](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/wb70/32/95668_2.png) [@WB70](https://community.smartthings.com/u/WB70)\
**Post date:** [January 26, 2018, 9:22pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/17 "2018-01-26T21:22:12Z")

</div>

> [@kmccb](#):
>
> Thank you!! That worked!!

Can you do me a favor and mark that post above as a solution. Click the check box ✓. That way it will help others in the future if they come across this. 🙂

---

<div class="post-metadata">

**Author:** ![kmccb](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/kmccb/32/181673_2.png) [@kmccb](https://community.smartthings.com/u/kmccb)\
**Post date:** [January 26, 2018, 9:34pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/18 "2018-01-26T21:34:39Z")

</div>

Sorry mate… I don’t see any check box…

---

<div class="post-metadata">

**Author:** ![WB70](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/wb70/32/95668_2.png) [@WB70](https://community.smartthings.com/u/WB70)\
**Post date:** [January 26, 2018, 9:37pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/19 "2018-01-26T21:37:14Z")

</div>

> [@kmccb](#):
>
> Sorry mate… I don’t see any check box…

Click on the … on that post and then you should see checkbox.

 ![Screenshot_20180126-133542~2](https://global.discourse-cdn.com/smartthings/original/3X/4/4/445b38fc2ccce0b5ff6a4d779393803330d90e8b.png)

---

<div class="post-metadata">

**Author:** ![kmccb](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/kmccb/32/181673_2.png) [@kmccb](https://community.smartthings.com/u/kmccb)\
**Post date:** [January 26, 2018, 9:49pm UTC](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050/20 "2018-01-26T21:49:27Z")

</div>

![](https://global.discourse-cdn.com/smartthings/original/3X/3/c/3c84c2f7c54149bf71e9785ba508ac07f1db84dc.png)

[Next page](https://community.smartthings.com/t/obsolete-garage-door-sunset-monitor/48050.md?page=2)
