-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotvac-mqtt.rules
executable file
·97 lines (81 loc) · 3.4 KB
/
botvac-mqtt.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
import java.text.SimpleDateFormat
import java.util.Date
rule "Clean each morning"
when
Time cron "00 00 10 ? * *"
then
if (Vtl_Schedule_NoWork_Today.state == OFF) {
In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.postUpdate(2)
In_Entrence_Vacuum_SendCommand.sendCommand('clean')
}
end
//------------------------------------------ Device logic below
rule "Set vacuum clock"
when
Item In_Entrence_Vacuum_Clock changed
or
Time cron "00 00 09 ? * mon"
then
val SimpleDateFormat sdf = new SimpleDateFormat("'SetTime' 'Day' u 'Hour' HH 'Min' mm 'Sec' ss")
val String timestampString = sdf.format(new Date())
logInfo("hallis", timestampString)
publish("mosquitto","/home/entrence/vacuum/command", timestampString)
end
rule "Dim vacuum display"
when
Item In_Entrence_Vacuum_SendCommand changed to "stop"
or
Item In_Entrence_Vacuum_ChargingActive changed to CLOSED
then
if ((In_Entrence_Vacuum_SendCommand.state.toString == "stop") && (In_Entrence_Vacuum_ChargingActive.state == CLOSED)){
publish("mosquitto","/home/entrence/vacuum/command", "TestMode On")
Thread::sleep(500)
publish("mosquitto","/home/entrence/vacuum/command", "SetLED BacklightOff")
Thread::sleep(500)
publish("mosquitto","/home/entrence/vacuum/command", "TestMode Off")
}
end
rule "Start continous vacuuming"
when Item In_Entrence_Vacuum_SendCommand received command "clean"
then
In_Entrence_Vacuum_ConsequtiveCleaningCyclesCurrent.postUpdate(0)
if (In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.state == 0){
In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.postUpdate(1)
}
In_Entrence_Vacuum_ConsequtiveCleaningCyclesCurrent.postUpdate(In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.state)
end
rule "Started charging"
when Item In_Entrence_Vacuum_ChargingActive changed to CLOSED
then
if ((In_Entrence_Vacuum_SendCommand.state.toString == "clean") || (In_Entrence_Vacuum_SendCommand.state.toString == "clean_again")){
In_Entrence_Vacuum_ConsequtiveCleaningCyclesCurrent.postUpdate((In_Entrence_Vacuum_ConsequtiveCleaningCyclesCurrent.state as Number) - 1)
if (In_Entrence_Vacuum_ConsequtiveCleaningCyclesCurrent.state <= 0){
In_Entrence_Vacuum_SendCommand.sendCommand("dock")
} else {
In_Entrence_Vacuum_SendCommand.sendCommand("clean_again")
}
} else if (In_Entrence_Vacuum_SendCommand.state.toString == "dock"){
In_Entrence_Vacuum_SendCommand.sendCommand("stop")
In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.postUpdate(3)
}
end
rule "Dock hallis - already in dock"
when Item In_Entrence_Vacuum_SendCommand received command "dock"
then
if (In_Entrence_Vacuum_ChargingActive.state == CLOSED){
In_Entrence_Vacuum_SendCommand.sendCommand("stop")
In_Entrence_Vacuum_ConsequtiveCleaningCyclesStart.postUpdate(3)
}
end
rule "Vacuum error"
when
Item In_Entrence_Vacuum_Error received command
or
Item In_Entrence_Vacuum_Error received update
then
if ((In_Entrence_Vacuum_Error.state == null) || (In_Entrence_Vacuum_Error.state == NULL) || (In_Entrence_Vacuum_Error.state == "")){
In_Entrence_Vacuum_Error_Show.sendCommand(OFF)
} else {
In_Entrence_Vacuum_Error_Show.sendCommand(ON)
}
end