---
title: Use the Expression Processor Function
slug: manufacturing-connect-edge-v2/use-the-expression-processor-function
docTags: 
createdAt: 2024-05-24T20:17:39.455Z
---

You can use a single input or multiple inputs to create a mathematical expression with your desired topic.&#x20;

Single inputs use events or values-type connection and multiple inputs use only values-type connection.

# User Scenario

Review the following scenario for the expression processor function. Then, you will simulate PLC data and calculate mathematical expression outputs using the expression processor function.

## User Scenario 1 (Using one Input Function)

In a cold storage facility, maintaining the right humidity levels is crucial for preserving the quality of perishable goods. An alert system needs to be in place to signal if the humidity goes beyond the acceptable range.

**Expression for Humidity Alert:&#x20;**(Humidity\_value \< 30 || Humidity\_value > 50) ? "Alert: Humidity Out of Range" : "Humidity Normal"

## User Scenario 2 (Using multiple Input Functions)

In a solar power plant, it's essential to constantly monitor the efficiency of solar panels to ensure optimal energy production. Efficiency can be calculated based on the ratio of the output power to the input solar radiation, along with the surface area of the solar panel.

**Expression for Efficiency Calculation:&#x20;**(P\_value / (S\_value \* Area\_value)) \* 100

# Step 1: Add a Device

Follow the steps to [Connect a Device](docId\:SqalV8ImyZmn8xA-56gno) and configure the following parameters:

- **Device Type**: Simulator
- **Driver Name**: Generator
- **Enable Alias Topics**: Select the checkbox.&#x20;

# Step 2: Add Tags

After connecting the device, add the following tags. See [Add Tags](docId:-5nFrBQ-uriWOY3GACnPt) to learn more. Each tag will represent one of the user scenario mentioned above.

## Tag 1 (User Scenario 1)

- **Name**: Select **S - Random value generator**.
- **Value Type**: Select **int64**.&#x20;
- **Polling Interval**: Enter **5**.
- **Tag Name**: Enter **Humidity**.
- **Min Value:** Enter **25**.
- **Max Value:** Enter **55**.

## Tag 2 (User Scenario 2)

- **Name**: Select **S - Random value generator**.
- **Value Type**: Select **float64**.&#x20;
- **Polling Interval**: Enter **5**.
- **Tag Name**: Enter **Power**.&#x20;
- **Min Value:** Enter **75**.
- **Max Value:** Enter **100**.

## Tag 3 (User Scenario 2)

- **Name**: Select **S - Random value generator**.
- **Value Type**: Select **float64**.&#x20;
- **Polling Interval**: Enter **5**.
- **Tag Name**: Enter **Solar\_Radiation**.&#x20;
- **Min Value:** Enter **50**.
- **Max Value:** Enter **75**.

## Tag 4 (User Scenario 2)

- **Name**: Select **S - Random value generator**.
- **Value Type**: Select **int64**.&#x20;
- **Polling Interval**: Enter **5**.
- **Tag Name**: Enter **Area**.&#x20;
- **Min Value:** Enter **250**.
- **Max Value:** Enter **500**.

# Step 3: Create Analytics Flows

You can now create the analytics flows using data from the device and tag you previously created. Follow the appropriate step out of 3a or 3b based on the two user scenarios for the Expression processor function you want to use.

## Step 3a: Configure Single Input Expression (User Scenario 1)

1. Navigate to **Analytics**.&#x20;
2. On the analytics canvas, click **Add processor**.
   The *Create a processor* dialog box displays.
   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/cxRhEOiDCl-zRqVGza5mG_image.png "The Add processor option")
3. Select **DataHub Subscribe**.
4. In the *Topic&#x20;*&#x66;ield, click the **Search&#x20;**&#x69;con, select the device you previously created, and then select the alias topic for the **Humidity&#x20;**&#x74;ag.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/pIw3wYv1KG_4xZuvVBYNQ_image.png" size="80" width="1141" height="571" position="center" caption="Create a Processor dialog box" showCaption="true"}
5. Click **Save**.
6. Click **Add processor** again and select **Expression&#x20;**&#x70;rocessor.
   The following information defines this function:
   - **Expression**: Enter the mathematical expression from the user scenario 1.&#x20;
     You must define the connection of the input tag as a **variable name&#x20;**(Humidity) and then use that in the mathematical expression (such as Humidity\_value).
   - **Output Field Name**: Enter **value&#x20;**&#x61;s the field to appear in the output.
