Bosch IoT Device Management

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

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

You will create a rule which switches the LED on the virtual demo device green and red based on the switch status.

In Groovy such a script looks like the following snippet.

import groovy.json.JsonSlurper
 
def isOn = target.feature('switch').property('status/on')
def color = isOn ? '{"r":0,"g":255,"b":0}' : '{"r":255,"g":0,"b":0}'
target.exec('led', 'setColor',new JsonSlurper().parseText(color))

In short, it acts like the following: Listen on the events of the switch. If the switch is on, set the color to green, else to red.

However, we will go step by step and explain how it was created.

Open the Bosch IoT Manager UI - Rules Management perspective

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

In case it is not there, use the search, and click the star icon to pin it to your navigation bar.

images/confluence/download/attachments/1774525276/rules-UI.png

The Bosch IoT Manager UI will open in a new browser tab where you find the entry point to create a new rule for the LED color automation scenario.

images/confluence/download/attachments/1774525276/rules-management-create.png

Create a rule

  1. Dashboard > Rule Management > Search Rules is opened by default.

  2. Click Create Management Rule and let the Create Rule dialogue which pops-up lead you though all the steps necessary.

  3. The fist dialog Action Script requires to set the name and the specific script for your use case.

    1. Name - set a speaking name, such that other operators get an impression on what yous script will do.

    2. Script - copy the snippet from the top of the page.

      images/confluence/download/attachments/1774525276/create-rule-script.png
    3. Continue with Next >

  4. The Execution Scope defines which parts of you system should be affected.

    1. As you want only the demo device to react, the pre-selected Device Scope is the right one.

    2. Choose for the Scope Selection Mode the Ids Selection
      images/confluence/download/attachments/1774525276/create-rule-scope.png

    3. Click Add ... to open a list of all your devices, there select your device ID > confirm with OK.

    4. The Device Scope table will show all selected devices.

    5. Continue with Next >

  5. The Rule Triggers section defines when the rule should be executed

    1. Click Add ... to open a list of options

    2. Select Event Based, as you want that the color settings react on the switch

    3. For the field Event Type click the Browse Events button to get a list of all "expected" events, based on all features of all registered devices.
      images/confluence/download/attachments/1774525276/create-rule-event-type.png

      1. Select FeaturesEvents > com.bosch.iot.suite.example:Switch:1.0.0 > PropertyChanged > StatusChanged.

      2. Your selection will be stored in the Event Type field.

    4. Continue with OK.

  6. Click Finish.

  7. Finally, enable the rule.
    This will activate the rule on each change event which Bosch IoT Manager receives, and could be de-activated after the demo in case you want to save traffic.

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

Read the rule details

  • Navigate to Dashboard > Rule Management > All Rules.

  • Click the rule name > Rule Details view will open in the section beneath.

images/confluence/download/attachments/1774525276/read-rulet.png

Change details of your rule

  • In case you want to apply the rule to multiple devices of the same type, we recommend you to create a group, and then assign the rule to the group.

  • In case the rule fails to execute, the counter of errors is displayed in section Finished With Errors. We recommend to pause or disable the rule and analyze the cause.

  • The edit icon in the view bar will give you access to refine all settings, and re-enable the rule afterwards.

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