-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpooltemp ST
82 lines (64 loc) · 2.08 KB
/
pooltemp ST
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
/**
* Particle Pool Temp Sensor
*
* Author: Brennon Scuderi
*
*
*
*
*/
preferences {
input name: "deviceId", type: "text", title: "Device ID", required: true
input name: "token", type: "password", title: "Access Token", required: true
input name: "TemperatureVar", type: "text", title: "Temperature Variable", required: true, defaultValue: "PoolTemp"
}
metadata {
definition (name: "Particle Pool Temp Sensor", author: "Brennon Scuderi") {
capability "Polling"
capability "Sensor"
capability "Refresh"
capability "Temperature Measurement"
attribute "temperature", "number"
}
tiles(scale: 2) {
valueTile("temperature", "device.temperature", width: 2, height: 2) {
state("temperature", label:'${currentValue}°', unit:"F",
backgroundColors:[
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
}
}
// handle commands
def poll() {
log.debug "Executing 'poll'"
getAll()
}
def refresh() {
log.debug "Executing 'refresh'"
getAll()
}
def getAll() {
getTemperature()
}
def parse(String description) {
def pair = description.split(":")
createEvent(name: pair[0].trim(), value: pair[1].trim())
}
private getTemperature() {
def closure = { response ->
log.debug "Temperature request was successful, $response.data"
sendEvent(name: "temperature", value: response.data.result)
}
httpGet("https://api.particle.io/v1/devices/${deviceId}/${TemperatureVar}?access_token=${token}", closure)
}