forked from ekimmagrann/hubitat-elkm1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Virtual Water Sensor.groovy
95 lines (87 loc) · 3.13 KB
/
Virtual Water Sensor.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
/***********************************************************************************************************************
*
* A Virtual Water Sensor.
*
* License:
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Name: Virtual Water Sensor
*
***********************************************************************************************************************/
public static String version() { return "v0.1.2" }
metadata {
definition(name: "Virtual Water Sensor", namespace: "captncode", author: "captncode", component: false) {
capability "WaterSensor"
command "dry"
command "wet"
}
preferences {
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
}
void updated() {
log.warn device.label + " Updated..."
log.warn "${device.label} description logging is ${txtEnable}"
}
void installed() {
log.warn "${device.label} Installed..."
device.updateSetting("txtEnable", [type: "bool", value: true])
}
void parse(String description) {
log.warn device.label + " parse(String description) not implemented"
}
void parse(List<Map> description) {
description.each {
if (device.currentState(it.name)?.value == null || device.currentState(it.name).value != it.value || it.isStateChange) {
Map eventMap = [:]
it.each { entry ->
eventMap[entry.key] = entry.value
}
if (eventMap.descriptionText == null)
eventMap.descriptionText = device.label + " " + eventMap.name + " is " + eventMap.value
else
eventMap.descriptionText = device.label + " " + eventMap.descriptionText
if (txtEnable)
log.info eventMap.descriptionText
sendEvent(eventMap)
}
}
}
void dry() {
if (device.currentState("water")?.value == null || device.currentState("water").value != "dry") {
String descriptionText = device.label + " sensor is dry"
if (txtEnable)
log.info descriptionText
sendEvent(name: "water", value: "dry", descriptionText: descriptionText)
}
}
void wet() {
if (device.currentState("water")?.value == null || device.currentState("water").value != "wet") {
String descriptionText = device.label + " sensor is wet"
if (txtEnable)
log.info descriptionText
sendEvent(name: "water", value: "wet", descriptionText: descriptionText)
}
}
/***********************************************************************************************************************
*
* Release Notes
*
* 0.1.2
* Fixed error when installed.
* Strongly typed commands.
* Improved descriptionText in event.
*
* 0.1.1
* Changed logging and events to only occur when state changes.
*
* 0.1.0
* New Virtual Water Sensor Driver.
*
***********************************************************************************************************************/