-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpool autofill ST
77 lines (64 loc) · 2.06 KB
/
pool autofill 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
metadata {
definition (name: "poolautofill", namespace: "brennonsapps", author: "bscuderi") {
capability "Actuator"
capability "Sensor"
capability "Polling"
capability "Refresh"
capability "switch"
attribute "gal", "number"
}
preferences {
input("token", "password", title: "Access Token")
input("deviceId", "text", title: "Device ID")
input name: "GallonsVar", type: "text", title: "Gallons Variable", required: true, defaultValue: "totalg1"
}
// tile definitions
tiles {
multiAttributeTile(name: "switch", type: "lighting", width: 4, height: 2, canChangeIcon: true) {
tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label: 'On', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#aaaaff"
attributeState "off", label: 'Off', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
tileAttribute("device.gal", key: "SECONDARY_CONTROL") {
attributeState "gal", label: '${currentValue} Gallons'
}
}
main "switch"
details(["switch", "gal", "refresh"])
}
}
def parse(String description) {
log.error "This device does not support incoming events"
return null
}
def on() {
put '1'
sendEvent(name: 'switch', value: 'on')
}
def off() {
put '0'
sendEvent(name: 'switch', value: 'off')
}
private put(relaystate) {
//particle API Call
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceId}/poolon",
body: [access_token: token, command: relaystate],
) {response -> log.debug (response.data)}
}
private getGallons() {
def closure = { response ->
log.debug "Gallons request was successful, $response.data"
sendEvent(name: "gal", value: response.data.result)
}
httpGet("https://api.particle.io/v1/devices/${deviceId}/${GallonsVar}?access_token=${token}", closure)
}
def updated() {
log.debug "Updated !"
state.gal = 1
log.debug "device.gal: ${device.gal}"
}
def refresh() {
log.debug "Executing 'refresh'"
getGallons()
}