Set Garage door to close if left open at a certain time


(Mcvoss) #1

I thought I saw an app for what I want to do but now I cant find it.

On my garage I have a tilt sensor and the Linear relay setup to open and close my garage door. What I would like to do is have Smartthings check the status of my tilt sensor, at a certain time (9pm) , and if open click the relay to close the garage. Any ideas on how to do this?

Thanks,
MIchael


(Matthew Rogers) #2

I have a similar need, except I just want to get a text if I’ve left my garage open past a certain time of night. I’ve dug around but I can’t find any way to do this (which seems insane to me, not supporting something basic like “@time if [sensor state] then [action]”).


(Scott) #3

Is it possible to run any actions based on a set amount of time with ST?


(Convinced ST will never be unbroken…) #4

Here is one I created to send a notification. Simple to add a switch it if you want.

/**
 *  Garage After Dark
 *
 *  Author: Scottin Pollock
 *
 *  Date: 2014-06-15
 */
definition(
    name: "Garage After Dark",
    namespace: "smartthings",
    author: "Scotin Pollock",
    description: "Sends notification when garage door is open during sunset times.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/garage_contact.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/garage_contact@2x.png"
)

preferences {
    section("Warn if garage door is open...") {
		input "multisensor", "capability.threeAxis", title: "Which?"
	}
	section ("Sunset offset (optional)...") {
		input "sunsetOffsetValue", "text", title: "HH:MM", required: false
		input "sunsetOffsetDir", "enum", title: "Before or After", required: false, metadata: [values: ["Before","After"]]
	}
	section ("Zip code (optional, defaults to location coordinates)...") {
		input "zipCode", "text", title: "Zip Code", required: false
	}
	section( "Notifications" ) {
		input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]], required: false
		input "message", "text", title: "Message to send...", required: false
	}
}

def installed() {
	initialize()
}

def updated() {
	unschedule()
	initialize()
}

def initialize() {
	scheduleAstroCheck()
	astroCheck()
}

def scheduleAstroCheck() {
	def min = Math.round(Math.floor(Math.random() * 60))
	def exp = "0 $min * * * ?"
    log.debug "$exp"
	schedule(exp, astroCheck) // check every hour since location can change without event?
    state.hasRandomSchedule = true
}

def astroCheck() {
	if (!state.hasRandomSchedule && state.riseTime) {
    	log.info "Rescheduling random astro check"
        unschedule("astroCheck")
    	scheduleAstroCheck()
    }
	def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)

	def now = new Date()
	def riseTime = s.sunrise
	def setTime = s.sunset
	log.debug "riseTime: $riseTime"
	log.debug "setTime: $setTime"
	if (state.riseTime != riseTime.time || state.setTime != setTime.time) {
		state.riseTime = riseTime.time
		state.setTime = setTime.time

		unschedule("sunriseHandler")
		unschedule("sunsetHandler")

		if (riseTime.after(now)) {
			log.info "scheduling sunrise handler for $riseTime"
			runOnce(riseTime, sunriseHandler)
		}

		if (setTime.after(now)) {
			log.info "scheduling sunset handler for $setTime"
			runOnce(setTime, sunsetHandler)
		}
	}
}

def sunriseHandler() {
	log.info "Executing sunrise handler"
	//Do Nothing
	unschedule("sunriseHandler") // Temporary work-around for scheduling bug
}

def sunsetHandler() {
	log.info "Executing sunset handler"
    def Gdoor = checkGarage()
       if (Gdoor == "open") {
       	send(message)
        }
	unschedule("sunsetHandler") // Temporary work-around for scheduling bug
}


private send(msg) {
	if ( sendPushMessage != "No" ) {
		log.debug( "sending push message" )
		sendPush( message )
	}

	log.debug message
}

def checkGarage(evt) {
def latestValue = multisensor.latestValue("status")
}

private getLabel() {
	app.label ?: "SmartThings"
}

private getSunriseOffset() {
	sunriseOffsetValue ? (sunriseOffsetDir == "Before" ? "-$sunriseOffsetValue" : sunriseOffsetValue) : null
}

