-
Notifications
You must be signed in to change notification settings - Fork 2
/
virtual-contact-switch.groovy
62 lines (54 loc) · 1.37 KB
/
virtual-contact-switch.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
/*
* modified from cwwilson08's code for a settable delay for off (button like)
* opens contact when switched on
* logs a message when triggered
*/
metadata {
definition (name: "Virtual Contact/Switch", namespace: "ccoupe", author: "Many") {
capability "Initialize"
capability "Sensor"
capability "ContactSensor"
capability "Switch"
attribute "switch","ENUM",["on","off"]
attribute "contact","ENUM",["close","open"]
}
}
preferences {
section {
input (
name: "AutoOff",
type: "bool",
title: "Enable auto off",
required: false,
displayDuringSetup: false,
defaultValue: false
)
input (
name: "OffMilli",
type: "number",
title: "Time to Off",
required: false,
displayDuringSetup: true,
defaultValue: 500,
description: "Milliseconds for turning off"
)
input("logEnable", "bool", title: "Enable logging", required: true, defaultValue: true)
}
}
def on() {
sendEvent(name: "contact", value: "open")
sendEvent(name: "switch", value: "on")
if (logEnable) log.info "Virtual Ct/Sw open/on"
if (AutoOff) {
runInMillis(settings.OffMilli, off)
}
}
def off() {
sendEvent(name: "contact", value: "closed")
sendEvent(name: "switch", value: "off")
if (logEnable) log.info "Virtual Ct/Sw closed/off"
}
def installed() {
}
def initialize() {
}