1
+ /**
2
+ * Copyright 2017 SmartThings
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at:
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11
+ * for the specific language governing permissions and limitations under the License.
12
+ *
13
+ * Everspring ST814 Temperature/Humidity Sensor
14
+ *
15
+ * Author: SmartThings
16
+ * Date: 2017-3-4
17
+ */
18
+
19
+ metadata {
20
+ definition (name : " Everspring ST814" , namespace : " smartthings" , author : " SmartThings" ) {
21
+ capability " Temperature Measurement"
22
+ capability " Relative Humidity Measurement"
23
+ capability " Battery"
24
+ capability " Configuration"
25
+ capability " Sensor"
26
+ capability " Health Check"
27
+
28
+ fingerprint mfr :" 0060" , prod :" 0006" , model :" 0001"
29
+ }
30
+
31
+ simulator {
32
+ for ( int i = 0 ; i <= 100 ; i + = 20 ) {
33
+ status " temperature ${ i} F" : new physicalgraph.zwave.Zwave (). sensorMultilevelV2. sensorMultilevelReport(
34
+ scaledSensorValue : i, precision : 1 , sensorType : 1 , scale : 1 ). incomingMessage()
35
+ }
36
+
37
+ for ( int i = 0 ; i <= 100 ; i + = 20 ) {
38
+ status " humidity ${ i} %" : new physicalgraph.zwave.Zwave (). sensorMultilevelV2. sensorMultilevelReport(
39
+ scaledSensorValue : i, precision : 0 , sensorType : 5 ). incomingMessage()
40
+ }
41
+
42
+ for ( int i = 0 ; i <= 100 ; i + = 20 ) {
43
+ status " battery ${ i} %" : new physicalgraph.zwave.Zwave (). batteryV1. batteryReport(
44
+ batteryLevel : i). incomingMessage()
45
+ }
46
+ status " wakeup" : " command: 8407, payload: "
47
+ }
48
+
49
+ tiles(scale : 2 ) {
50
+ valueTile(" temperature" , " device.temperature" , inactiveLabel : false , width : 2 , height : 2 ) {
51
+ state " temperature" , label :' ${currentValue}°' ,
52
+ backgroundColors :[
53
+ [value : 32 , color : " #153591" ],
54
+ [value : 44 , color : " #1e9cbb" ],
55
+ [value : 59 , color : " #90d2a7" ],
56
+ [value : 74 , color : " #44b621" ],
57
+ [value : 84 , color : " #f1d801" ],
58
+ [value : 92 , color : " #d04e00" ],
59
+ [value : 98 , color : " #bc2323" ]
60
+ ]
61
+ }
62
+ valueTile(" humidity" , " device.humidity" , inactiveLabel : false , width : 2 , height : 2 ) {
63
+ state " humidity" , label :' ${currentValue}% humidity' , unit :" "
64
+ }
65
+ valueTile(" battery" , " device.battery" , inactiveLabel : false , decoration : " flat" , width : 2 , height : 2 ) {
66
+ state " battery" , label :' ${currentValue}% battery' , unit :" "
67
+ }
68
+
69
+ main( [" temperature" , " humidity" ] )
70
+ details( [" temperature" , " humidity" , " battery" ] )
71
+ }
72
+ }
73
+
74
+ def updated () {
75
+ state. configured = false
76
+ }
77
+
78
+ def parse (String description ) {
79
+ def result = []
80
+
81
+ def cmd = zwave. parse(description, [0x20 : 1 , 0x31 : 2 , 0x70 : 1 , 0x71 : 1 , 0x80 : 1 , 0x84 : 2 , 0x85 : 2 ])
82
+
83
+ if (cmd) {
84
+ result = zwaveEvent(cmd)
85
+ }
86
+
87
+ if (result instanceof List ) {
88
+ log. debug " Parsed '$description ' to ${ result.collect { it.respondsTo("toHubAction") ? it.toHubAction() : it }} "
89
+ } else {
90
+ log. debug " Parsed '$description ' to ${ result} "
91
+ }
92
+ return result
93
+ }
94
+
95
+ def zwaveEvent (physicalgraph.zwave.commands.wakeupv2.WakeUpNotification cmd ) {
96
+ def result = [
97
+ createEvent(descriptionText : " ${ device.displayName} woke up" , isStateChange : false )
98
+ ]
99
+ if (state. configured) {
100
+ result << response(zwave. batteryV1. batteryGet())
101
+ } else {
102
+ result << response(configure())
103
+ }
104
+ return result
105
+ }
106
+
107
+ def zwaveEvent (physicalgraph.zwave.commands.alarmv1.AlarmReport cmd ) {
108
+ if (cmd. alarmType == 1 && cmd. alarmType == 0xFF ) {
109
+ return createEvent(descriptionText : " ${ device.displayName} battery is low" , isStateChange : true )
110
+ } else if (cmd. alarmType == 2 && cmd. alarmLevel == 1 ) {
111
+ return createEvent(descriptionText : " ${ device.displayName} powered up" , isStateChange : false )
112
+ }
113
+ }
114
+
115
+ def zwaveEvent (physicalgraph.zwave.commands.sensormultilevelv2.SensorMultilevelReport cmd ) {
116
+
117
+ def map = [:]
118
+ switch ( cmd. sensorType ) {
119
+ case 1 :
120
+ /* temperature */
121
+ def cmdScale = cmd. scale == 1 ? " F" : " C"
122
+ map. value = convertTemperatureIfNeeded(cmd. scaledSensorValue, cmdScale, cmd. precision)
123
+ map. unit = getTemperatureScale()
124
+ map. name = " temperature"
125
+ break
126
+ case 5 :
127
+ /* humidity */
128
+ map. value = cmd. scaledSensorValue. toInteger(). toString()
129
+ map. unit = " %"
130
+ map. name = " humidity"
131
+ break
132
+ }
133
+
134
+ return createEvent(map)
135
+ }
136
+
137
+ def zwaveEvent (physicalgraph.zwave.commands.batteryv1.BatteryReport cmd ) {
138
+ def map = [ name : " battery" , unit : " %" ]
139
+ if (cmd. batteryLevel == 0xFF ) {
140
+ map. value = 1
141
+ map. descriptionText = " ${ device.displayName} has a low battery"
142
+ map. isStateChange = true
143
+ } else {
144
+ map. value = cmd. batteryLevel
145
+ }
146
+
147
+ def response_cmds = []
148
+ if (! currentTemperature) {
149
+ response_cmds << zwave. sensorMultilevelV2. sensorMultilevelGet(). format()
150
+ response_cmds << " delay 1000"
151
+ }
152
+ response_cmds << zwave. wakeUpV1. wakeUpNoMoreInformation(). format()
153
+
154
+ return [createEvent(map), response(response_cmds)]
155
+ }
156
+
157
+ def zwaveEvent (physicalgraph.zwave.commands.multichannelv3.MultiChannelCmdEncap cmd ) {
158
+ def result = null
159
+ def encapsulatedCommand = cmd. encapsulatedCommand([0x20 : 1 , 0x31 : 2 , 0x70 : 1 , 0x71 : 1 , 0x80 : 1 , 0x84 : 2 , 0x85 : 2 ])
160
+ log. debug (" Command from endpoint ${ cmd.sourceEndPoint} : ${ encapsulatedCommand} " )
161
+ if (encapsulatedCommand) {
162
+ result = zwaveEvent(encapsulatedCommand)
163
+ }
164
+ result
165
+ }
166
+
167
+ def zwaveEvent (physicalgraph.zwave.Command cmd ) {
168
+ log. debug " Unhandled: ${ cmd.toString()} "
169
+ return [:]
170
+ }
171
+
172
+ def configure () {
173
+ state. configured = true
174
+ sendEvent(name : " checkInterval" , value : 8 * 60 * 60 + 2 * 60 , displayed : false , data : [protocol : " zwave" , hubHardwareId : device. hub. hardwareID])
175
+ delayBetween([
176
+ // Auto report time interval in minutes
177
+ zwave. configurationV1. configurationSet(parameterNumber : 6 , size : 2 , scaledConfigurationValue : 20 ). format(),
178
+
179
+ // Auto report temperature change threshold
180
+ zwave. configurationV1. configurationSet(parameterNumber : 7 , size : 1 , scaledConfigurationValue : 2 ). format(),
181
+
182
+ // Auto report humidity change threshold
183
+ zwave. configurationV1. configurationSet(parameterNumber : 8 , size : 1 , scaledConfigurationValue : 5 ). format(),
184
+
185
+ // Get battery – report triggers WakeUpNMI
186
+ zwave. batteryV1. batteryGet(). format()
187
+ ])
188
+ }
0 commit comments