Rules

From AirQ Networks wiki
Jump to: navigation, search

Contents

ExpressionActionSimple behavior.jpg

Rules are used to create behaviors more complex than data observing and relay actions with clicking on an interface.

With rules system can perform actions if certain conditions are verified.

A rule is a couple expression-actions, where expression defines conditions, and actions defines actions. If the expression is verified, all the actions are executed.


Some examples of rules:

  • If temperature of 101.1.1.1 is greater than -18 (expression), send an SMS to 123456 number (actions)
  • If IN1=True of 3.1.1.1 (expressions), activate RELAY1 of 3.1.1.1 (actions)
  • If temperature of 101.1.1.1 is greater than -18 and IN=True of 3.1.1.1 (expressions), send and SMS to 123456 number and send email to xxx@x.it and activate RELAY1 of 3.1.1.1 (actions)


An expression is generally formed by a set of comparison and arithmetic among states and/or values sensed by AirQNetworks boards.

Actions are a list of these:

  • Send an SMS to a phone number;
  • Send an email to an address;
  • Activate a relay of the AirQ 300 Board.




Define a rule with Pingu

Rules are grouped by board, so to go to managing rules interface, click on the relative icon of a board in the dashboard:

Manage rules.jpg

Add a new rule

From the managing rules interface, use the top displayed module for add a new rule

Rule nameAdd an expressionAdd an actionAdd new rule.jpg
About this image

Expressions

An expression is a comparison between two numeric or truth values. User can add a single expression or two expressions linked by and AND/OR value. If an expression is verified, all the actions are executes. For add a new expression, click on the relative button in new rule form.

Left argumentComparisonRight argumentSingle expression.jpg
About this image
Left argumentsComparisonsRight argumentsLogical operatorDouble expression.jpg
About this image

Left side argument of an expression

First step for definition of left argument for an expression

The definition of the left arguments is based on two steps. The first step select a detected board (AirQ 300 Board, temperature sensor etc.) or Time between operator. The second step specialize the argument.

In the first step you can select one of these:

  • a time interval condition using Time between operator;
  • an AirQ 300 Board control board;
  • a sensor (temperature, humidity etc...)





Time interval definition

If you have selected Time between operator in the first step, you have to define the time interval in second step:

Time interval definition
Time interval definition

In the second step, you have to choose between two times (the second is always higher than first).

Note that when you select Time between in the first step, the comparison and the second argument of the expression is autocompleted: default is <time interval>= True. If you want, you can change the second argument with False value.

Control Unit power

If you have selected Control unit operator in the first step, you can set an expression that says if your control unit is powered by mains or battery

Check power of control unit

Note that when you select Control unit in the first step, the comparison and the second argument of the expression is autocompleted: default is Control Unit.Power= True. If you want, you can change the second argument with False value.

AirQ 300 board

If you have selected an AirQ 300 Board board id in the first step (ex. 3.0.8.7), you can choose one of these in the second step:

  • Board inputs: you can check if a board input is on or off (ex. IN2 = True);
  • Board relays: you can check if a board relay is on or off (ex. RELAY1 = False);
  • Linked pin: you can check if a board is linked with the receiver device (ex. Linked = True).
B3 expr 1.jpg

For an AirQ 300 Board board argument definition, the comparison and the second argument of the expression is autocompleted with = and True. If you want, you can set the second argument with False value.

Sensors

If you have selected a sensor in the first step id (ex. 101.0.8.7), you can choose one of these in the second step:

  • Main value of the sensor. For a 101.x.x.x sensor the main value is Temperature, for a 110.x.x.x sensor the main value is "Humidity" etc. ;
  • Signal level of the sensor;
  • Battery level of the sensor;
  • Linked pin: you can check if a board is linked with the receiver device (ex. Linked = True).
B101 expr 1.jpg

If you have selected the linked pin, the comparison and the second argument of the expression is autocompleted with = and True. If you want, you can set the second argument with False value. If you have selected the main value, the signal level or the battery level, you can compare the value with a numeric value (the second argument must be a number).

