Define and execute an Action in Node-RED
Define Actions on your devices and call them from the cloud. For example, use actions to turn on/off a lock or call a function that reboots your device.
From the side navigation tab of the device page, click on Create Action. Set the name, description and hit submit. For this example, we will name the action "Bash Command" since we want to execute a bash command from another device or from the cloud on this device.
Ensure your device is connected to the cloud by checking if you see the green light on the device page, Enable the Node-RED connection in the Remote Connections tab, and hit Connect.
To define an action in Node-RED, drag and drop an action start and an action finish. Every action start node needs to be finished with an action finish node to confirm that the action was properly executed. When an action is triggered with an HTTP request, this will result in an HTTP response code of 200 that confirms the request has been fulfilled properly
Double-click on the action start node, and then click on the edit button to add the device API Key credentials if you haven't configured the connection yet.
Next, we will click the refresh button in the Topic and select the Action that we will like to execute, in this case "Bash Command", and click Done.
Connect the action start node to your the function / actuator that needs to be triggered when the action is called. In this case, we will connect it to an exec node to execute a command. Drag and drop an exec code and connect its threads similar to the following figure. Also, double click on the exec node and check mark the Append option to pass the msg.payload (the HTTP request body) to this node. This way, once we execute this Action from the cloud, our command will be executed on the device and its stdout results will be sent back to us.
You can send a HTTP Post request to execute / call an Action. You can find the action uuid from the right hand side navigation.
Execute a Device Action
Read Last Status of a Device Action