forked from ekimmagrann/hubitat-elkm1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Elk-M1-Driver-Custom.groovy
126 lines (114 loc) · 4.69 KB
/
Elk-M1-Driver-Custom.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***********************************************************************************************************************
*
* A Hubitat Child Driver supporting Elk M1 Custom
*
* 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: Elk M1 Driver Custom
*
*** See Release Notes at the bottom***
***********************************************************************************************************************/
public static String version() { return "v0.1.1" }
metadata {
definition(name: "Elk M1 Driver Custom", namespace: "captncode", author: "captncode") {
capability "Actuator"
capability "Refresh"
command "setCustomTime", [[name: "hours*", description: "0 - 23", type: "NUMBER"],
[name: "minutes*", description: "0 - 59", type: "NUMBER"]]
command "setCustomValue", [[name: "value*", description: "0 - 65535", type: "NUMBER"]]
attribute "custom", "string"
attribute "format", "enum", ["number", "time of day", "timer"]
}
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}"
}
hubitat.device.HubAction installed() {
log.warn device.label + " Installed..."
device.updateSetting("txtEnable", [type: "bool", value: true])
refresh()
}
void uninstalled() {
}
hubitat.device.HubAction refresh() {
parent.sendMsg(parent.refreshCustomValue(getUnitCode()))
}
int getUnitCode() {
String DNID = device.deviceNetworkId
return DNID.substring(DNID.length() - 2).take(2).toInteger()
}
void parse(Map description) {
int value = description.value
String format = description.format
String valueStr = value.toString()
String formatStr
if (format == "1") {
format = "timer"
} else if (format == "2") {
int hours = value / 256
int minutes = value % 256
valueStr = String.format("%02d", hours) + ":" + String.format("%02d", minutes)
format = "time of day"
} else {
format = "number"
}
if (device.currentState("custom")?.value == null || device.currentState("custom").value != valueStr) {
String descriptionText = "${device.label} is ${valueStr}"
if (txtEnable)
log.info descriptionText
sendEvent(name: "custom", value: valueStr, descriptionText: descriptionText)
}
if (device.currentState("format")?.value == null || device.currentState("format").value != format) {
String descriptionText = "${device.label} format is ${format}"
if (txtEnable)
log.info descriptionText
sendEvent(name: "format", value: format, descriptionText: descriptionText)
}
}
void parse(List description) {
log.warn device.label + " parse(List description) received ${description}"
}
hubitat.device.HubAction setCustomTime(BigDecimal hours, BigDecimal minutes) {
if (device.currentState("format")?.value == null || device.currentState("format").value == "time of day") {
parent.sendMsg(parent.setCustomTime(getUnitCode(), hours, minutes))
} else {
log.warn device.label + " value must be in number format"
}
}
hubitat.device.HubAction setCustomValue(BigDecimal value) {
if (device.currentState("format")?.value == null || device.currentState("format").value != "time of day") {
parent.sendMsg(parent.setCustomValue(getUnitCode(), value))
} else {
log.warn device.label + " value must be in time of day format"
}
}
/***********************************************************************************************************************
*
* Release Notes (see Known Issues Below)
*
* 0.1.1
* Strongly typed commands
* Changed format to ENUM so the values can be selected in the rules engine.
*
* 0.1.0
* New child driver to Elk M1 Custom
*
***********************************************************************************************************************/
/***********************************************************************************************************************
*
* Feature Request & Known Issues
* I - The Elk M1 panel does not automatically report when a custom value changes. This could cause the custom device
* within Hubitat to go out of sync. The Refresh command can be used to update the value in this case.
*
***********************************************************************************************************************/