private getSunsetOffset() {
	sunsetOffsetValue ? (sunsetOffsetDir == "Before" ? "-$sunsetOffsetValue" : sunsetOffsetValue) : null
}

(Mcvoss) #5

Thanks ScottinPollock, I appreciate it!


(Matthew Rogers) #6

That’s great Scottinpollock, thank you. You should submit that so it’s available to everyone.


(Convinced ST will never be unbroken…) #7

Done… but my experience has been that it takes a week or two for submissions to be approved.


(Matthew Rogers) #8

Cool – I have more than one garage door, and I thought it would be helpful to be able to select multiple doors to be alerted about. I did a little work on it (this is the very first SmartApp code I’ve written)…it’s almost entirely your code, but now it seems to work with multiple doors. Waiting to test it for real tonight. I’d like to make it generic for all types of doors though, not just threeAxis sensors…what’s the best way to do that? It doesn’t seem you can OR capabilities (as in, show me sensors that support threeAxis OR contact).

/**
 *  Doors After Dark
 *	Be alerted whenever selected door(s) are open after sunset.
 *  Nearly all of this is stolen from Scottin Pollock's 'Garage after Dark'
 *
 *  Author: Matt Rogers
 *
 *  Date: 2014-06-25
 */
definition(
    name: "Doors After Dark",
    namespace: "smartthings",
    author: "Matt Rogers",
    description: "Sends notification when door is open during sunset times.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/garage_contact.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/garage_contact@2x.png"
)

preferences {
    section("Select door(s)") {
		input "doors", "capability.threeAxis", title: "Which?", multiple: true
	}
	section ("Sunset offset (optional)") {
		input "sunsetOffsetValue", "text", title: "HH:MM", required: false
		input "sunsetOffsetDir", "enum", title: "Before or After", required: false, metadata: [values: ["Before","After"]]
	}
	section ("Zip code (optional, defaults to location coordinates)") {
		input "zipCode", "text", title: "Zip Code", required: false
	}
	section( "Notifications" ) {
		input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]], required: false
		input "message", "text", title: "Message to send", required: false
	}
}

def installed() {
	initialize()
}

def updated() {
	unschedule()
	initialize()
}

def initialize() {
	scheduleAstroCheck()
	astroCheck()
}

def scheduleAstroCheck() {
	def min = Math.round(Math.floor(Math.random() * 60))
	def exp = "0 $min * * * ?"
    log.debug "$exp"
	schedule(exp, astroCheck) // check every hour since location can change without event?
    state.hasRandomSchedule = true
}

def astroCheck() {
	if (!state.hasRandomSchedule && state.riseTime) {
    	log.info "Rescheduling random astro check"
        unschedule("astroCheck")
    	scheduleAstroCheck()
    }
	def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)

	def now = new Date()
	def riseTime = s.sunrise
	def setTime = s.sunset
	log.debug "riseTime: $riseTime"
	log.debug "setTime: $setTime"
	if (state.riseTime != riseTime.time || state.setTime != setTime.time) {
		state.riseTime = riseTime.time
		state.setTime = setTime.time

		unschedule("sunriseHandler")
		unschedule("sunsetHandler")

		if (riseTime.after(now)) {
			log.info "scheduling sunrise handler for $riseTime"
			runOnce(riseTime, sunriseHandler)
		}

		if (setTime.after(now)) {
			log.info "scheduling sunset handler for $setTime"
			runOnce(setTime, sunsetHandler)
		}
	}
}

def sunriseHandler() {
	log.info "Executing sunrise handler"
	//Do Nothing
	unschedule("sunriseHandler") // Temporary work-around for scheduling bug
}

def sunsetHandler() {
	log.info "Executing sunset handler"
    doors?.each {
        def door = checkDoor(it)
        log.debug(door)
        if (door == "open") {
            send(message)
        }
    }
    unschedule("sunsetHandler") // Temporary work-around for scheduling bug
}


private send(msg) {
	if ( sendPushMessage != "No" ) {
		log.debug( "sending push message" )
		sendPush( message )
	}

	log.debug message
}

def checkDoor(door) {
	def latestValue = door.latestValue("status")
}

private getLabel() {
	app.label ?: "SmartThings"
}

