Datacake Docs
  • Welcome
  • Get Started
  • Changelog
  • Best practices
    • Best practices: Getting started
    • Best practices: Resolution (Timeframe)
    • Best practices: Dashboards
    • Best practices: Reports
    • Best practices: Grouping Devices
  • Datacake LNS
    • Getting Started
    • Gateways
      • Milesight LoRaWAN Gateway - UG6x
      • RAKwireless WisGate Edge Light 2
    • Devices
    • Add Devices without Gateway
  • Device
    • Product
    • Configuration
    • Claiming
    • Historical Data
    • Database
      • Configuration Fields
      • Fields
        • Manual input
        • Field Roles
        • Formulas
        • Mapping Fields
      • Data retention & Datapoints
      • Examples
        • Mapping 4-20mA Signals
        • Converting Units
  • Dashboards
    • Global Dashboards
      • Setting Homepage
    • Device Dashboards
    • Multi-Device Dashboards
    • Widgets
      • Value Widget
      • Chart Widget
      • Image Map
      • Map Widget
      • Text Widget
      • SOS Widget
      • Boolean Widget
      • iFrame Widget
      • Downlink Widget
      • Set Value Widget
      • Measurement List Widget
      • Heatmap Widget
      • Table Widget
      • Image Widget
  • Portal
    • Multi-Tenancy (Workspaces)
    • Reports
      • Energy Report
    • Administrators
    • Members
      • API Users
    • Security & Privacy
    • Billing
      • Support Packages
      • VAT Exemption / Tax ID
      • SMS Credits
      • Access Invoices
      • Unused time and Remaining time in Invoices (Prorations)
      • Codes
    • White Label
    • Rules
      • Legacy Rule Engine
        • Sending notifications via Telegram
      • New Rule Engine
        • Rule Engine Table Overview
        • Copy/Paste and Template Functionality
        • Advanced Rule Engine E-Mail and Webhook Templates
        • Time Restrictions
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
    • Configuring LNS
      • The Things Stack (TTN / TTI) Automated Setup
      • The Things Stack (TTN / TTI) Manual Setup
      • Loriot
      • Kerlink Wanesy
      • Helium
      • ChirpStack
      • Tektelic
      • Actility ThingPark
      • Senet
      • Milesight Gateway
      • KPN
    • Downlinks (LoRaWAN)
      • Set Time Frame
    • Securing Webhooks
    • Payload Decoders
      • Location and GPS
      • Access Gateway Metadata
      • Access Measurements
      • Global Variables
    • Using Cayenne LPP
    • Converting Payload
  • Generic API Devices
    • HTTP Downlinks
  • Integrations
    • MQTT
    • Particle
      • Get Started
      • Adding Integrations
      • Decoding Payloads
      • Calling Functions
      • Templates
        • Particle Tracker One
    • Incoming Webhooks
    • Outgoing Webhooks
      • Securing Outgoing Webhooks in Datacake
    • Golioth
    • Blues Wireless Notecard
    • Sigfox
    • Swarm Asset Tracker
    • Grandcentrix Modbus Cloud Connect
    • YuDash LYNX IoT Gateway
    • Dragino NB-IoT
      • Changing NB-IoT Bands
    • Hardwario CHESTER
    • 1NCE OS
  • API
    • Exporting Data
    • Record Measurements via API
    • Node RED to Datacake
    • Generate Access Token
    • Internal MQTT
      • Get Started
      • MQTT Documentation
      • MQTT over WebSocket
      • Example Code
    • GraphQL API
      • Using GraphQL
      • Device Creation
      • Tutorials
        • Read Group via Tags
  • Guides
    • Python
    • Send Slack Notifications
    • Forward Data to Cake Red
    • Multiple Data Feeds
    • Automated Dynamic Downlinks
    • Ingesting JSON Data into Datacake API Devices
    • Working with Default HTTP Decoder on API Devices and Code Examples
    • Accessing Measurements in Decoders
    • Connecting Datacake to Notion Using Zapier
    • How to set up and use location on non-GPS devices
    • How to integrate with AWS IoT Core
    • How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
    • How to Map Sensor Values to Ranges or Booleans, Strings using Mapping Fields
    • Understanding Internal vs. External MQTT Brokers on Datacake
    • Sending UDP Messages between 1NCE OS and Datacake
    • Concepts of LoRaWAN Payload Decoders on Datacake
    • How to check if a value stays above or below limits for given time
Powered by GitBook
On this page
  • Intro
  • Video
  • How to Copy and Paste a Rule
  • JSON Export for Templates
  • Creating and Using Rule Templates
  • Understanding Rule Templates
  • Creating a Template
  • Sharing Templates Across Workspaces
  • JSON Configuration Reference

