# Understanding Conditions

Conditions are auxiliary controls for event/action rule operation: these are **condition variables**, 'locks' for the defined event/action mappings.

Each condition can only be in one of two states: **OFF** or **ON** (0 or 1, *false* or *true*, to put it in terms of formal logic). When applied to a rule, the condition serves as an additional clause for the action execution: the action will only be performed if attached condition is ON, and is never performed if condition is OFF - regardless of whether the event has been triggered. The condition **state** can be manipulated using the *Set condition* and *Unset condition* **actions** (these exist by default for each and every created condition), which, in their turn, can be set off by some other events.

The conditions are available in the *Event & Action Configurator*: click the *Conditions* button in the bottom part of the *Rules* section to load the existing condition list or create a new one.

#### Add Condition

To add, remove and manage the conditions in the Macula Console, go to the *Events & Actions* section and choose *Conditions* from the menu on the left. Conditions can be also added as you go from the Event & Action Configurator.

Click the *+ New condition* button on the upper panel to bring up the condition configuration dialog box. Here you have to:

* enter a comprehensible **title** for the condition - usually, the best ones are those which express a state, e.g., camera offline, motion present, door opened etc.
* choose the **target server** - conditions, as non-global events, are local and operate within a single server
* set condition **default state**, i.e., the state it is in before it is set or unset for the first time; this can be either ON or OFF
* Save State: Save condition state after server restart

<figure><img src="https://412599993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeNXnJx0OpvxnmpWqOBNm%2Fuploads%2FoboLe0nmuYEMSAbwR1Rv%2Fimage.png?alt=media&#x26;token=7957ef06-3968-48ce-8f46-fbb80564b354" alt="" width="563"><figcaption></figcaption></figure>

When you have finished, click *OK* to save and close the dialog box; the newly created condition will appear in the item list and will become available in the *Event & Action Configurator*.

Use the buttons on the upper panel to edit and remove the conditions; the filters on the bottom panel will help you load recently added or recently edited items.

#### Condition Usage Examples

Consider a system that has three cameras installed:  *Camera A* overlooking area A, *Camera B* overlooking area B that is just next to area A, and *Camera C,* which is a supplementary PTZ device and can be turned to view both areas and even more, and overlooks area C by default. If a person walks into area A, he/she will be detected by *Camera A's* video analytics; if he moves on, he will enter area B and the security guard will see him on *Camera B*.

Now, imagine that *Camera B* suddenly goes offline. The security guard is OK with that, until there is someone in area B; he notices some motion in area A and takes control of *Camera C*, and makes it overlook area B, but the person of interest is long gone by that time, and there is no footage of him being present in area B. So, the task is to automate the process so that *Camera 3* serves as a backup while *Camera B* is offline; the configuration in such a case may look as follows:

* Event 1: *VCA*, source: *Camera A*
* Event 2: *Video Lost*, source: *Camera B*
* Condition: *Camera B Offline,* default state: *OFF*
* Action 1: make *Camera C* go to preset *Area B*
* Action &#x32;*: Set Condition,* target: condition *Camera B Offline*

Rules:

* Event 2 triggers Action 2 (that switches the state of condition *Camera B Offline* to ON)
* Event 1 triggers Action 1 upon the condition *Camera B Offline*

Thus, Action 1 (go to the PTZ preset) is only actually triggered then and then only if *Camera B Offline* condition state is ON, which is not possible while *Camera B* is online.

Now, we need this to work both ways, i.e., we want to return *Camera C* to its home position and reset condition state back to *OFF* when *Camera B* comes online again. New configuration elements will be added:

* Event 3: *Video Restored*, source: *Camera B*
* Action 3: *Unset Condition*, target: condition *Camera B Offline*
* Action 4: make *Camera C* go to preset *Area C*

Rules:

* Event 3 triggers Action 3 (that switches condition state to OFF)
* Event 3 triggers Action 4

These new rules ensure that, once *Camera B* is streaming again, *Camera C* will go back to its original position, thus terminating it as a backup device; and the condition is *OFF*, meaning that the triggering of VCA rules in area A will not make *Camera C* move.

The whole setup in *Event & Action Configurator* is as follows:

<figure><img src="https://412599993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeNXnJx0OpvxnmpWqOBNm%2Fuploads%2FLL6XxeWX7uwGLMZpDxi2%2Fimage.png?alt=media&#x26;token=d7647382-7949-4bbf-bd34-910df55e5912" alt=""><figcaption></figcaption></figure>
