-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac.rules
executable file
·84 lines (72 loc) · 2.04 KB
/
ac.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
rule "AC System Start"
when
System started
then
ac_mode.postUpdate(1)
ac_temp.postUpdate(25)
ac_fan.postUpdate(3)
Arduino.sendCommand("$1,#")
end
rule "AC Poll Temp Humid"
when
Time cron "0 * * ? * *"
then
// ask for the temperatures if i-feel is turned on or every 20 minutes
if (ac_i_feel.state == ON || now.getMinuteOfHour % 20 == 0) {
Arduino.sendCommand("$1,#")
}
end
rule "AC Arduino message"
when
Item Arduino received update
then
var String json = Arduino.state.toString
var temp = transform("JSONPATH", "$.temperature", json)
if (temp != null) {
livingTemp01.postUpdate(temp)
if (ac_i_feel.state == ON) {
// +0.5 for rounding
// +0.4 faster response (-0.4 for heating)
var i_feel_offset = 0.4
if (ac_mode.state == 2) {
i_feel_offset = -0.4
}
var String arduino_cmd = "$2,0," + ac_mode.state + "," + ac_fan.state + ",1,1," + (Float::parseFloat(temp) + 0.5 + i_feel_offset).intValue + ",#"
Arduino.sendCommand(arduino_cmd)
}
}
var humid = transform("JSONPATH", "$.humidity", json)
if (humid != null) {
livingHum01.postUpdate(humid)
}
var st = transform("JSONPATH", "$.ac_state", json)
if (st != null) {
ac_state.postUpdate(st)
}
end
rule "AC Air Conditioner update"
when
Item ac_power received command or
Item ac_mode received update or
Item ac_fan received update or
Item ac_i_feel changed or
Item ac_temp received update
then
var String arduino_cmd = "$2,"
if (receivedCommand == ON || ac_state.state == 1) {
if (receivedCommand == ON) {
arduino_cmd += "1,"
ac_i_feel.state = OFF
} else {
arduino_cmd += "0,"
}
arduino_cmd += ac_mode.state + "," + ac_fan.state + "," + "0" + ","
if (ac_i_feel.state == ON) {
arduino_cmd += "1,"
} else {
arduino_cmd += "0,"
}
arduino_cmd += ac_temp.state + ",#"
Arduino.sendCommand(arduino_cmd)
}
end