Skip to content

alertR: rule engine

Foreword and interesting links

alertR is a project of mine which I started in August 2014. It is an unified alerting system which is based on a client/server model. The main part is written in Python and is published as Free-Software. If you do not know this project yet, here are some interesting links:

* Github repository
* Github wiki for documentations
* Blog article: Introducing alertR: Open-Source alerting system (with video)
* Blog article: alertR: dbus and xbmc notification client (with video)

Introduction and motivation

Since I implemented alertR inside my home, I still had motion sensors connected to a Raspberry Pi which were not managed by alertR. The reason of this was that first one of the two motion sensors had to trigger and then in a time frame of 5 seconds the next one has to trigger before an event should happen.

Because of this I started to implement a "rule engine" for alertR over the Christmas time. And finally it is finished.


Before I tell you the details about the rule engine, I want to show you that the rule engine works via a short video. Please have the subtitles activated to get a description of what I am doing and what is happening.

How does it work?

As you could see/read in the video I used the two motion sensors to start the media center in my living room and to let it play a specific radio channel. This should only happen during the week (not on a weekend) and only at the time when I have to stand up to go to work. The media center has speakers in the living room, kitchen and bathroom. So I can hear the music inside my apartment while I prepare my self to leave for work.

Now with the rule engine alertR can manage this setting too. The rule engine is able to chain rules together so you can have a sequence of rules which have to be fulfilled in a specific order and in a specific time frame. One rule can consist of different rule elements that are bound together by a boolean operator.

Note at this point that this rule engine is event driven. This means that it is only checked if a sensor event is sent to the server (this also means that a rule must have at least one sensor in it). It does not work if you have a rule configured which just checks the time (if you want something like this, use cron as a sensor) or if you only have one sensor in this rule which state is negated by a NOT.

Here is a list of the elements that are supported (at the time of writing this) by the rule engine:

* sensor - this rule element represents a sensor of the alertR system and is evaluated if a sensor trigger event is sent to the server
* boolean - this is a boolean operator to form a complex rule with the given rule elements (supported operators are: AND, OR and NOT)
* weekday - this element represents the day of the week (Monday - Sunday)
* monthday - this element represents the day of the month (1-31)
* hour - this element represents the hour time frame in which this element is set to triggered
* minute - this element represents the minute time frame in which this element is set to triggered
* second - this element represents the second time frame in which this element is set to triggered

With this rule elements you can form complex rules with your sensors. For example you can combine the boolean element AND with hour, minute and sensor to only trigger this rule when a specific sensor triggers in a specific time window.

A practical example would be a sensor at your door and a motion sensor outside the door. Every time you come home the motion sensor is triggered first and then the door sensor (since you have to walk to the door before you can open it). When this rule triggers, you can for example start the media center with the music you like.

Additionally, the rules can have a counter if you want a specific rule only trigger once every 24 hours or something like that. This is also used by me with the two motion sensors to start the media center in the living room. I only want to trigger it once a day since I only stand up and go to work once a day ;-)

Final words

The rule engine is a powerful tool when you use sensors in your home. With it you can perform complex checks before an actual event should trigger. At the moment I only use it for the described scenario above. But I think it will also have a lot of other fields where it can be handy.


No Trackbacks


Display comments as Linear | Threaded

Gabriele on :

This is a very interesting project. Congratulations. However in trying to run the I get the following error message:
urwid.widget.WidgetError: Cannot pack (maxcol,) size, this is not a flow widget:
I'm new to python and also in urwid. Could you please sugest me what is going wrong ?

sqall on :


can you please use the "Issues" function on github for this:
This way it is easier for me to keep track of it and to talk to you. At the moment this looks like something of a version issue, but I need more information.


The author does not allow comments to this entry

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
Form options

Submitted comments will be subject to moderation before being displayed.