private getSunriseOffset() {
	sunriseOffsetValue ? (sunriseOffsetDir == "Before" ? "-$sunriseOffsetValue" : sunriseOffsetValue) : null
}

private getSunsetOffset() {
	sunsetOffsetValue ? (sunsetOffsetDir == "Before" ? "-$sunsetOffsetValue" : sunsetOffsetValue) : null
}

(Scott) #9

Do I have to write my own apps in order to do stuff like this? Set things to happen after x amount of time?


(Matthew Rogers) #10

Right now, it appears so if you want it based on time of day. There doesn’t seem to be anything in the “official” catalog – the closest one is to alert you if a door has been left open for X minutes, but that doesn’t quite serve the need here. We’re looking to be alerted if a door is open after a certain time of day (sunset, in this case).

This is a major issue I take with SmartThings – the apps are too specific. The platform needs to support much more generic rulesets a la the If This Then That service. If their developers didn’t think of it, you have to get in here and make/find a user-created app to do it (and finding the right user-created app can be really hard, by the way – there’s no good searchable catalog, just one you can browse from the IDE). Which in some sense it’s definitely great that it’s so extensible, but right now the ST ecosystem is too reliant on that – the platform will never be “for the masses” if the majority of needs have to be addressed via custom code.


(David McCabe) #11

Is there anything new to follow in the area of this topic? I just put 3 EcoLink tilt sensors on garage doors and they are great sensors! I just don’t know what to do with them! I finally got their icons changed to mimic a garge door and would love to be able to do a check at 9 PM to see if they are open, then send an alert. I tried “garage after dark” code and it is not alerting me. I pulled a sensor off and have it sitting out in the open state in order for the code to run against an open door.
Not blaming the code however, I could have hosed that up.


(Brianh) #12

@mccabeio I am trying to find an app to do this as well. I picked up two of the EcoLink tilt sensor cheap and want to find an smartapp that can tell me if the door is opened after a specific time. I haven’t found one yet.


(Mcvoss) #13

I use this. I DID NOT right this app, it was written by Matt Nohr all credit goes to him. For some reason I cant find it here again. Maybe not looking hard enough. This will send an alert and if you want close the door also.

/**

  • Close Garage Door At Night
  • Copyright 2014 Matt Nohr
  • 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.

*/

/**

preferences {
section(“What Garage Door?”) {
input “contact1”, “capability.contactSensor”, title: "Open/Closed Sensor"
input “opener1”, “capability.momentary”, title: “Garage Door Button”
}
section(“Actions”) {
input “alertTime”, “time”, title: “Alert Me At This Time”, required: false
input “closeMode”, “mode”, title: “Close when switching to this mode”, required: false
}
}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unschedule()
unsubscribe()
initialize()

}

def initialize() {
if(closeMode) {
subscribe(location, “modeChangeHandler”)
}
if(alertTime) {
runDaily(alertTime, “checkAndAlert”)
}
}

def checkAndAlert() {
def doorOpen = isDoorOpen()
log.debug "In checkAndAlert - is the door open: $doorOpen"
if(doorOpen) {
def message = "The garage door is still open!"
log.info message
sendNotification(message, [method: “push”])
}
}

def modeChangeHandler(evt) {
log.debug "In modeChangeHandler for $evt.name = $evt.value"
if(evt.value == closeMode && isDoorOpen()) {
def message = "Closing garage door since it was left open"
log.info message
sendNotification(message, [method: “push”])

	opener1.push()
}

}

def isDoorOpen() {
return contact1.latestValue(“contact”) == “open”
}


(Matthew Rogers) #14

I finally got around to writing this a few days ago. It’s generic to all doors (not just garages) and it’s only an alert – it does not try to close the door It’s pretty basic right now, but I tested it last night by leaving my garage open and it worked as expected.


(Wes Jacobs) #15

I would like this app to just check the garage door at specified time and leave out the sunset time, the time would change depending and the time of year. And of course left me know the status of the door. Anyone know how to do that?


(Greg) #16

this will work, but it won’t close a garage door


(Wes Jacobs) #17

Thanks!! At least 20!!