--- title: "Derived Tags | Examples | N3uron KB V.1.20" slug: "derived-tags-examples" description: "Derived Tags is a N3uron module designed to implement custom logic, advanced calculations, and data aggregation for operational data analysis at N3uron…" updated: 2022-01-14T09:04:12Z published: 2022-01-14T09:04:12Z canonical: "docs.n3uron.com/derived-tags-examples" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.n3uron.com/llms.txt > Use this file to discover all available pages before exploring further. # Examples The following examples show different expressions that can be used in an **Expression Ta****g**. ## Sum of two tags: ```javascript //Returns the sum of the value of tags a and b $.output= $.input.a.value + $.input.b.value; ``` ## Set a value based on a condition: ```javascript //If the value of a is above the threshold, it will return 1, //otherwise it will return 0 if ($.input.a.value > threshold) $.output =1; else $.output = 0; ``` ## Increment a global counter based on a condition: ```javascript //First, the global variable counter needs to exist. The counter //then needs to be incremented when the condition is set to true //(a.value must be even) if ($.input.a.value % 2 === 0) counter++; //Return counter so that it is saved to the tag; $.output=counter; ``` ## ## Get total RAM for this machine: ```javascript //os.totalmem() returns the total memory of the machine in //bytes, divided twice by 1024 to obtain MB. $.output = os.totalmem()/1024/1024; ``` ## Get free RAM for this machine: ```javascript //os.freemem() returns the free memory of the machine in //bytes, divided twice by 1024 to obtain MB. $.output = os.freemem()/1024/1024; ``` ## Get hostname: ```javascript //os.hostname() returns the hostname as a string $.output = os.hostname(); ``` ## Get uptime: ```javascript //os.uptime() returns the host machine in seconds as a number $.output = os.uptime(); ``` ## Get memory usage of Derived Tags: ```javascript //process.memoryUsage() returns an object with memory //information. The rss property holds the total memory usage //of the process (in this case DerivedTags), in bytes $.output = process.memoryUsage().rss/1024/1024; ``` ## Assigning a quality based on a condition: ```javascript //If the value of the tag is above 100, we set the quality //to 16 (BAD_SENSOR_FAILURE) if ($.input.a.value > 100) $.output = {value: -1, quality:16} else $.output = {value: a.value, quality:192}; ``` ## Redundant tags In this example, the **DerivedTags** module is used to provide an output tag after evaluating the quality of two redundant tags coming from two redundant nodes linked to a central node.![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/12-Main-source-node-linked-to-the-central-node.png) Figure 12: Main source node linked to the central node ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/13-Redundant-source-node-linked-to-the-central-node.png)Figure 13: Redundant source node linked to the central node ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/14-Central-node.png)Figure 14: Central node - **Step 1:** Add a new module in the “Modules” section, give it a name, and select “DerivedTags” in the “Module type” field. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/15-Adding-module.png) Figure 15: Adding module - **Step 2:** Configure the **Logger** and **API** for the **DerivedTags** module. In this example, the default configuration settings have been left unedited, since (in most cases) this is a valid configuration option. - **Step 3:** Configure the module. In this example, the default configuration settings have been left unedited. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/16-Module-configuration.png) Figure 16: Module configuration - **Step 4:** Configure the tag Source section. In this example, **Mode** is set to **Expression tag** and **Trigger** is set to **Periodic**. The **Aliases** created are “Amplitude”, which has the **Input tag** /SITE01/LINE01/MACHINE01/AMPLITUDE of the main node, and “AmplitudeBis”, which has the **Input tag** /SITE01Bis/LINE01/MACHINE01/AMPLITUDE of the redundant node. Figure N°16 shows the JavaScript written in **Expression**. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/17-Tag-configuration(1).png) Figure 17: Tag configuration ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/18-Java-script-Code.png)Figure 18: Java script Code **Result:**![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/19-Redundant-tag.png) Figure 19: Redundant tag ## Aggregated tag In this example, the **DerivedTags** module will be used to output the result of an aggregation of a source tag in a tag value over a period of time.![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/20-The-Tag-AP-is-used-for-aggregation-in-this-example.png)Figure 20: The tag “AP” is used for aggregation in this example - **Step 1:** Add a new module in the “Modules” section, give it a name, and select “DerivedTags” in the “Module type” field. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/21-Adding-module.png) Figure 21: Adding module - **Step 2:** Configure the Logger and **API** for the **DerivedTags** module. In this example, the default configuration settings have been left unedited, since (in most cases) this is a valid configuration option. - **Step 3:** Configure the module. In this example, the default configuration settings have been left unedited. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/22-Module-configuration.png) Figure 22: Module configuration - **Step 4:** Configure the tag Source section. In this example, Mode is set on **Aggregated ta****g**, **Aggregation method** is set on **Average**, and the **Source Ta****g** is /000_PLANT/010_ZONE/010_MTR/AP. ![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/23-Tag-configuration.png) Figure 23: Tag configuration **Result:**![](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/24-Aggregated-tag.png)Figure 24: Aggregated tag