-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgate_opener.groovy
103 lines (91 loc) · 3 KB
/
gate_opener.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Gate Opener SmartApp for eWeLink Gate Opener
*
* Copyright 2023 Will Cole
*
* 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: "Gate Opener Control",
namespace: "triosniolin",
author: "Will Cole",
description: "Control eWeLink Gate Opener",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]")
preferences {
page(name: "page1")
page(name: "page2")
page(name: "page3")
page(name: "lastpage")
}
def page1() {
dynamicPage(name: "page1", title: "Select virtual switch:", nextPage: "page2", uninstall:true) {
section("Switch to act as input to gate opener logic") {
input "switch1", "capability.switch",
multiple: false,
title: "Virtual switch",
required: true,
}
}
}
def page2() {
dynamicPage(name: "page2", title: "Select eWeLink Opener Output:", nextPage: "page2", uninstall:true) {
section("eWeLink switch (or other relay output)") {
input "switch2", "capability.switch",
multiple: false,
title: "Output switch",
required: true,
}
}
}
def page3() {
dynamicPage(name: "page2", title: "Select eWeLink Opener Output:", nextPage: "page2", uninstall:true) {
section("Seconds to hold switch output on") {
input "seconds", "number",
title: "Seconds to hold output on (1-15)",
range: "1..15",
defaultValue: "3",
required: true,
submitOnChange: true
}
}
}
def lastpage() {
dynamicPage(name: "lastpage", title: "Name app and configure modes", install: true, uninstall: true) {
section([mobileOnly:true]) {
label title: "Assign a name", required: false
mode title: "Set for specific mode(s)", required: false
}
}
}
def installed(){
if (switch1) {
subscribe (switch1, "switch.on", switch1Handler)
}
log.info "subscribed to all of switches events"
}
def updated()
{
unsubscribe()
if (switch1) {
subscribe (switch1, "switch.on", switch1Handler)
}
log.info "subscribed to all of switches events"
}
def switch1Handler(evt){
log.info "switch1Handler Event: ${evt.value}"
switch2.on()
pause(seconds * 1000)
switch1.off()
switch2.off()
}