Arithmetic Operations Using the Sum Node

This guide assumes familiarity with:

In this guide, you'll learn how to perform an arithmetic operation of addition using a Sum Node in an action flow. You can use a Sum Node to increase the attribute value of a device, such as volume or brightness level, by a specific integer within a specified range. And while this guide highlights the addition operation, you can also use other arithmetic operations in Bixby Home Studio (BHS).

This guide uses the example "Increase the volume of the television by 10," to increase the volume of the television by a value stated in a user's voice command.

Using the volume - increase Voice Intent

The goal is to define the action flow for the volume-increase voice intent for the device.

For this voice intent, the user is expected to give Bixby an integer value between 0 and 100 in the voice command.

Example: "Increase the volume of the television by 10."

Passing the Parameter

As you learned in the Sending a Device Command With an Argument guide, the parameter value in a user command is passed to the Utterance Parameter Node.

In BHS, you can configure the Utterance Parameter Node with a default value. Normally, a device would get the input value from a user's utterance. For testing purposes in this guide, use a default value, which allows you to test the action flow on a device without an actual user utterance.

First, start building your action flow. Drag the Start and Utterance Parameter Nodes from the Action Flow Nodes Sidebar to the editor area. Then, configure the Utterance Parameter Node:

  1. Click the Utterance Parameter Node. This opens the Node Configuration menu on the right of the editor area.

    Open Utterance Parameter Node Configuration Menu

  2. In the data type drop-down menu, select integer (integer). This sets the node parameter type to integer.

    Select Integer Data Type

  3. Below your data type selection, enter an integer between 0 and 100 in the defaultValue field. For this example, enter 10.

    Configure Utterance Parameter Node

Now the default value of 10 is set for the Utterance Parameter Node. In a real use case, you need to fetch the volume value from a user's utterance.

Fetching the Volume Value

Now, you need to add and configure an Attribute Node, to fetch the current volume value of the device.

The current volume value of the device is an attribute of the audioVolume capability.

To add and configure this node:

Drag the Attribute Node from the Action Flow Nodes sidebar to the editor area. Select the node. This opens the Node Configuration Menu on the right of the editor area.

Open Node Configuration Menu

Select the audioVolume capability. In most cases, you can leave the component selection as the default option, main. For more information on components, see the note at the bottom of this section.

Select audioVolume Capability

In the pop-up, select the value property for the audioVolume attribute. Click SAVE.

Select Value Property

The Node Cofiguration window will look like this:

Node Configuration Window

Note

Most devices have only one operating section or compartment. In this case, the only option for component is main. If a device has many sections or compartments that you can operate independently, there will be multiple component options, such as top, bottom, and middle.

Now you're ready to add a Sum Node to the action flow.

Adding With the Sum Node

Drag a Sum Node from the Action Flow Sidebar to the editor area.

The values of the Utterance Parameter Node and the Attribute Node get passed to a Sum Node, whose output sets the final audioVolume of the device.

Add the Sum Node to the Action Flow

The Sum Node has two input data ports (leftValue and rightValue), and one output data port. The output port returns the result of adding the leftValue and rightValue.

Sum Node Diagram

Next, you need to add a Command Node to the action flow to set the device's audioVolume.

Setting the audioVolume

Finally, add a Command Node. The output value of the Sum Node will be the argument for the Command Node. Configure the Command Node to tell the device to set its audioVolume to the argument value:

Drag a Command Node to the flow editor area. Then, click the node to open the Node Configuration menu on the right. Click APPEND NEW ITEM.

Open the Command Node Configuration Menu

Select main in the component drop-down menu. Then, select audioVolume in the capability drop-down menu.

Select audioVolume Capability

A pop-up for the audioVolume capability opens. Select the setVolume command. Click SAVE.

Select setVolume Command

The Command Node should now have a dynamic input port for the audioVolume value. The input value determines the volume value for this device.

The New Input Port for Command Node

Now you need to connect a data path from the Sum Node's value data port to the Command Node's dynamic input port. You also need to connect the Start Node's main port to the Sum Node's trigger port and the Sum Node's main port to the Command Node's trigger port.

Here's the finished action flow:

Finished Action Flow

Testing Your Action Flow

To test the action flow, click the Try It button at the top right of the editor window. The flow editor should look like this:

Execution Flow

As you can see above, the current audioVolume value is 21, and the user's utterance value is 10. These two values are fed into the Sum Node, which gives the result of 31. This value is sent to the device using the Command Node to set the audioVolume to 31.

Using Other Arithmetic Operations

You can use any of these arithmetic operations in action flows:

  • addition (increase by n)

    Sum Node

  • subtraction (reduce by n)

    Subtraction Node

  • multiplication (increase by n times)

    Multiplication Node

  • division (reduce by n times)

    Division Node