Rules¶
A rule will filter events from a stream and execute actions if conditions meet.
Configuration¶
Each rule has a name and is assigned to a single stream and event type.
Event types¶
There are several event types available:
- Packet added: When a packet is received for a device
- Reading added: When a reading is created for a device
- Action added
- Action executed
- Action failed
Condition¶
For each received event a condition is executed with the event-data.
If the condition evaluates to true
, the action will be executed. It the result is not truthy, no action will be executed.
The checkbox "Don't execute action until result of condition changes." will execute the action every time the condition switches from truthy to falsy and from falsy to truthy. This feature can be used to detect when a door opens/closes or a value raises/falls below a certain value.
Availible operators are listed in the Data Structure Overview.
Examples¶
Time based¶
After 16:00 in Berlin Timezone:
time(at_time_zone(measured_at, "Europe/Berlin")) >= time("16:00")
Between 8:00 and 16:00 in Berlin Timezone:
time(at_time_zone(measured_at, "Europe/Berlin")) >= time("08:00") && time(at_time_zone(measured_at, "Europe/Berlin")) < time("16:00")
Only on Monday:
date_part("dow", at_time_zone(measured_at, "Europe/Berlin")) == 1
Only on a Weekday:
date_part("dow", at_time_zone(measured_at, "Europe/Berlin")) > 0 && date_part("dow", at_time_zone(measured_at, "Europe/Berlin")) < 6
Condition for the last 24 hours:
measured_at > (now() - interval("1 day"))
Timer¶
A timer can be added to handle timing-related conditions.
The "condition" will be split in two parts, "start condition" and "abort condition".
With a new event, the "start condition" will be evaluated. If this is truthy, the timer will be started. If its falsy, nothing will be done.
Now there are two possibilities:
A. Another event occurs within the "timer duration":
- If the "abort condition" is truthy, the timer will be cancelled.
- If not nothing happens.
B. If there is no event within "timer duration", the configured action will be executed.
This feature can be used for example to detect if a door is open for too long. The start condition would be reading.door == "open"
and the abort condition reading.door == "closed"
.
Actions¶
The following actions can be selected:
- Send Notification
- Add Folder to Device
- Remove Folder from Device
- Send HTTP request
Send Notification¶
This action will send an E-Mail for the given configuration.
- E-Mail Address of Recipient
- Multiple addresses can be separated by komma:
a@b.com,x@y.com
- E-Mail Subject
- E-Mail Body
In the configuration values access to data from device/packet/reading is possible.
Add Folder to Device¶
This action will add the configured folder to the device.
- Folder
This feature can be used to automatically move devices to a folder if the device needs service like a battery replacement.
Remove Folder from Device¶
This action will remove the configured folder from the device.
- Folder
This feature can be used to automatically remove devices from a folder if the device got service like a battery replacement.
Send HTTP request¶
This action will send a HTTP request for the given configuration.
- HTTP Method: One of GET, POST, PUT, PATCH, DELETE
- URL: Like "https://www.example.com/"
- HTTP Headers: Like "Authorization: Basic d2lraTpwZWRpYQ=="
- HTTP Body: Can be used to send form data or JSON/XML content
In the configuration values access to data from device/packet/reading is possible.
Options:
- Send whole event as JSON: Will add the
Content-Type: application/json
header and fill the "HTTP Body" with the JSON of all available data from event. - Log result of request: Will add the logs from executing the action to the protocol. Old logs will be removed periodically.
Send MSCONS E-Mail¶
This action will use a Reading (Messwert) to generate a MSCONS E-Mail and send it automatically.
This action has its own article at MSCONS.