-
Notifications
You must be signed in to change notification settings - Fork 4
/
dyson438.rules
146 lines (142 loc) · 5.66 KB
/
dyson438.rules
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
import java.text.SimpleDateFormat
import java.util.TimeZone
// Rules for Dyson Pure Cool Link (438)
var SimpleDateFormat simpleDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")
// Start of STATE-SET msg
val String startStateSetCmdStr = "{\"msg\":\"STATE-SET\",\"time\":"
// Variable to store String used as command
var String cmdStr
// TOPIC "438/<id>/status/current" ############################################
// msg "ENVIRONMENTAL-CURRENT-SENSOR-DATA" ############
// msg "CURRENT-STATE" ################################
// msg "STATE-CHANGE" #################################
rule "438/<id>/status/current"
when
Item Dyson438_Topic_Status_Current received update
then
val String content = Dyson438_Topic_Status_Current.state.toString()
val String msg = transform("JSONPATH", "$.msg", content)
if (msg == "ENVIRONMENTAL-CURRENT-SENSOR-DATA") {
val String tact_str = transform("JSONPATH", "$.data.tact", content)
if (tact_str != "OFF") {
var double tact = Float.parseFloat(tact_str)
tact = (tact - 2731.5)/10
postUpdate(Dyson438_Tact, tact as Number)
}
val String hact_str = transform("JSONPATH", "$.data.hact", content)
if (hact_str != "OFF") {
val int hact = Integer.parseInt(hact_str)
postUpdate(Dyson438_Hact, hact as Number)
}
} else if (msg == "CURRENT-STATE") {
if (transform("JSONPATH", "$.product-state.fpwr", content) == "ON") {
postUpdate(Dyson438_Fpwr, ON)
} else {
postUpdate(Dyson438_Fpwr, OFF)
}
if (transform("JSONPATH", "$.product-state.auto", content) == "ON") {
postUpdate(Dyson438_Auto, ON)
} else {
postUpdate(Dyson438_Auto, OFF)
}
if (transform("JSONPATH", "$.product-state.rhtm", content) == "ON") {
postUpdate(Dyson438_Rhtm, ON)
} else {
postUpdate(Dyson438_Rhtm, OFF)
}
if (transform("JSONPATH", "$.product-state.oson", content) == "ON") {
postUpdate(Dyson438_Oson, ON)
} else {
postUpdate(Dyson438_Oson, OFF)
}
if (transform("JSONPATH", "$.product-state.nmod", content) == "ON") {
postUpdate(Dyson438_Nmod, ON)
} else {
postUpdate(Dyson438_Nmod, OFF)
}
if (transform("JSONPATH", "$.product-state.fnst", content) == "FAN") {
postUpdate(Dyson438_Fnst, 1)
} else {
postUpdate(Dyson438_Fnst, 0)
}
val String fnsp = transform("JSONPATH", "$.product-state.fnsp", content)
if (fnsp == "AUTO") {
postUpdate(Dyson438_Fnsp, 11 as Number)
} else {
postUpdate(Dyson438_Fnsp, Integer.parseInt(fnsp) as Number)
}
} else if (msg == "STATE-CHANGE") {
if (transform("JSONPATH", "$.product-state.fpwr[1]", content) == "ON") {
postUpdate(Dyson438_Fpwr, ON)
} else {
postUpdate(Dyson438_Fpwr, OFF)
}
if (transform("JSONPATH", "$.product-state.auto[1]", content) == "ON") {
postUpdate(Dyson438_Auto, ON)
} else {
postUpdate(Dyson438_Auto, OFF)
}
if (transform("JSONPATH", "$.product-state.rhtm[1]", content) == "ON") {
postUpdate(Dyson438_Rhtm, ON)
} else {
postUpdate(Dyson438_Rhtm, OFF)
}
if (transform("JSONPATH", "$.product-state.oson[1]", content) == "ON") {
postUpdate(Dyson438_Oson, ON)
} else {
postUpdate(Dyson438_Oson, OFF)
}
if (transform("JSONPATH", "$.product-state.nmod[1]", content) == "ON") {
postUpdate(Dyson438_Nmod, ON)
} else {
postUpdate(Dyson438_Nmod, OFF)
}
if (transform("JSONPATH", "$.product-state.fnst[1]", content) == "FAN") {
postUpdate(Dyson438_Fnst, 1)
} else {
postUpdate(Dyson438_Fnst, 0)
}
val String fnsp = transform("JSONPATH", "$.product-state.fnsp[1]", content)
if (fnsp == "AUTO") {
postUpdate(Dyson438_Fnsp, 11 as Number)
} else {
postUpdate(Dyson438_Fnsp, Integer.parseInt(fnsp) as Number)
}
}
end
//#############################################################################
// REQUEST "438/<id>/command"##################################################
// msg "REQUEST-CURRENT-STATE" ########################
rule "Request Current State every 30 seconds"
when
Time cron "0/30 * * * * ?"
then
// Create current TimeStamp as UTC
simpleDF.setTimeZone(TimeZone.getTimeZone("UTC"))
val String timeStampUtc = simpleDF.format(new java.util.Date())
cmdStr = "{\"msg\":\"REQUEST-CURRENT-STATE\","
cmdStr = cmdStr + " \"time\":\"" + timeStampUtc + "Z\","
cmdStr = cmdStr + " \"mode-reason\": \"LAPP\" }"
Dyson438_Request.sendCommand(cmdStr)
end
// msg "SET-STATE" ####################################
rule "438/<id>/command SET-STATE fpwr"
when
Item Dyson438_Fpwr received command
then
// Create current TimeStamp as UTC
simpleDF.setTimeZone(TimeZone.getTimeZone("UTC"))
val String timeStampUtc = simpleDF.format(new java.util.Date())
// Cast fpwr to String representation
var String fpwr = "OFF"
switch receivedCommand {
case ON: fpwr = "ON"
case OFF: fpwr = "OFF"
}
// Create JSON for commanding and send it
cmdStr = startStateSetCmdStr + "\"" + timeStampUtc + "Z\","
cmdStr = cmdStr + "\"mode-reason\":\"LAPP\","
cmdStr = cmdStr + "\"data\":{\"fpwr\":\"" + fpwr + "\"}}"
Dyson438_Request.sendCommand(cmdStr)
end
//#############################################################################