7. Click **Save**.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/nhQ5MzfNLKq1hJgo29wb6_image.png" size="80" width="499" height="412" position="center" caption="Expression processor dialog box" showCaption="true"}
8. Connect the DataHub Subscribe processor (tag: *Humidity)* to the Expression processor with a wire and enter the definition of **Humidity&#x20;**&#x66;or the **value-type** connection.
9. On the analytics canvas, click **Save**.

The configured analytics flows should look like the following:&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/xJ4FVX1NJmMS_Qtgw25c4_image.png" size="80" width="665" height="260" position="center" caption="Completed canvas flow with one input" showCaption="true"}

## Step 3b: Configure Multiple Inputs Expression (User Scenario 2)

1. Navigate to **Analytics**.&#x20;
2. On the analytics canvas, click **Add processor.**
   The *Create a processor* dialog box displays.
   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/c_nkhpFTj28c72IxPHuxD_image.png "The Add processor option")
3. Select **DataHub Subscribe**.
4. In the *Topic&#x20;*&#x66;ield, click the **Search&#x20;**&#x69;con, select the device you previously created, and then select the alias topic for the **Power&#x20;**&#x74;ag.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/_QwATfY_T5BN8PSVpokls_image.png" size="80" width="1141" height="571" position="center" caption="Create a Processor dialog box" showCaption="true"}
5. Repeat steps 2-4 in *Step3b* to add another *DataHub Subscribe* node. Select the alias topic for the **Solar\_radiation&#x20;**&#x61;nd **Area&#x20;**&#x74;ag respectively.&#x20;
6. Click **Save**.
7. Click **Add processor** again and select **Expression&#x20;**&#x70;rocessor.
   The following information defines this function:
   - **Expression**: Enter the mathematical expression from the user scenario 2.&#x20;
     You must define the connection of the input tag as a **variable name&#x20;**(P, S, Area) and then use that in the mathematical expression (such as P\_value, S\_value, and Area\_value).
   - **Output Field Name**: Enter **value&#x20;**&#x61;s the field to appear in the output.
8. Click **Save**.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/8_FEm8mpuQTdLwy_wLJ9v_image.png" size="80" width="565" height="621" position="center" caption="Exression processor dialog box" showCaption="true"}
9. Connect the DataHub Subscribe processor (tag: *Power)* to the Expression processor with a wire and enter the definition of **P&#x20;**&#x66;or the **value-type** connection.
10. Connect the DataHub Subscribe processor (tag: *Solar\_Radiation)* to the Expression processor with a wire and enter the definition of **S&#x20;**&#x66;or the **value-type** connection.
11. Connect the DataHub Subscribe processor (tag: *Area)* to the Expression processor with a wire and enter the definition of **Area&#x20;**&#x66;or the **value-type** connection.
12. On the analytics canvas, click **Save**.

The configured analytics flows should look like the following:&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/zrbi2x3pTrQf4b0hcUhIy_image.png" size="80" width="845" height="578" position="center" caption="Completed canvas flow with multiple inputs" showCaption="true"}

# Step 4: View Output of Processor

Click the **View&#x20;**&#x69;con in the *Expression* processor to view the output values.

## View Output for User Scenario 1

The expression function calculates the humidity from the defined tag values and gives the output for the mathematical expression.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/AkWURX2n1NCU_RCVwNOtj_image.png" size="80" width="949" height="754" position="center" caption="Output for single input expression" showCaption="true"}

## View Output for User Scenario 2

The expression function calculates the efficiency from the defined tag values and gives the output for the mathematical expression.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/9zm9ofKFqkPc52HeIsZiS_image.png" size="80" width="825" height="779" position="center" caption="Output for multiple input expression" showCaption="true"}

