Logical Pattern
Logical patterns match events that arrive in temporal order and correlate them with logical relationships such as and, or and not.
Refer the Siddhi query guide for more information.
define stream RegulatorStateChangeStream(deviceID long,
roomNo int, tempSet double, action string);
define stream RoomKeyStream(deviceID long, roomNo int,
action string);
@sink(type='log')
define stream RegulatorActionStream(roomNo int, action string);
from every e1=RegulatorStateChangeStream[ action == 'on' ]
-> e2=RoomKeyStream
[ e1.roomNo == roomNo and action == 'removed' ]
or e3=RegulatorStateChangeStream
[ e1.roomNo == roomNo and action == 'off']
select e1.roomNo,
ifThenElse( e2 is null, 'none', 'stop' ) as action
having action != 'none'
insert into RegulatorActionStream;
|
Defines |
|
Defines |
|
|
|
Defines |
|
Sends a stop action on RegulatorActionStream stream, if a removed action is triggered in the RoomKeyStream stream before the regulator state changing to off which is notified RegulatorStateChangeStream stream |
|
|
|
Checks whether pattern triggered due to removal of room key. |
|
This application sends a stop action on the regulator if a removed action is triggered in the RoomKeyStream stream.
Input
First, below event is sent to
RegulatorStateChangeStream,[
10,5,30,on]Then, send below events are sent to
RoomKeyStream,[
10,5,removed]
Output
After processing the above input events, the event arriving at RegulatorActionStream will be as follows:
[5, stop]
