Bosch IoT Device Management - will be discontinued by mid 2024

Create a rule to auto-adjust the led color according to the switch settings

In this section you will learn the next steps towards automation.

You will create a rule which triggers changes the led color depending on the settings of the switch feature.

Create a second demo device and group both with a Tag

Provision the deviceSet the rule trigger based on the DeviceOnlineEvent

Use the demo device Vorto model and make sure the name is for the new device unique.

Create the tag

images/confluence/download/attachments/2232980481/create-tag.png

Group the two demo devices with the tag

Assign the devices to the tag. One by one.

images/confluence/download/attachments/2232980481/device-to-tag.png

Activate the checkbox of the tag to check the correct filtering.

Result should be as shown in the screenshot.

images/confluence/download/attachments/2232980481/tag-demo-device.png

Create a rule which will be applied to all devices grouped with the tag

Starting at the Bosch IoT Suite Console click the Rules entry in the left navigation.

Click the plus icon in the upper right corner of the list to get the "Create rule wizard".

Deviating for the task, you can edit a rule settings, triggers and actions multiple times.

Set the Settings

In this example, want to apply the rule only on devices which implement the led feature.

  1. Enter a Name for the rule.

  2. In section Scope > Tags choose the demo-device tag for filtering the scope to demo devices only.

  3. In section Execution options make sure that Once per device is deselected to allow rule execution multiple times per device.

  4. Continue with Next.

images/confluence/download/attachments/2232980481/rule-on-tag.png

Set the Rule trigger to be based on a FeatureEvent

The next step is to set the appropriate trigger to the rule.

In this example we will use an event type trigger based on an Eclipse Vorto model:

  1. Add a new trigger via the plus icon.

  2. Choose the trigger type. Select Event Based.

  3. Open event type selection dialog by clicking the Select from event browser icon.

  4. Search for event type. For this example search for FeaturesEvents/com.bosch.iot.suite.example:Switch:1.0.0.

  5. Select the event type row - FeaturesEvents/com.bosch.iot.suite.example:Switch:1.0.0/PropertyChanged/Status/on.

  6. Click Select.

  7. Click Save.

  8. Continue with Next.

images/confluence/download/attachments/2232980481/create-trigger-featureEvent-statusOn.png


Set the Action

import groovy.json.JsonSlurper
 
def isOn = event.value
def color = isOn ? '{"r":0,"g":255,"b":0}' : '{"r":255,"g":0,"b":0}'
target.exec('led', 'setColor', new JsonSlurper().parseText(color))

Save the Rule

Click Finish, to save your new rule.

Click Enable rule, to enable the rule immediately.

images/confluence/download/attachments/2232980481/rule-new-enable.png


In case your device is disconnected, you can connect it now, and see if the rule is triggered.

Hint: If you increase the sensor update rate of your demo device connection, then you can focus more on the triggered rule executions caused by changing the switch.

Play with the switch and depending on the state "on" or "off" the LED color should change respectively.

Once the rule is enabled the play icon within the circle changes into a stop icon, allowing to disable the rule.

The wrench icon holds a menu of further actions to pause or re-run your rule.

images/confluence/download/thumbnails/2232980481/rule-pause.png

Summary

Your first rule gives an example how you could automate your device management based on values reported by the device itself.
The digital twin layer (Bosch IoT Things) creates a change event for all changes it receives from the connectivity layer (Bosch IoT Hub) and forwards them to the device management layer (Bosch IoT Manager).
The device management layer makes use of the pre-defined "operation" of a feature (in our case LED provides setColor) and sends a message to the device.
The device tries to execute and reports again all changes to the cloud services.

Further reading