Create a task to auto-adjust the led color to green
In this section you will learn the first steps towards mass management.
You will send the "setColor" message to devices belonging to a specified device scope.
Create a task
The task will set the LED on the virtual demo device to green.
Open the Tasks view
Click the + icon to create a new task.
Fill in the Settings
A name is required and could describe in human readable form what the task will do.
The type can be Device or System (in our example select Device).
The device selection by offers to choose a device set and filer conditions, ID, or a Groovy script. Choose the ID.
The list with all devices registered for your subscription will be displayed at the right side. Check the box for your demo device.
The ID is now listed as "Selected device".
For the concurrency limit you can set a number.
For the concurrency timeout you can set a number. These are the seconds upon which a non-confirmed execution will expire and will stop occupying room in the concurrency limit.
Optionally you can define a time constraint.
Continue with Next.
Fill in the Action
Click the Groovy DI API to get assistance on the available methods.
Search for the method to send the message you have applied to the LED feature of the demo device.
Copy the method signature to the main field.
Adjust it respectively to match the LED feature of the demo device.
import
groovy.json.JsonSlurper
def color =
'{"r":0,"g":255,"b":0}'
target.exec(
'led'
,
'setColor'
,
new
JsonSlurper().parseText(color))
Click Finish to launch the task.
In case your device is disconnected, you can connect it now and see if the task is executed.
Read the Tasks details
Retry the Tasks details
In case the device was not listening at the time the action was triggered, make sure the demo device is reported online and trigger the action again, manually.
Check the Executions view
In case of errors, you will find details in the Executions view
If your task shows "Finished with success" the log will look similar to this screenshot.
Check the result on the demo device
The LED should be green. If you filter for the incoming messages you will see how the full message looks like.
Further reading
Concepts > Device management concepts > Mass Management > Rules
How-to guides > Device Management > User interface > Create a task