forked from Lcstyle/HBBWASpaManager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HBBWASpaManager_Thermostat_Device.groovy
182 lines (155 loc) · 6.09 KB
/
HBBWASpaManager_Thermostat_Device.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Hubitat BWA Spa Manager
* -> Thermostat Device Driver
*
* Copyright 2023-2024 Kurt Sannders
* based on work Copyright 2020 Richard Powell that he did for Hubitat
*
* Copyright 2020 Richard Powell
*
* 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.
*/
#include kurtsanders.SanderSoft-Library
#include kurtsanders.BWA-Library
import groovy.transform.Field
@Field static String THERMOSTAT_CHILD_DEVICE_NAME_PREFIX = "HB BWA SPA Thermostat"
@Field static String PARENT_DEVICE_NAME = "HB BWA SPA Thermostat"
@Field static final String VERSION = "1.3.0"
@Field static final List THERMO_STAT_MODES = ["heat","Off"]
@Field static final List THERMO_STAT_OPERATING_STATE = ["heating", "idle", "pending heat"]
@Field static final List THERMO_STAT_FAN_MODES = ["off", "circulate"]
metadata {
definition (name: THERMOSTAT_CHILD_DEVICE_NAME_PREFIX, namespace: NAMESPACE, author: "Kurt Sanders") {
capability "Thermostat"
capability "Refresh"
capability "Actuator"
capability "Sensor"
capability "Initialize"
capability "ThermostatHeatingSetpoint"
capability "ThermostatCoolingSetpoint"
capability "ThermostatSetpoint"
capability "TemperatureMeasurement"
capability "ThermostatMode"
capability "ThermostatOperatingState"
attribute "supportedThermostatFanModes", 'JSON_OBJECT'
attribute "supportedThermostatModes", 'JSON_OBJECT'
attribute "thermostatFanMode", "enum", THERMO_STAT_FAN_MODES
attribute "thermostatOperatingState", "enum", THERMO_STAT_OPERATING_STATE
attribute "thermostatMode", "enum", THERMO_STAT_MODES
command "setHeatingSetpoint", [[name:'Heating Setpoint*', type:'NUMBER', description:'Heating setpoint temperature']]
command "setCoolingSetpoint", [[name:'Cooling Setpoint*', type:'NUMBER', description:'Cooling setpoint temperature']]
command "setThermostatFanMode", [[name: 'Fan Mode*', type: 'ENUM', constraints: THERMO_STAT_FAN_MODES]]
command "setThermostatMode", [[name: 'Thermostat Mode*', type: 'ENUM', constraints: THERMO_STAT_MODES]]
command "getTemperatureRange"
preferences {
input "defaultOnTemperature", "number", title: "Default Temperature When Turned On", range: getTemperatureRange()
}
}
}
void initialize() {
installed()
}
void updated() {
logInfo "Preferences Updated..."
checkLogLevel()
}
void installed() {
String stmJSON = new groovy.json.JsonBuilder(THERMO_STAT_MODES).toString()
sendEvent(name: "supportedThermostatModes", value: stmJSON, displayed: false, isStateChange: true)
stmJSON = new groovy.json.JsonBuilder(THERMO_STAT_FAN_MODES).toString()
sendEvent(name: "supportedThermostatFanModes", value: stmJSON, displayed: false, isStateChange: true)
sendEvent(name: "thermostatFanMode", value: "circulate")
sendEvent(name: "thermostatMode", value: "heat")
}
void sendEvents(List<Map> events) {
events.each {
sendEvent(name: it.name, value: it.value)
}
}
void sendEventsWithStateChange(List<Map> events) {
events.each {
sendEvent(name: it.name, value: it.value, isStateChange: true)
}
}
void sendEventsWithUnits(List<Map> events) {
events.each {
sendEvent(name: it.name, value: it.value, unit: it.unit)
}
}
void auto() {
notImplemennted("auto()")
}
void setThermostatMode(mode) {
logDebug "==> setThermostatMode(${mode})"
sendEvent([name: "thermostatMode", value: "heat"])
// sendEvent([name: "thermostatMode", value: mode])
}
void setCoolingSetpoint(setpoint) {
notImplemennted("setCoolingSetpoint(setpoint)= ${setpoint}")
// logDebug "==> setCoolingSetpoint(setpoint)= ${setpoint}"
// sendEvent(name: "coolingSetpoint", value: setpoint)
// logInfo "Waiting 5 secs to lower updateThermostatSetpoint to ${setpoint}..."
// runIn(5, "updateThermostatSetpoints", [overwrite: true, data: setpoint])
}
void setHeatingSetpoint(setpoint) {
logDebug "==> setHeatingSetpoint(setpoint)= ${setpoint}"
logInfo "Waiting 5 secs to raise updateThermostatSetpoint to ${setpoint}..."
runIn(5, "updateThermostatSetpoints", [overwrite: true, data: setpoint])
}
def updateThermostatSetpoints(setpoint) {
logInfo "updateThermostatSetpoints(${setpoint})"
sendEvent(name: "heatingSetpoint", value: setpoint)
parent?.sendCommand("SetTemp", device.currentValue("temperatureScale") == "C" ? setpoint * 2 : setpoint)
runIn(5, "refresh")
}
def getTemperatureRange() {
return "(26.5..104)"
}
def refresh() {
parent?.refresh()
}
void fanOn(){
notImplemennted("fanOn")
}
void off() {
notImplemennted("off")
}
void emergencyHeat() {
logInfo "Emergency Heat Requested"
setThermostatMode("heat")
}
void fanCirculate() {
notImplemennted("fanCirculate")
}
void cool() {
notImplemennted("cool")
}
void heat() {
setThermostatMode("heat")
}
void setThermostatFanMode(fanmode){
notImplemennted("setThermostatFanMode(${fanmode})")
}
void fanAuto() {
notImplemennted("fanAuto")
}
void notImplemennted(functionnName) {
logInfo "The '${functionnName}' device command is not applicable to the Spa Thermostat mode"
}
//Additional Preferences
preferences {
//Logging Options
input name: "logLevel", type: "enum", title: fmtTitle("Logging Level"),
description: fmtDesc("Logs selected level and above"), defaultValue: 0, options: LOG_LEVELS
input name: "logLevelTime", type: "enum", title: fmtTitle("Logging Level Time"),
description: fmtDesc("Time to enable Debug/Trace logging"),defaultValue: 0, options: LOG_TIMES
//Help Link
input name: "helpInfo", type: "hidden", title: fmtHelpInfo("Community Link")
}