Comparison

Expression comparison operators

For arguments comparisons, you have to select one of these operators:

  • >
  • <
  • =
  • >=
  • <=
  •  !=



Right side argument of an expression

First step for definition of right argument for an expression

The definition of the right arguments is based on two steps. The first step select a base value (number or boolean), an arithmetic or a detected board (AirQ 300 Board, temperature sensor etc.). The second step specialize the argument.

In the first step you can select one of these:

  • a numeric value (ex. "temperature of 101.1.2.3 > -18");
  • a boolean value (ex. "Linked 3.1.2.3 = True");
  • an arithmetic (ex. "humidity of 110.1.2.3 < (humidity of 110.9.8.7 - 10)");
  • a detected board (ex. "temperature of 101.1.2.3 < temperature of 101.9.8.7").

The second step selection is like definition of the left argument.






Actions

Selection of the action type

After definition of the expression, you have to define all the actions that will be execute if the expression is true.

For each rule, you can define how may actions you want.

An action is composed by three parts: action, delay and duration.

Action

There are three types of action you can define:

Relay switching or pulsating

You can define a relay switching or pulsating in three steps:

  • Select an AirQ 300 Board board;
  • Select the relay. If you select Pulse relay, the action do a pulsation of the relay, simulating a button pression (by default relays are switches)
  • Select if the relay must turn on or turn off or if have to pulsate.
Board selection
Relay selection
ON/OFF selection

Sending SMS

You can set the system for sending SMS if the expressions is true. After selected sendSMS action, click on the relative icon to compose the SMS text and specify the phone number.

SMS settings buttonSms button.jpg
About this image
Set phone number and message text

If you click on the SMS settings, a popup will appear on the screen. You can set phone prefix, phone number and SMS text.

Phone prefixPhone numberSMS textBoards valuesBoards valuesSms settings.jpg
About this image
Phone prefix

A phone prefix is required

Phone number

A phone prefix is required, without the prefix

SMS text

A custom text is required.

Boards values

You can insert a value of a board in the text body, clicking on the menu on the left of the popup. For example, if you want add in text the temperature of the sensor 101.0.0.0, you can select from the menu the related value, so will appear in text the string <V>101.0.0.0.TEMP</V>. When SMS will be sended, the string <V>101.0.0.0.TEMP</V> will be replaced with the temperature of 101.0.0.0, detected when expression is true.

Sending email

You can set the system for sending email if the expressions is true. After selected sendEmail action, click on the relative icon to compose the email text and specify the address.

email settings buttonEmail button.jpg
About this image
Set email address and message text

If you click on the email settings, a popup will appear on the screen. You can set email address and email text.

email addressemail textBoards valuesBoards valuesEmail settings.jpg
About this image
Email address

n email address is required.

Email text

A custom text is required.

Boards values in email

You can insert a value of a board in the text body, clicking on the menu on the left of the popup. For example, if you want add in text the temperature of the sensor 101.0.0.0, you can select from the menu the related value, so will appear in text the string <V>101.0.0.0.TEMP</V>. When email will be sended, the string <V>101.0.0.0.TEMP</V> will be replaced with the temperature of 101.0.0.0, detected when expression is true.

Copy/paste of a text

You can copy and paste the text body from a text area to another, independent of SMS or email type.

copy buttonCopy text.jpg
About this image
paste buttonPaste text.jpg
About this image

Delay

For each action, you can set a delay, in ms, representing a time delay of action executing if the expression is True; if delay has the default value 0, the action has no delay;

Duration

For each action, you can set a duration, in seconds, representing the time of validity of the action; after this time the action will not execute if the expression matches; the action will re-executed only after rule state will be changed; if duration has the default value 0, the action will always evaluated.

Rules editing

Once rules are added in Pingu, you can edit it in the interface. Three main operations can be done:

  • editing a rule; the interaction is the same of the rule definition; to confirm the change, you have to click on update button;
  • delete a rule; clicking on the delete button and confirm deletion;
  • start/stop a rule.
  • see the rule history
