Home‎ > ‎

How to Configure Rules


Rules allow you to easily define and customize how you want your sensor to work with the system. A rule is a set of conditions that,  when met, trigger and action. For example you may want the system to alert you if the temperature of your house reaches freezing, or is very hot. 


You don't need to worry about programming these rules, we have created an easy-to-use graphical tool for defining rules, as shown below.


Figure 1: An example of a rule for the alarm system

Make sure you are on the latest version of PrivateEyePi

Instruction on how to install the PrivateEyePi software on your Raspberry Pi can be found HERE.


Rules explained further


Rules are made up of Conditions and Actions:

 

If [CONDITION] Then [Action]

Examples of popular rules:

 - If Sensor Open And Sensor = Front Door Then Send Email

 - If Sensor Open And Sensor = Front Door Then Alarm

 - If Sensor Open And Sensor = Front Door And Hour Of Day is between 9 and 17 Then Alarm

 - If Sensor Open and Zone is Armed And Sensor = Front Door Then Alarm

 - If Sensor Value is between -10 and 0 And Sensor = Outside Temperature then Send Email

 - If Sensor is open for 5 minutes And Sensor = Garage Door Then Send Email

 - If Day Of Week = Friday and Hour Of Day = 17 Then Arm Zone Office

 - If Day Of Week = Monday and Hour Of Day = 9 Then Disarm Zone Office

Conditions

A condition is the part of the rule that needs to be met before action is taken.  Each condition within a rule is connected with every other condition within that rule with an AND operator (e.g. door open And Zone is armed). You can define an infinite amount of rules, but every rule can only have between 1 and 4 conditions. We have found that 4 conditions are ample, but could add more in the future if required. 

We currently support the following conditions (further described below):

 - Sensor

 - Zone is armed

 - Zone is not armed

 - Sensor open

 - Sensor closed

 - Sensor value

 - Rule delay

 - Sensor is closed for x minutes

 - Day of week

 - Hour of day

 

  Sensor

The sensor condition is where you specify which sensor you wish to apply the rule to. Every rule must be associated with a sensor.

 

  Zone is armed, zone is not armed

These conditions will be met if the zone(s) to which the sensor is linked are either armed or disarmed.

 

  Sensor is open or sensor is closed

These conditions apply to sensor that has two states only (sensor values of 1 and 0). For example a door switch or PIR sensor that are either open or closed.

 

  Sensor Value (Primary)

Sensor value is any numeric sensor value that needs to be met (e.g. temperature value). We also allow you to specify a numeric range (e.g. 20-30).

  Sensor Value (Secondary)

Some sensor have two values (e.g. temperature and humidity). You can use the secondary value to implement rules on the secondary value (e.g. humidity). Sensor value is any numeric sensor value that needs to be met. We also allow you to specify a numeric range (e.g. 20-30).

    Rule Delay (minutes)

A rule delay is a time period that the rule needs to me met before triggering the action. An example of this is alerting you when your garage door has been open for 5 minutes. Another popular example is when monitoring a freezer which may fluctuate when opened and closed, so adding a delay will allow you to open and close the freezer and only trigger the rule if the temperature is sustained for a period of time.

 

  Day of week

The day of week condition allows you to perform specific actions only on specific days of the week. We also allow you to specify a day of week range (e.g. Mon-Fri, or Sat-Sun).

 

  Hour of day

 

The hour of day condition allows you to perform specific actions only on specific hours of the day. The hourly range is specified in 24h notation (0-23). We also allow you to specify a hourly ranges (e.g. 9-17).

 

Actions

An action is performed when a condition or set of conditions are met. Rule actions depend on the typw of device you have (Raspberry Pi or IOT WIFI device).The actions that we currently support per device are:

 

 Action  Raspberry Pi  IOT WIFI Device
 Alarm (for the zone(s) to which the sensor is linked)  Yes  V2 and Up
 Email (Local)  Yes  V2 and Up
 Email from Server is subscription only  Yes  Yes
 Arm (you specify which zone you want to arm)  Yes  Yes
 Disarm (you specify which zone you want to disarm)  Yes  Yes
 Chime   Yes  V2 and Up
 Siren  Yes  V2 and Up
  Relay On/ Relay Off  Yes  Yes
 Text (subscription only)  Yes  Yes
--- The WiFi Version number is at the bottom of each WiFi Sensor Setup page. ---


 - Alarm (this is sound the alarm for the zone(s) to which the sensor is linked

 - Email

 - Arm (you specify which zone you want to arm)

 - Disarm (you specify which zone you want to disarm)

 - Chime 

 - Siren

 - Relay On/ Relay Off

 - Text (see here for further details on how to configure text messages)


    Chime and Siren

There are some new configurations in the globals.py file that allow you to customize how your want the siren and chime to work. You can set the chime duration which is the amount of time the chime will sound. This is useful if you want to know if someone enters the house or you have a new customer in your shop. Siren delay will delay the siren for a period of time (seconds). You can have a intermittent beep during the delay to warn you that the alarm is about to sound (BeepDuringDelay).


        UseSiren = False

        SirenGPIOPin = 18

        SirenDelay=30 #The amount of time the siren will delay before it sounds

        BeepDuringDelay = True #if your want the siren to beep during the SirenDelay period

        SirenTimeout = 30 #siren will timeout after 30 seconds

        ChimeDuration = 5

 


In order to define rules go to : 

 

www.privateeyepi.com

 

Log in using your normal user and password.

 

There is a menu item called Rules where you can add new rules.

 

Adding new rules

 

To add new rules select the Rules in the menu option then on the Automation Page, click on the Add button after which the screen to add new rules will be displayed (Figure 2). You will be presented with a grid of 5 lines where the top 4 lines are condition and the last line is the action.

 

Figure 2 - How to define a new rule


Note: You need to define all your alarm system rules. Rules that were hard coded into the old alarm system need to be defined by you. For example the old system would trigger an alert email, insert a log and sound the alarm when a sensor is opened. Now you need to define each of those rules in the system. For an alarm system each sensor needs three rules, one for the alarm and one for the email and one for the log entry.

To define you first condition select the condition from the drop down list and enter the condition values (if any).

You can add new conditions to a rule by clicking on the drop down box under the AND column and selecting “And”.

Once you have entered all your conditions select the sensor from the "sensor =" drop down box.

Lastly select the action from the drop down box, then click “Insert rule”. The rule will now be added to the rule list. Add more rules by repeating the above steps or delete a rule by clicking “delete” from the Delete column of the rule list. You can’t amend a rule. If you want to change a rule, just delete it and re-insert it.

How rules work

 - All the rules are processed whenever a message is sent to the server (door open,. close, temperature reading etc.). Additionally rules are processed whenever the Rpi polls the server (every 5 minutes) to check in and check if any configs have changed.

 - The system does not check whether a rule makes sense, so validate that the rule is correct. There are a number of rules that just make no sense, like if a Door sensor value is between 20 and 30. A door can only have a value of 0 and 1 (closed and open).

- Rules are triggered once only. A triggered rule is reset once the rule is no longer true. A rule is reset when the rule is no longer valid. For example if a door open has an action to send an email, then an email is sent when the door opens - only one email. If the door is closed, then the rule is no longer true and it is reset. If the door is opened again then an email is sent once again. Another example would be if an email is sent for a temperature value between 20 and 30 then it would be reset when the temperature is no longer between 20 and 30.

- We don’t currently support repeating rule actions. For example you may want the system to send you and email alert every 5 minutes until the rule is reset. This is on the list for a future release.