-
Notifications
You must be signed in to change notification settings - Fork 7
/
st_foscam_mode_alarm.groovy
71 lines (64 loc) · 1.85 KB
/
st_foscam_mode_alarm.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
/**
* Foscam Mode Alarm
*
* Copyright 2014 skp19
*
*/
definition(
name: "Foscam Mode Alarm",
namespace: "skp19",
author: "skp19",
description: "Enables Foscam alarm when the mode changes to the selected mode.",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]")
preferences {
section("When the mode changes to...") {
input "alarmMode", "mode", multiple: true
}
section("Enable these Foscam alarms...") {
input "cameras", "capability.imageCapture", multiple: true
input "notify", "bool", title: "Notification?"
}
section("Only between these times...") {
input "startTime", "time", title: "Start Time", required: false
input "endTime", "time", title: "End Time", required: false
}
}
def installed() {
subscribe(location, checkTime)
}
def updated() {
unsubscribe()
subscribe(location, checkTime)
}
def modeAlarm(evt) {
if (evt.value in alarmMode) {
log.trace "Mode changed to ${evt.value}. Enabling Foscam alarm."
cameras?.alarmOn()
sendMessage("Foscam alarm enabled")
}
else {
log.trace "Mode changed to ${evt.value}. Disabling Foscam alarm."
cameras?.alarmOff()
sendMessage("Foscam alarm disabled")
}
}
def checkTime(evt) {
if(startTime && endTime) {
def currentTime = new Date()
def startUTC = timeToday(startTime)
def endUTC = timeToday(endTime)
if((currentTime > startUTC && currentTime < endUTC && startUTC < endUTC) || (currentTime > startUTC && startUTC > endUTC) || (currentTime < endUTC && endUTC < startUTC)) {
modeAlarm(evt)
}
}
else {
modeAlarm(evt)
}
}
def sendMessage(msg) {
if (notify) {
sendPush msg
}
}