start/stop buttonrule history buttonupdate buttondelete buttonEdit rules.jpg
About this image
delete confirmDelete confirm.jpg
About this image

Start and stop of rules

When a rule is created, it's automatically active. If you want, you can deactivate and activate a rule clicking respectively on pause and play button.

You can control rules activation directly from Pingu dashboard. For each board, if play button is showed, it means that at least one rule of this group is deactivated; clicking on it, activate all rules. Viceversa, if pause button is showed, it means that all rules of this group are activated; clicking on it, all rules of this group are deactivated.

Activate all group rulesRules on.jpg
About this image
Deactivate all group rulesRules off.jpg
About this image

Rule history

For each rule, a table history is available. In this table you can see the status of the old SMS and email sended, or internal errors of the rule.

Rules history.jpg

Examples

Example 1

Suppose you have a temperature sensor with id 101.2.1.0 and a AirQ 300 control board with id 3.0.1.6. Sensor is used to detect real-time temperatures of a cold store. If the temperature is too high (threshold is -18°C), a pump put cold air in the cold store to decrease the temperature. The pump switch is linked to RELAY1 of 3.0.1.6.

You have to define the phrase "If cold store temperature is greater than -18°C, turn on the pump, else turn off it"

In boards terms, you have to set "if the temperature detected by 101.2.1.0 is greater than -18, activate RELAY1 of board 3.0.1.6, else turn off RELAY1". You can define it in Pingu with two rules:

  1. if temperature of 101.2.1.0 is greater than -18, turn on RELAY1 of 3.0.1.6;
  2. if temperature of 101.2.1.0 is lower than -18, turn off RELAY1 of 3.0.1.6.


Rule 1 definition

For rule 1, expression is "temperature of 101.2.1.0 is greater than -18" and action is "turn on RELAY1 of 3.0.1.6"

How to define expression
1. Insert a rule name and click on add expression button
2. Select the for step 1 of left argument
3. Select the temperature for step 2 of left argument
4. Select ">" comparison
5. Select number for step 1 of right argument
6. Insert number value for step 2 of right argument (and click on add action button to add an action)
How to define actions
1. Select the board
2. Select the relay. Note that turning on is autocompleted (default value is True)


Rule 2 definition

For rule 2, expression is "temperature of 101.2.1.0 is lower than -18", and action is "turn off RELAY1 of 3.0.1.6"

How to define rule 2
1. Define an expression as in rule 1 definition. For this rule you have to select the "<" comparison
2. Define an action as in rule 1 definition. For this rule you have to select the "False" value to turn off the relay

Result

If cold store temperature is greater than -18°C, turn on the pumpIf cold store temperature is lower than -18°C, turn off the pumpRule ex 1k.jpg
About this image





Example 2

"if the temperature detected by 101.2.1.0 is greater than -20 and current hour is between 16:00 and 17:00, activate RELAY2 of board 3.0.1.6 with a delay of 10 seconds and send a SMS with all input values of the board 3.0.1.6"

The rule is composed by two expressions linked by an AND operator and two actions:

  • expression 1: temperature detected by 101.2.1.0 is greater than -20;
  • expression 2: current hour is between 16:00 and 17:00;
  • action 1: activate RELAY2 of 3.0.1.6 with a delay of 10 seconds;
  • action 2: send a SMS with all input values of the board 3.0.1.6.
How to define rule 2
click on the button to add a new comparison in the expressionRule ex 2a.jpg
About this image
click on the button to add a new actionRule ex 2b.jpg
About this image
Define the first expressionSelect AND operatorDefine the second expressionDefine the first actionSet a 10s delayDefine the second actionClick to edit SMS settingRule ex 2c.jpg
About this image
Select a phone prefixInsert a phone number without phone prefixInsert text and select board inputs for show its values in the text when SMS will be sendedInsert text and select board inputs for show its values in the text when SMS will be sendedRule ex 2d.jpg
About this image
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox