What is a Command¶
The Node Command is an advanced scene connected to a node, this scene can have parameters that will be requested when the command is started. There is no limit to the number of the commands that a node can have.
Create a Command¶
In the node page search for the section "Commands", when you open that box you will find all the commands of the node. If the node has no commands than it is presented like this:
- The Type accepts only the values "num" for numeric, "str" for string and "bool" for booleans values,
- Name is the identifier of the input, the string that will be used in the script to retrieve the value,
- Default is the default value of the input,
- And last is the description of the field, to describe what the input is for or to specify what values are expected there;
The "Lua Code" button open a window where it is possible to write the code that will be executed at the start of the command;
Use input parameters in the script¶
When the command is started, the input parameters present are passed to the scene, but to don't have conflict between inputs there is a check that rewrite the name of the inputs making them all lowercase. To actually retrive the inputs value you need this code:
nameInput1 = "name" nameInput2 = "lastname" nameInput3 = "age" input = resiot_inputparam() name, err = json_getfield(input, nameInput1) if err ~= "" or name == "" then resiot_debug("Invalid 'name' input name.") return end lastname, err = json_getfield(input, nameInput2) if err ~= "" or lastname == "" then resiot_debug("Invalid 'lastname' input name.") return end age, err = json_getfield(input, nameInput3) if err ~= "" or age == "" then resiot_debug("Invalid 'age' input name.") return end resiot_debug(name) resiot_debug(lastname) resiot_debug(age)
There are 4 different ways a command can start, which are:
- "Node Command" menu: under the "Node/Devices" section of the menu, there is a page called "Node Command".
- Button type widget: between the varius types of widgets there is the Buttons type that allows to create a link to a script or command directly to the dashboard. When creating a widget select the "Buttons" type: