Arithmetic Operations Using the Sum Node

This guide assumes familiarity with the following information:

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 the volume or brightness level, by a specific integer within a specified range. While this guide highlights the addition operation, you can also use other arithmetic operations in Bixby Home Studio (BHS). The device used in this guide is a SmartThings-enabled TV.

This guide uses the example "Increase the volume of the television" to raise the TV's volume level by a reasonable amount in response to the user's command.

The volume-increase Voice Intent

The goal is to define an action flow with the volume-increase voice intent for the device. For this voice intent, the user should be satisfied that the volume has increased a reasonable amount.

Example: "Increase the volume of the television."

Fetch an Attribute Value

You need to add and configure an Attribute node to fetch the attribute value. In this example, you should fetch the current volume value of the TV, which is an attribute of the audioVolume capability.

To add and configure this node, do the following:

  1. Drag the Attribute node from the action flow nodes sidebar to the editor area.

  2. Select the node. This opens the Node Configuration menu on the right of the editor area.

  1. 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 end of this section.

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

The Node Configuration window will look like the following:


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.

Add With the Sum Node

A satisfactory volume level varies from person to person; in this guide, you'll increase the current volume level by 10.

  1. Drag a Constant node from the action flow nodes sidebar to the editor area.
  2. Set its value type to Integer.
  3. Give it the value 10. The values of the Attribute node and the Constant node get passed to a Sum node, whose output sets the final audioVolume of the device.
  4. Drag a Sum node from the sidebar to the editor area. 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.
  5. Connect the Constant node to one input port of the Sum node, and the Attribute node to the other input port.

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

Set 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:

  1. 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.
  2. Select main in the component menu.
  3. Select audioVolume in the capability menu. A pop-up for the audioVolume capability opens.
  4. Select the setVolume command.
  5. Click SAVE. The Command node should now have a dynamic input port for the audioVolume value. The input value determines the volume value for this device.
  6. Connect a data path from the Sum node's value data port to the Command node's dynamic input port.
  7. Also 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:

Test 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:

As shown in the previous image, the current audioVolume value is 21. To increment it by 10, configure a Constant node to have a value of 10. Those 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.

Next Steps

You can use any of the Math nodes while performing arithmetic operations. For more information about the various operations, see the math section in the Nodes reference page.

You can also perform calculations with the Sub Graph feature to reduce the complexity of a graph and separate functionality into distinctive and reusable sections.

The Node Recommendation feature enables you to get recommendations for next possible nodes, and can make it easier to create a graph.

For an additional example, see the "Increase the Brightness of the Device by a Value" Sample Graph.