home > en > features > rules

Rules

Rules define what actions should be performed in response to events related
to the transmission of new data
by devices. When data fulfills the conditions specified in the rules, the service
generates a message
of a specific type.

Rules can be defined for:

  • a selected device,
  • a selected group of devices,
  • all devices with a specific tag,
  • all devices belonging to a selected place (path) in the organizational structure.

Defining rules

A rule can be active or inactive.

An incoming data analysis rule is defined for:

  • a device with a selected identifier (EUI),
  • a group,
  • devices tagged with a tag of a selected name and value.

Analysis can be limited to data not older than a specified number of minutes.

Hysteresis is taken into account when analyzing value changes.

When the data meets the rule's conditions, the system generates a notification with a selected severity level:

  • Info
  • Warning
  • Alert
  • Critical
  • Emergency

The notification is directed to a selected list of users.
Optionally, when the rule ceases to be met (data values return to the expected range), the system generates a notification sent to the specified list of users.

Data analysis conditions are defined by:

  • selecting options in the form,
  • defining a script that analyzes the data.

Selecting options

If the script checkbox is not checked on the form, conditions can be defined by filling in the appearing form fields and specifying:

  • the name of the analyzed measurement,
  • the comparison condition (less than, greater than, equal to, not equal to),
  • the value to compare against.

Multiple such conditions can be defined.

Python script

By defining conditions using a script, you can check more dependencies than by selecting options from the form. For example, compare different measurements with each other.

The script must define a checkRule() function returning the result by calling the conditionsNotMet() or conditionsMet() function.

Example:

def checkRule():
    v1 = getValue("temperature1")
    v2 = getValue("temperature2")
    if v1 is None or v2 is None:
        return conditionsNotMet()
    if v2 - v1 > 10:
        return conditionsMet("temperature2",v2)
    return conditionsNotMet()

Variables in rule messages

When composing message content, the following variables can be used:

  • {target.eui} - EUI of the device to which the rule applies (if it applies to a device)
  • {target.name} - name of the device to which the rule applies
  • {tag.name} - name of the device tag to which the rule applies
  • {tag.value} - value of the device tag (named {tag.name}) to which the rule applies
  • {device.eui} - EUI of the device for which the rule was triggered
  • {device.name} - name of the device for which the rule was triggered
  • {var} - name of the measurement for which the rule was triggered
  • {measurement} - name of the measurement for which the rule was triggered
  • {value} - measurement value that fulfills the rule
  • {info} - if present, it is used to separate the message subject from its body
  • {device.owner} - username of the user who owns the device
  • {device.team} - list of usernames of users belonging to the device's team
  • {device.admins} - list of usernames of users who are administrators of the device

Example of use in a message:

This is the notification subject{info}Warning! The value {value} of parameter {measurement} for device
{device.name} ({device.eui}) is above target.

© 2023-2025 Grzegorz Skorupa