---
title: Rules
id: "en:tracking:admin:rules.adoc"
site: en
component: tracking
module: admin
version: 3.0
lang: en
url: "https://help.rtlscloud.io/en/tracking/3.0/admin/rules.html"
source_repo: "https://github.com/iot-invent/xCloud.git@3.0.x"
source_path: tracking/docs/en/modules/admin/pages/rules.adoc
---

# Rules

Within this area, a distinction is made between two different categories.

| Category | Description |
| --- | --- |
| Event Rules | Rules that are triggered based on events |
| Periodic Rules | Rules that are triggered repeatedly based on time |

> **NOTE:** Periodic rules are described on their own page: Periodic Rules.

## Conditions

| Field | Type | Description |
| --- | --- | --- |
| **Start/End** | Location | Start/End of the rule |
| Max. Dwell Time | Time | Max. time the asset is allowed to stay in the location |
| Max. Transport Time | Time | Max. time the transport to the location may take |
| **Destination** | Location | Start/End of the rule |
| Max. Dwell Time | Time | Max. time the asset is allowed to stay in the location |
| Max. Transport Time | Time | Max. time the transport to the location may take |

## Actions

| Field | Type | Description |
| --- | --- | --- |
| **Start/End** | Location | Start/End of the rule |
| Max. Dwell Time | Time | Max. time the asset is allowed to stay in the location |
| Max. Transport Time | Time | Max. time the transport to the location may take |
| **Destination** | Location | Start/End of the rule |
| Max. Dwell Time | Time | Max. time the asset is allowed to stay in the location |
| Max. Transport Time | Time | Max. time the transport to the location may take |

## E-mail notification

A rule can send an e-mail as one of its actions. Subject and body are stored as **FreeMarker templates** and filled at execution time with the data of the triggering rule.

### Available data

Two objects are available inside the template:

| Object | Content |
| --- | --- |
| `asset` | The asset that triggered the rule |
| `context` | The full execution context of the rule |

From the asset you can output name, id, type and tags, among others:

```none
Asset ${asset.name} has changed its location.
```

The details of the location change are available under `context.transitionResult`:

| Field | Description |
| --- | --- |
| `entered` | ID of the entered location |
| `exited` | ID of the exited location |
| `enterTime` | Timestamp of entering |
| `exitTime` | Timestamp of exiting |
| `allEntered` / `allExited` | all entered / exited location IDs |

A location ID can be resolved into an object with `id` and `name` using `context.findLocation(id)`.

Example: subject

```none
<#assign locationName = "unknown location">
<#assign time = "unknown time">
<#if context.transitionResult??>
  <#assign time = context.transitionResult.enterTime!"unknown time">
  <#if context.transitionResult.entered??>
    <#assign location = context.findLocation(context.transitionResult.entered)>
    <#if location??><#assign locationName = location.name></#if>
  </#if>
</#if>
Asset ${asset.name} reached ${locationName} at ${time}
```

> **TIP:** The rule offers a test mode that renders the template with sample data (asset "Demo Asset", location "Dummyhausen", current timestamps). This lets you validate templates without real tracking events.
