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.
Let's choose a task of increasing the brightness of a bulb by a value stated by the user's voice command: "Increase the brightness of the Bulb by {value}."
The goal is to define the action flow for the Brightness Increase voice intent for the device.
The bulb's brightness is defined and controlled as a switch level SmartThings capability. This capability has only one command, setLevel
, which sets the level of the bulb's brightness to a given value. It is important to note that this capability does not itself have any increase command.
For this intent, the user is expected to give an integer value in the voice command: "Increase the brightness of the Bulb by 10"
As you learned by sending a device command with an argument, the parameter value (10
) is passed down to the Utterance Parameter
node. In the action flow, add an Attribute
node, and configure it to fetch the current brightness value of the device. The values of the Utterance Parameter
node and the Attribute
node are passed to a Sum
node, whose output will be used to set the final brightness of the device.
Finally, in the action flow, add a Command
node with an argument as the output of the Sum
node, and configure it to send a command to the device to set its brightness to the argument value, like in other guides.
First, let's look at the action flow without the Sum node:
The Sum node has two input data ports, leftValue
and rightValue
, and one output data port. The output returns the result of adding leftValue
and rightValue
.
When you test the action flow with the Try It button, observe that the current value of switch level is 40, and the user's utterance value is 10. These two value are fed into the Sum node, which gives the result of 40. This value is sent to the device using the Command node to set the switchlevel
to 50.
Similarly, other arithmetic operations can be used to subtract (reduce by n
), multiply (increase to n
times), divide (reduce by n
times), and perform similar operations.