# Rules

Rules are a powerful feature that can make automation via the Enteprise platform very easy. They are intuitive to use and configuration is done directly from the GUI in a browser window, same way any other Enterprise features are utilised.

You can have one or multiple rules and control a single or many devices in order to create an automated structure that will not only save you time, but also keep you updated with important events in your building.

## Creating your first rule

Navigate to the main building view and click on the "Rules" button, it is in the top panel, right below the weather info.

<figure><img src="/files/jzl02dnQNSB6Gjo8vFiy" alt=""><figcaption><p>Rules button</p></figcaption></figure>

You will see the main rule creation window that appear if you have no rules created. Create a new rule via one of the two buttons (the lower one will not be available once you have your first rule).

<figure><img src="/files/vi6xw9444vOretTfNo9t" alt=""><figcaption><p>Rule creation</p></figcaption></figure>

Give you rule a "Name", the "Description" is optional. Once you click on the "Create" button your new rule will be brought into existence.

<figure><img src="/files/oMFqyAgptkj7gB4n3iFS" alt=""><figcaption><p>Rule Name and Description</p></figcaption></figure>

You still need to configure the rule itself though, so lets begin.

## Triggers

To start off you need a "Trigger" for any rule, which is the actual device that will be observed and acted upon.

Press on the "Add trigger" button and a window with a table will open. All devices that are currently in the building will be listed on the left.

<figure><img src="/files/x1OR9zAS2aigGQLnOFAq" alt=""><figcaption><p>Adding a trigger</p></figcaption></figure>

### Adding a Trigger

You can select as many trigger devices as you like via the check boxes, once done press on the right arrow to move them to the other side of the table.

For simplicity we are going to use only 1 device for this example.

<figure><img src="/files/HMyXh7kOSch0swsTQLa1" alt=""><figcaption><p>Selecting a device</p></figcaption></figure>

As the device is now in the right table you can go ahead and "Save".

This will close the table and the trigger device will pop up in the main rule window view.

<figure><img src="/files/3GbjbwsS0bQ8yuDtKPUI" alt=""><figcaption><p>Adding the device to the rule</p></figcaption></figure>

### Connecting to a Field

Since this is your first device a Field widget will pop up next to it. It represent a property of the device that will be monitored for change in order to trigger the rule.

As you can have many devices and many field (you can add more with the "Add field" button below the first field). You need to associate the trigger device with the field.

{% hint style="info" %}
You can have many trigger devices and many fields, but each field has to be associated with a device. You can also have multiple fields associated with one device.
{% endhint %}

Press on either of the purple dots and drag the line to the other (left to right or vice versa). Refer to the image below.

<figure><img src="/files/qhdz3OFLOdIJXXU8rtNB" alt=""><figcaption><p>Connecting the trigger and field</p></figcaption></figure>

Once you connect the trigger and the field you see the connection line and an "x" symbol in the middle of it which you can click on if you want to sever the connection and associate the field with another device.

<figure><img src="/files/rqQdnf2RJ0uhG0BUIkeQ" alt=""><figcaption><p>Severing the connection</p></figcaption></figure>

As your field now is connected to the trigger device you can go ahead and select a field value via the drop down menu. Press on it and the following window will pop up with a number of values.

{% hint style="info" %}
The values displayed below are specific to thе 16ASPM, as this is what device we have connected the field to. If you connect it to another type of device, the field values will change correspondingly.
{% endhint %}

Let's select the Energy field for this example and move to creating an Condition for it

<figure><img src="/files/SFvGUT2PVBTnbkM0GlQw" alt=""><figcaption><p>Selecting the energy field</p></figcaption></figure>

### Creating a Condition

A condition is the actual trigger of the rule. It is what governs what change in the field value is considered as a call to action.

{% hint style="info" %}
You can have multiple conditions for the same field or have multiple conditions each with its own field.

You can also add row to condition in order to implement "and/or" mechanics.
{% endhint %}

A example would best explain how conditions work, so lets go through one. Each field is selected in order:

* If - select Field 1 (Energy) this should be your only option
* is - select more than
* to - Const (this will let you enter a constant value), enter 10 000

If you have followed the example correctly you will end up with a condition as the one in the image below.

<figure><img src="/files/BTuaPemktwpHFr96NwHe" alt=""><figcaption><p>Configured condition</p></figcaption></figure>

Set up in this way an action will be triggered if the Energy is more than a constant value of 10000W (10kW).

What the result of this triggered even will be is determined by the "Action"

### Creating an Action

Similarly to the other elements you can add one or more actions via the "Add action" button.

<figure><img src="/files/0FqcKsvEFFzwEpukb5zz" alt=""><figcaption><p>Adding an action</p></figcaption></figure>

At the time of writing this document there are 3 options available:

* Send notification via email
* Send downlink
* Webhook

#### Sending a notification Email

Let's start with the simplest action, getting a notification email. Press on the "Add action" button and select the "Send notification" option

<figure><img src="/files/ksgOVWDJk85LXHhsa9bM" alt=""><figcaption><p>Adding an action</p></figcaption></figure>

The action widget will pop up, where you need to connect it to the condition we set up in the previous step (the connection is done in a similar way to the one between the trigger and field). Refer to the image below.

<figure><img src="/files/BZj3RxpSMWmZyHumy1EB" alt=""><figcaption><p>Connecting the action to the condition</p></figcaption></figure>

Now you need to configure the actual Email you want to receive. You need to enter:

* Recipient - add as many as you want via the blue button (refer to the image below)
* Email - the body of the message itself, you can enter any text you want manually

You can also use a neat feature that is to auto populate the email with a field value from a device in your building, this can be any device, even one that is not participating in this rule.

For the sake of simplicity we are going to select the same 16ASPM device we are using as the trigger and select the Energy value in order to get the exact reading at the time of sending the email. This will add a piece of code to the body of the email that will extract the value (the blue box in the image below).

If you have followed the instructions the Send Email action should look more or less like the one in the image below.

<figure><img src="/files/tOt9dCj6NUPFI9CE2a3T" alt=""><figcaption><p>Sending an email notification via an action</p></figcaption></figure>

Your rule is now all set up and the only thing left is to "Save" it. If you have made no configuration changes and there are no unused or unconfigured blocks you will be notified by a green "Rule updated successfully" message at the tip right corner above the "Save" button.

This mean your rule is not in effect and as soon as a condition for a field assigned to a trigger devices is met you will receive the result of the associated action.

In our case if the accumulated energy by the relay exceeds 10kW an email notification will be send with a custom text message and the exact value of the measured energy.

<figure><img src="/files/K9GWtf1e8iULUBj11fCt" alt=""><figcaption><p>Complete rule</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mclimate.eu/mclimate-enterprise/advanced-features-and-use-cases/rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
