LogoLogo
Website
  • Overview
  • Getting started
  • Integrations
    • MQTT Integration
    • HTTPS Integration
    • LORIOT Integration
    • Swisscom LPN Integration
    • TheThingsNetwork Integration
    • TheThingsIndustries Integration
    • Sigfox Integration
    • AWS IoT Integration
    • AWS Kinesis Integration
    • Azure Event Hub Integration
    • Azure IoT Hub Integration
    • Helium Network Integration
  • Key concept
    • Entities and relations
    • Entity Groups
    • Attributes
    • Device Profiles
    • Telemetry data
    • Device alarms
    • Version control
  • Dashboards
    • Dashboards
      • Dashboard Templates
      • IAQ Template
      • Aliases
    • Widget library
      • Energy management widgets
        • Summarized annual consumption
        • Daily profile
        • XY chart
  • Rule Engine
    • Rule Engine
      • Rule Engine Templates
        • General data proccessing concept
        • Weather data feed
      • Test Javascript function
      • Predefined Message Types
      • Filter rule nodes
        • check alarm status
        • check existence fields
        • check relation
        • gps geofencing filter
        • message type filter
        • message type switch
        • originator type filter
        • originator type switch
        • script filter
        • switch script node
      • Enrichment rule nodes
        • calculate delta
        • customer attributes
        • customer details
        • originator attributes
        • originator fields
        • originator telemetry
        • related attributes
        • related Device attributes
        • tenant attributes
        • tenant details
      • Transformation rule nodes
        • change originator
        • duplicate to group
        • duplicate to related
        • script transformation
        • to email transformation
        • M-Bus decoder
      • Action rule nodes
        • Add to group
        • Remove from group
        • Generate report
        • Integration Downlink
        • REST Call Reply
        • Change owner
        • Create alarm
        • Clear alarm
        • Delay messages
        • Generator
        • Log
        • RPC Call Reply
        • RPC Call Request
        • GPS geofencing events
        • Save attributes
        • Math Function
        • Asset Profiles Feature
        • fetch device credentials
        • delete attributes
        • split array msg
        • json path
        • delete keys
        • rename keys
        • copy keys
        • Save to Custom
        • Assign To Customer
        • Unassign From Customer
        • Create Relation
        • Delete Relation
        • Push to cloud
        • Pus to edge
        • Save timeseries
      • Analytics rule nodes
        • Aggregate Latest
        • Aggregate Stream
        • Alarms Count
      • Output connectors
        • AWS SNS
        • AWS SQS
        • MQTT
        • RabbitMQ
        • Kafka
        • Azure IoT Hub
        • Rest API
        • Priva
          • Realtime Telemetry API
          • Realtime Setpoint API
          • Data Insight Metadata API
          • Data Insight History API
          • Alarm Data Api
        • SOAP API
        • send email
        • send SMS
        • send Twilio SMS
      • Flow
        • Acknowledge
        • Checkpoint
        • Rule Chain
        • Output
  • Device Type Library
    • telemetry data keys
    • attribute data keys
      • Assets
        • Property
          • Building
          • Floor
          • Room
        • Facility
          • Component
        • City Zone
      • Devices
    • relation Type keys
  • API documentation
    • Admin Controller
  • CLI Tool
    • How to install the tool
    • Dataimport
  • Dynamic QR Codes
    • Dynamic QR Code App
Powered by GitBook
On this page
  • What is the Rule Engine?
  • Typical Use Cases
  • Hello-World Example

Was this helpful?

  1. Rule Engine

Rule Engine

What is the Rule Engine?

Rule Engine is an easy to use framework for building event-based workflows. There are 3 main components:

  • Message - any incoming event. It can be an incoming data from devices, device life-cycle event, REST API event, RPC request, etc.

  • Rule Node - a function that is executed on an incoming message. There are many different Node types that can filter, transform or execute some action on incoming Message.

  • Rule Chain - nodes are connected with each other with relations, so the outbound message from rule node is sent to next connected rule nodes.

Typical Use Cases

Tesenso IoT Cloud Rule Engine is a highly customizable framework for complex event processing. Here are some common use cases that one can configure via Tesenso IoT Cloud Rule Chains:

  • Data validation and modification for incoming telemetry or attributes before saving to the database.

  • Copy telemetry or attributes from devices to related assets so you can aggregate telemetry. For example data from multiple devices can be aggregated in related Asset.

  • Create/Update/Clear alarms based on defined conditions.

  • Trigger actions based on device life-cycle events. For example, create alerts if Device is Online/Offline.

  • Load additional data required for processing. For example, load temperature threshold value for a device that is defined in Device’s Customer or Tenant attribute.

  • Trigger REST API calls to external systems.

  • Send emails when complex event occurs and use attributes of other entities inside Email Template.

  • Take into account User preferences during event processing.

  • Make RPC calls based on defined condition.

  • Integrate with external pipelines like Kafka, Spark, AWS services, etc.

Hello-World Example

Let’s assume your device is using DHT22 sensor to collect and push temperature to the Tesenso IoT Cloud. DHT22 sensor can measure temperature from -40°C to +80°C.

In this tutorial we will configure Tesenso IoT Cloud Rule Engine to store all temperature within -40 to 80°C range and log all other readings to the system log.

Adding temperature validation node

In Tesenso IoT Cloud UI go to Rule Chains section and open Root Rule Chain.

return typeof msg.temperature === 'undefined'         || (msg.temperature >= -40 && msg.temperature <= 80);

If temperature property not defined or temperature is valid - script will return True, otherwise it will return False. If script returns True incoming message will be routed to the next nodes that are connected with True relation.

Now we want that all telemetry requests pass through this validation script. We need to remove the existing Post Telemetry relation between Message Type Switch node and Save Telemetry node:

Next, we need to connect Script Filter node with Save Telemetry node using True relation. So all valid telemetry will be saved:

Also, we will connect Script Filter node with Log Other node using False relation. So that all not valid telemetry will be logged in the system log:

Press Save button to apply changes.

Validate results

For validating results we will need to create Device and submit telemetry to the Tesenso IoT Cloud. So go to Devices section and create new Device:

For posting device telemetry we will use Rest API. To do this this we will need to copy device access token from the device Thermostat Home.

Lets post temperature = 99. We will see that telemetry was not added in Device Latest Telemetry section:

curl -v -X POST -d '{"temperature":99}' http://tesenso.io:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

*you need to replace $ACCESS_TOKEN with actual device token

Lets post temperature = 24. We will see that telemetry was saved successfully.

curl -v -X POST -d '{"temperature":24}' http://tesenso.io:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"
PreviousXY chartNextRule Engine Templates

Last updated 3 years ago

Was this helpful?

Drag and Drop rule node to the chain. Node configuration window will be opened. We will use this script for data validation:

image

And connect node with node using Post Telemetry relation:

image
image
image
Script Filter
Message Type Switch
Script Filter