Copy/Paste and Template Functionality

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

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,
}

Last updated