Turn lights off after so many minutes?

This doesn’t work in my case, already tried it. I need to shut off a switch (dry contact on a gas fireplace) when the door in that room is left open for a period of time, like 5 minutes. I do not want it to shut off the switch immediately when the door opens. The option to add a delay does not exist in this app. Again, 1. Door opens, then wait 5 minutes, if door is still open, then turn off fireplace. This allows people to go in and out without shutting off the fireplace unless the door is left open. This is a typical problem with renters at our vacation property.

OK, now you are describing a somewhat different scenario than the original. Because now you have a conditional at the end of the delay: I only want to turn the switch off if the door is still open. Not just after a delay from when the door first opened.

A delay from when the door first opened is easy. You can do it with the official features in the new V3 app. Or you can do it using the virtual timer I mentioned above.

But since you want to check the condition after the delay before executing the action, that’s what we call a “stacked conditional“ and it is definitely more complicated.

You are probably going to need to use webcore for this. It can definitely be done, but not through the official features. See the following FAQ:

How to Get Started Creating Complex Rules in SmartThings

Thanks JD I will check it out. On the surface it looks like flying from NY to CA via Hong Kong. Actually I found “Something Left Open” in the Marketplace under Energy Management, seems it makes more sense for me to figure out how to alter this code. It has the basics, just need to open a switch instead of send a text or notification.

I see… Just a remark, I would never use Smartthings to control something that could lead to fire or gas hazards. ST is not claiming they are a safety/security proven design and I know @JDRoberts previously shared the terms and conditions about that on ST pages.

You should consider what happens if you get your sensor or actuator lost/disconnected, how you get notified of it (generally suppose you go to the device list and check it by yourself) and you have to go on-site to reset the sensor.

1 Like

Thanks for the advice but I considered this long ago. The current fireplace has not been altered in any way. This switch is in series with the wall switch which is a mechanical timer. Further this switch is normally open. The worst case scenario is the guest have no fireplace. The alternative is, without this switch, the guest leave the fireplace on when they leave for the day (forced me to add the mechanical timer). Already happened. Not good. Not to mention it’s tied to CO, smoke detectors, temp, and motion sensors. Frankly one would be remiss not using this setup on a gas fireplace.

1 Like

JD check out the “Something Left Open” (I will later today), my guess is it’s using stacked conditions. Just need to alter the action.

What is the “new V3 app”?

I missed that this was for a gas fireplace.

It’s important to note that in many US jurisdictions it is illegal to have any kind of control on a gas fireplace which can be operated remotely. Even if you never intend to operate it remotely. Just the capability of being at your office 20 miles away and turning on the gas fireplace is against code in many places. That’s why the nationally sold gas fireplace remotes almost all are limited to about 20 feet, which is intended to be line of sight.

So the first thing to do is to check with your local township and make sure that it is legal to automate a gas fireplace switch with something that has a phone app. Because in most places it won’t be. And that in turn will invalidate your homeowners insurance if there is a fire.

So that’s the first thing to do.

If it is legal in your jurisdiction, then most people will choose a relay which has a built-in timer system so even if smartthings glitches and turns it on when you don’t expect it to be turned on, it will automatically turn itself off after 20 minutes or so. That’s what most people in the community have done. I assume that’s what your mechanical timer is doing, just not networked, and now you were just trying to turn it off even sooner if the door is left open.

So given that you have the mechanical timer and the other safety features, and assuming that it is legal in your jurisdiction, then again webcore should be able to do what you want. :sunglasses:

I just modified for you an adapted Left it open that turns off switches you select.
Have a try.

/**

  • Copyright 2015 SmartThings
  • 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.
  • Left It Open so swtich off
  • Author: SmartThings modified by Philippe Portes to switch off devices upon notification.
  • Date: 2013-05-09
    */
    definition(
    name: “Left It Open so switch off”,
    namespace: “PhilippePortesPPO”,
    author: “Philippe Portes”,
    description: “Notifies you when you have left a door or window open longer that a specified amount of time.”,
    category: “My Apps”,
    iconUrl: “https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage.png”,
    iconX2Url: “https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage%402x.png
    )

preferences {

section(“Monitor this door or window”) {
input “contact”, “capability.contactSensor”
}

section(“And notify me if it’s open for more than this many minutes (default 10)”) {
input “openThreshold”, “number”, description: “Number of minutes”, required: false
}

section(“Delay between notifications (default 10 minutes”) {
input “frequency”, “number”, title: “Number of minutes”, description: “”, required: false
}
section(“Choose one or more switches to turn off when notify”){
input “mySwitch”, “capability.switch”, title: “Switch to turn off”, required: false, multiple: true
}
section(“Via text message at this number (or via push notification if not specified”) {
input(“recipients”, “contact”, title: “Send notifications to”) {
input “phone”, “phone”, title: “Phone number (optional)”, required: false
}
}
}

def installed() {
log.trace “installed()”
subscribe()
}

def updated() {
log.trace “updated()”
unsubscribe()
subscribe()
}

def subscribe() {
subscribe(contact, “contact.open”, doorOpen)
subscribe(contact, “contact.closed”, doorClosed)
}

def doorOpen(evt) {
log.trace “doorOpen($evt.name: $evt.value)”
def delay = (openThreshold != null && openThreshold != “”) ? openThreshold * 60 : 600
runIn(delay, doorOpenTooLong, [overwrite: true])
}

def doorClosed(evt) {
log.trace “doorClosed($evt.name: $evt.value)”
unschedule(doorOpenTooLong)
}

def doorOpenTooLong() {
def contactState = contact.currentState(“contact”)
def freq = (frequency != null && frequency != “”) ? frequency * 60 : 600

if (contactState.value == “open”) {
def elapsed = now() - contactState.rawDateCreated.time
def threshold = ((openThreshold != null && openThreshold != “”) ? openThreshold * 60000 : 60000) - 1000
if (elapsed >= threshold) {
log.debug “Contact has stayed open long enough since last check ($elapsed ms): calling sendMessage()”
sendMessage()
runIn(freq, doorOpenTooLong, [overwrite: false])
} else {
log.debug “Contact has not stayed open long enough since last check ($elapsed ms): doing nothing”
}
} else {
log.warn “doorOpenTooLong() called but contact is closed: doing nothing”
}
}

void sendMessage() {
def minutes = (openThreshold != null && openThreshold != “”) ? openThreshold : 10
def msg = “{contact.displayName} has been left open for {minutes} minutes.”
log.info msg

// turns off all switches
mySwitch.each {
it.off()
}

if (location.contactBookEnabled) {
sendNotificationToContacts(msg, recipients)
} else {
if (phone) {
sendSms phone, msg
} else {
sendPush msg
}
}
}

1 Like

Thanks Phillippe. I got that to work after a little clean up. Now I need to add a way to turn the switch back on. Think I can grab part of the code from the lighting automation app if I can find it. It shows up on my classic app but not the IDE.

1 Like