Skip to content

Node Command

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:

To add en empty command you just need to to click the "Add New" button and the next line will be shown:
The "Name" field specify the name off the command, it is a normal field that can contain special characters; The "Tag" field is a unique code that can be used to identify this specific command; The "Input" button, if clicked, show a window where it is possible to configure some parameters that will be asked as inputs at the start of the command:
As the image shows, each input is divided in 4 parts: [TYPE]NAME(DEFAULT)DESCRIPTION;
- 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;
The "Hide if ReadOnly User" check allow the admin to hide the unwanted command from a user with "ReadOnly" privileges that has the policy to see the node; The "Show in data list" check allow the button to be seen
After all the fields are filled, the command will be created once the node is saved.

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.")
lastname, err = json_getfield(input, nameInput2)
if err ~= "" or lastname == "" then
    resiot_debug("Invalid 'lastname' input name.")
age, err = json_getfield(input, nameInput3)
if err ~= "" or age == "" then
    resiot_debug("Invalid 'age' input name.")


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".

This page is very simple, select in the combo field the node which has the command you need, fill the input parameters if there are any and click "Run" to start the command.
- Command by list: as explained in the Create a Command section, if the "Show in data list" check is activated then it is possible to start a command directly from the list of nodes.
- 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:
The section "Widget Elements" will contain all the commands that will be displayed, by clicking the button "New Elements" a row is added where it is possible to select the desired node and its command:
This will create a widget on the dashboard that will contain a button to start the command:
- From a script: it is possible to start a command from a script lua, you can find the code Here