Was this helpful?

  1. Portal
  2. Rules
  3. New Rule Engine

Copy/Paste and Template Functionality

How to duplicate, copy and paste rules and work with rule templates on the new rule engine.

Last updated 7 months ago

Was this helpful?

Intro

You can easily copy and paste rules within your workspaces. This feature simplifies the process of replicating configurations, saving time and effort.

Video

See everything covered on this video:

How to Copy and Paste a Rule

  1. Navigate to the Rule Engine: Select the rule you would like to replicate. Ensure the rule is configured with the triggers, conditions and actions (e.g., Webhook, Email notification) as needed.

  2. Hover to Access Copy/Paste Option: Hover over the button "More", next to the Enabled switch on the right corner. You will see the options to Copy rule configuration and Paste rule configuration.

  1. Select a Target Workspace: Before pasting the rule, ensure that the target device for the rule exists within the workspace where you want to paste the rule. If not, claim the device in the workspace.

    1. If you don't have access to the product or device, you can still copy and paste the rule and reuse conditions and actions, such as email templates, webhooks, etc.

  2. Paste the Rule:

    • Go to the target workspace’s Rule Engine.

    • Click Add Rule and select Paste rule configuration instead of manually configuring a new rule.

    • The copied rule will be pasted with the original trigger, condition, and action.

  3. Customisation Options:

    • When pasting, you will have the option to replace certain elements. For instance, you can deselect actions or triggers if you want to configure your own actions.

    • You can modify details like the recipient in an Email action or other specifics based on your needs.

  4. Enable and Save the Rule: After making any necessary adjustments, enable the rule and save it. Your copied rule is now active and ready to use.

JSON Export for Templates

One of the advanced features of the Copy/Paste functionality is the ability to work with the rule’s JSON structure. When copying a rule, you can see the JSON representation on your clipboard, which contains all the rule’s configuration data.

You can:

  • Save the JSON externally for future use, creating reusable templates.

  • Modify the JSON to make changes like swapping out email recipients or adjusting triggers without needing to reconfigure everything from scratch.

This provides a powerful way to manage and distribute rule configurations, especially when working with multiple devices, workspaces or complex setups.

Creating and Using Rule Templates

Understanding Rule Templates

  • Rules in the Datacake IoT platform are represented as JSON objects. By copying and modifying these JSON structures, users can create reusable rule templates.

  • Rule templates can be shared across workspaces, making it easy to replicate rules for multiple devices or projects without needing to recreate them from scratch.

Creating a Template

  1. Analyze the JSON Structure:

    • Each rule’s configuration can be viewed and modified using the JSON format. Understand the structure and identify fields that need to be adjusted, such as triggers, actions, and product identifiers.

  2. Modify and Save as Template:

    • Make necessary changes to the JSON configuration and save it as a template for future use.

  3. Importing a Template:

    • When creating a new rule, paste the template’s JSON configuration and adjust any product-specific fields as needed.

Sharing Templates Across Workspaces

  • When using templates across different workspaces, ensure that the product fields are appropriately configured, as products might differ between workspaces.

  • Templates can be shared with other users or within different workspaces by copying and pasting the JSON configuration.

JSON Configuration Reference

  • The rule engine’s JSON configuration allows for detailed customization of rules. Documentation is available with explanations of different JSON tags and their meanings.

  • By utilizing JSON configurations, users can fine-tune rules, automate processes, and create sophisticated automation strategies.

RULE_CONDITION_SCHEMA = {
    "$schema": "http://json-schema.org/schema#",
    "definitions": {
        "timerangeOperation": {
            "type": "object",
            "properties": {
                "kind": {
                    "type": "string",
                    "enum": [
                        "AVERAGE",
                        "MIN",
                        "MAX",
                        "ABSOLUTE_CHANGE",
                        "RELATIVE_CHANGE",
                        "SUM",
                        "COUNT",
                    ],
                },
                "start": {"type": "string"},
                "end": {"type": "string"},
            },
            "additionalProperties": False,
            "required": ["kind", "start", "end"],
        },
        "leftOperand": {
            "type": "object",
            "properties": {
                "kind": {"type": "string", "enum": ["TRIGGERING_DEVICE_FIELD_VALUE"]},
                "fieldId": {"type": "string", "format": "uuid"},
                "timerangeOperation": {"$ref": "#/definitions/timerangeOperation"},
            },
            "additionalProperties": False,
            "required": ["kind", "fieldId"],
        },
        "staticNumberValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "STATIC_NUMBER_VALUE"},
                "numberValue": {"type": "number"},
                "hysteresis": {"type": "number", "minimum": 0},
            },
            "additionalProperties": False,
            "required": ["kind", "numberValue"],
        },
        "staticRangeValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "STATIC_RANGE_VALUE"},
                "rangeValue": {
                    "type": "object",
                    "properties": {
                        "start": {"type": "number"},
                        "end": {"type": "number"},
                        "includeBoundaries": {"type": "boolean"},
                    },
                    "additionalProperties": False,
                    "required": ["start", "end", "includeBoundaries"],
                },
                "hysteresis": {"type": "number"},
            },
            "additionalProperties": False,
            "required": ["kind", "rangeValue"],
        },
        "staticBooleanValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "STATIC_BOOLEAN_VALUE"},
                "booleanValue": {"type": "boolean"},
            },
            "additionalProperties": False,
            "required": ["kind", "booleanValue"],
        },
        "staticStringValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "STATIC_STRING_VALUE"},
                "stringValue": {"type": "string"},
            },
            "additionalProperties": False,
            "required": ["kind", "stringValue"],
        },
        "staticGeofenceValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "STATIC_GEOFENCE_VALUE"},
                "geofenceValue": {"type": "string"},
            },
            "additionalProperties": False,
            "required": ["kind", "geofenceValue"],
        },
        "dynamicTriggeringDeviceFieldValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "DYNAMIC_TRIGGERING_DEVICE_FIELD_VALUE"},
                "fieldId": {"type": "string", "format": "uuid"},
            },
            "additionalProperties": False,
            "required": ["kind", "fieldId"],
        },
        "dynamicDeviceFieldValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "DYNAMIC_DEVICE_FIELD_VALUE"},
                "fieldId": {"type": "string", "format": "uuid"},
                "deviceId": {"type": "string", "format": "uuid"},
            },
            "additionalProperties": False,
            "required": ["kind", "fieldId", "deviceId"],
        },
        "dynamicConfigurationFieldValue": {
            "type": "object",
            "properties": {
                "kind": {"const": "DYNAMIC_CONFIGURATION_FIELD_VALUE"},
                "fieldId": {"type": "string", "format": "uuid"},
            },
            "additionalProperties": False,
            "required": ["kind", "fieldId"],
        },
        "rightOperand": {
            "type": "object",
            "oneOf": [
                {"$ref": "#/definitions/staticNumberValue"},
                {"$ref": "#/definitions/staticRangeValue"},
                {"$ref": "#/definitions/staticBooleanValue"},
                {"$ref": "#/definitions/staticStringValue"},
                {"$ref": "#/definitions/staticGeofenceValue"},
                {"$ref": "#/definitions/dynamicTriggeringDeviceFieldValue"},
                {"$ref": "#/definitions/dynamicDeviceFieldValue"},
                {"$ref": "#/definitions/dynamicConfigurationFieldValue"},
            ],
        },
    },
    "type": "object",
    "properties": {
        "id": {"type": "string", "format": "uuid"},
        "description": {"type": "string"},
        "conjunction": {"type": "string", "enum": ["AND", "OR"]},
        "kind": {
            "type": "string",
            "enum": [
                "EQUALS",
                "NOT_EQUALS",
                "CONTAINS",
                "NOT_CONTAINS",
                "LESS_THAN",
                "LESS_THAN_OR_EQUAL",
                "GREATER_THAN",
                "GREATER_THAN_OR_EQUAL",
                "INSIDE_RANGE",
                "OUTSIDE_RANGE",
                "INSIDE_GEOFENCE",
                "OUTSIDE_GEOFENCE",
            ],
        },
        "leftOperand": {"$ref": "#/definitions/leftOperand"},
        "rightOperand": {"$ref": "#/definitions/rightOperand"},
    },
    "additionalProperties": False,
    "required": ["id", "description", "kind", "leftOperand", "rightOperand"],
}

CONDITION_EVALUATION_SUBRESULTS_SCHEMA = {
    "$schema": "http://json-schema.org/schema#",
    "type": "object",
    "propertyNames": {"format": "uuid"},
    "unevaluatedProperties": {"type": ["boolean", "null"]},
    "additionalProperties": False,
}


WEBHOOK_ACTION_HEADER_SCHEMA = {
    "$schema": "http://json-schema.org/schema#",
    "type": "object",
    "properties": {
        "key": {
            "type": "string",
        },
        "value": {
            "type": "string",
        },
    },
    "required": ["key", "value"],
    "additionalProperties": False,
}