Configure twin rules
Twin rules dynamically calculate the thing model properties of a twin node. This topic describes how to configure twin rules.
Prerequisites
You have configured functional properties for the twin node in the Twin Workbench. For more information, see Configure functional properties.
Background information
Twin rules are classified as self rules and parent-child rules. Each rule consists of input parameters, an expression, and an output property. The input parameters correspond to the thing model properties of a twin node. When the runtime data of an input property changes, it triggers the rule to update the output property. If this output property serves as an input parameter for another twin rule, it recursively triggers other rules. This process enables runtime data interaction between twin nodes.
Context
The output property of a self rule cannot trigger another self rule.
For example, in a factory twin, you add the following twin nodes in hierarchical order: Central Control Unit, Fan, and Temperature Sensor. The following figure shows the configuration and trigger flow of the twin rules.

For more information about rule limitations, see Limitations.
Edit twin rules
In the Twin Workbench, click a twin node. In the Twin Node panel on the right, click Edit Twin Rule.
In the Twin Rule panel, you can add a single twin rule or add them in batches.
Add a single twin rule
-
Click Add Twin Rule. In the dialog box that appears, configure the following parameters.
Parameter
Description
Rule Name
Enter a custom name. The name can contain Chinese characters, letters, Japanese characters, digits, hyphens (-), underscores (_), forward slashes (/), and periods (.). It must start with a Chinese character, a letter, or a digit, and be up to 30 characters long.
Property Reference Type
Select one of the following options:
-
parent-child rule: The Property Source for the input parameters is a child node of the current twin node.
-
self rule: The Property Source for the input parameters is the current twin node.
Input Parameters
Enter a custom Parameter Name, then select the corresponding Property Source (a twin node) and its Property.
The parameter name can contain letters and digits, must start with a letter, and be up to 20 characters long.
Click Add Parameter to add more input parameters. You can add up to 5 input parameters.
Expression
Enter an arithmetic expression. For more information about supported operators and functions, see Rule expressions.
The variable names in the expression must match the names specified in the Parameter Name field of the Input Parameters section.
If an expression uses multiple input parameters, a change to any one of their values triggers the rule. When the rule executes, it uses the latest snapshot values for the other parameters.
For example, if you define a parent-child rule
room1_temp+room2_temp=floor_tempand both theroom1_tempandroom2_tempvalues are reported simultaneously, the expression is executed twice:-
Changed value of room1_temp + snapshot of room2_temp. -
Snapshot of room1_temp + changed value of room2_temp.
ImportantIf the snapshot value of an input parameter is empty, the expression returns an error. You can use a conditional function to return a default value. For more information, see Value conditional function.
Output Property
Select a functional property of the current node to store the expression's result.
If the Property Reference Type is self rule, you cannot select properties that have already been added as input parameters.
Each functional property can be used as the output property for only one twin rule.
ImportantThe expression's output is automatically converted to the data type of the output property.
For example, if an expression outputs a double and the output property is an integer, the fractional part of the double value is truncated.
-
-
Click OK.
Add twin rules in batches
-
Click Batch Add. In the Batch Add Twin Rules dialog box, click Download .xls Template to download a
.xlsrule file named after the current twin node.ImportantYou must download a separate rule file for each twin node that you want to configure.
You can upload up to 300 twin rules.
-
Edit and save the rules in the downloaded file.
For parameter descriptions, see the "Add a single twin rule" section above. The template file includes the following columns: Name, Expression, ExpressionParamsType, Input.NodeName, Input.Identifier, Input.Variable, and Output.Identifier.
-
In the Batch Add Twin Rules dialog box, click Select File, select the saved
.xlsfile, and click Open.If a parsing error occurs, click Download Invalid List. Correct the rule file based on the error messages in the downloaded list, and then upload the file again.
-
After the file is uploaded successfully, click OK.
Next steps
Set a digital twin template: Combine multiple digital twin nodes to create a digital twin template.
Add a data mapping: Configure data mapping for the TSL model properties of a digital twin node.