I'd like to look into redesigning the Event Plug-in to make it better suited to handling complex events. In the current Event Plug-in, a complex event might need to be broken into several separate events.
Lets say, as an example, you would like to automate whether your lawn sprinklers should be On or Off. In this example, you have two sensor devices to help determine when to water your lawn. The first sensor, a rain sensor detects if it is currently raining. If is is raining the state of the sensor will be "Raining" and if it is not raining, the state will be "No Rain". The second sensor, a ground moisture sensor, detects the percentage of moisture in the ground.
In this example, you'd like the lawn to be watered only if the following conditions are satisfied:
- The time is between 0500-0659
- The rain sensor state is "No Rain"
- The moisture sensor state is 25% or less
- House mode is not Entertaining (you don't want to soak your guests)
Using the current Event Plug-in you would need to define six different events to manage your sprinklers. You need two events (one On and one Off) for each type of event that effects the sprinklers. Here are the six events, the event criteria are shown in parentheses:
- Event 1 - Time Based at 0500, turn on
(AND
(sprinkler state = "Off")
(moisture sensor state <= 25%)
(rain sensor state "No Rain")
(NOT
(house mode "Entertaining")
)
)
* ACTION: Turn the sprinklers on
- Event 2 - Time Based at 0700, turn off
(sprinkler state = "On" )
* ACTION: Turn the sprinklers off
- Event 3 - State Based, turn on
(AND
(sprinkler state = "Off")
(current time >= 0500)
(current time < 0700)
(moisture sensor state <= 25%)
(rain sensor state = "No Rain")
(NOT
(house mode "Entertaining")
)
)
* ACTION: Turn the sprinklers on
- Event 4 - State Based, turn off
(AND
(sprinkler state = "On")
(OR
(moisture sensor state > 25%)
(rain sensor state = "Raining")
)
)
* ACTION: Turn the sprinklers off
- Event 5 - House Mode Based, turn on
(AND
(sprinkler state = "Off")
(current time >= 0500)
(current time < 0700)
(moisture sensor state <= 25%)
(rain sensor state = "No Rain")
(NOT
(house mode "Entertaining")
)
)
* ACTION: Turn the sprinklers on
- Event 6 - House Mode Based, turn off
(AND
(sprinkler state = "On")
(house mode "Entertaining")
)
* ACTION: Turn the sprinklers off
As you can see, it takes a bit of thought to get this setup properly. This is due to the current implementation of the Event Plug-in only being able to act on single events. In this example, the individual events are Time, State, and House Mode.
An alternate implementation of the Event Plug-in could be less focused on the events that occur in the system and more focused on the overall state of the devices managed by LinuxMCE. In this implementation, instead of being tied to a specific event, you just define the conditions necessary for your sprinklers to be On or Off. To implement the example above only two rules are needed. This is much easier for a person to implement and understand.
- Rule 1 - Sprinklers auto-on
(AND
(sprinkers state off)
(current-time >= 0500)
(current-time < 0700)
(rain-sensor state "No Rain")
(moisture-sensor state <= 25%)
(NOT
(house-mode "Entertaining")
)
)
* ACTION: (sprinklers send-command "on")
- Rule 2 - Sprinklers auto-off
(AND
(sprinklers state on)
(OR
(current-time < 0500)
(current-time >= 0700)
(rain-sensor state "Raining")
(moisture-sensor state > 25%)
(house-mode "Entertaining")
)
)
* ACTION: (sprinklers send-command "Off")
Implementing an event plugin that is based on the overall state of the system can quickly become inefficient if the right algorithm is not used. You can immagine a nieve algorithm, checking each condition of each rule every time an event is fired, would bog down the system in a hurry. I'm proposing this plug-in be based on the Rete algorithm. You can read more about the
Rete algoritm on Wikipedia, but in a nutshell it is designed to efficiently handle this type of rule based logic. A C language public domain implementation of the Rete algorithm exists and is called
CLIPS (C Language Integrated Production System). I'd like to use CLIPS to implement a Rules-Base event plugin for LinuxMCE. I'd also like to re-do the web interface for events to make it work with this new implementation.
Is it alright if I implement a new Event Plug-in? Are there any other suggestions on how this should be done or features it should support?