Created
October 3, 2020 16:21
-
-
Save PolarbearDK/020de22ed4a5388c06b1fd6905f06635 to your computer and use it in GitHub Desktop.
Garage port automation with close timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Garage port automation with timer | |
* | |
* Copyright 2020 Philip Hoppe | |
* | |
* 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. | |
* | |
*/ | |
definition( | |
name: "Garage port automation with close timer", | |
namespace: "PolarbearDK", | |
author: "Philip Hoppe", | |
description: "Garage port automation with close timer", | |
category: "SmartThings Labs", | |
iconUrl: "http://cdn.device-icons.smartthings.com/Transportation/transportation13-icn.png", | |
iconX2Url: "http://cdn.device-icons.smartthings.com/Transportation/transportation13-icn@2x.png", | |
iconX3Url: "http://cdn.device-icons.smartthings.com/Transportation/transportation13-icn@2x.png") | |
preferences { | |
section("Close door after period") { | |
input "garageSensor", "capability.contactSensor", required: true, multiple: false, title: "Door sensor?" | |
input "closeInMinutes", "number", required: true, title: "Close after Minutes?" | |
input "garageSwitch", "capability.switch", required: true, title: "Switch to close door?" | |
} | |
} | |
def installed() { | |
log.debug "Installed with settings: ${settings}" | |
initialize() | |
} | |
def updated() { | |
log.debug "Updated with settings: ${settings}" | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
subscribe(app, appHandler) | |
subscribe(garageSensor, "contact.open", garageDoorOpen) | |
subscribe(garageSensor, "contact.closed", garageDoorClosed) | |
} | |
def appHandler(evt) { | |
log.debug "app event ${evt.name}:${evt.value} received" | |
} | |
def garageDoorOpen(evt) { | |
log.debug "garageDoorOpen event ${evt.name}:${evt.value} received" | |
// execute handler in one minutes from now | |
runIn(60*closeInMinutes, closeGarageDoor) | |
} | |
def garageDoorClosed(evt) { | |
log.debug "garageDoorClosed event ${evt.name}:${evt.value} received" | |
// Unschedule event | |
unschedule(closeGarageDoor) | |
} | |
def closeGarageDoor() { | |
garageSwitch.on() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment