Contents


Overview

Skill Level: Beginner

With IBM Watson IoT Platform you can set up rules and actions that trigger from your IoT device data. The following recipe uses a simulated device to set cloud analytics rules and actions for three metrics: temperature, humidity and object temperature.

Ingredients

To follow this recipe you will require:

  • An instance of Watson IoT Platform running in Bluemix.

Step-by-step

  1. Registering the iotsensor with Watson IoT Platform

    Before you can receive events and datapoints from the sensor, your must register it with Watson IoT Platform by following these steps. This step is only required the first time that your follow this recipe.

    1. In your Watson IoT Platform dashboard, select Devices from the menu pane, then click Add Device in the upper-right.Snap1
    2. Click Create device type. Creating a device type will make it easier to find and identify the iotsensor device after connecting it.
    3. Enter iotsensor_device as the device type name then click Next and then click Create.Snap3
    4. Click Next.
    5. Enter iotsensor as the device ID.
    6. Click Next.
    7. Provide an authentication token, or accept an automatically generated token. Providing a memorable authentication token may be useful for recalling it later, for example “MyDevice”.
    8. Verify that the summary information shown is correct and then click Add.
    9. In the device information page, copy and save the following device information
      • Organization ID
      • Device Type
      • Device ID
      • Authentication method
      • Authentication token

    Snap12

  2. Connect the iotsensor to the Watson IoT Platform

    This step connects the iotsensor to the registered device in your Watson IoT Platform organization.

    1. Go to: http://watson-iot-sensor-simulator.mybluemix.net/
    2. When prompted, enter the device information to connect to Watson IoT Platform.Snap14
    3. Verify that the connecting message changes to the name of your device, i.e. iotsensor. The device is now connected to Watson IoT Platform.
    4. In the Device browse dashboard, click your device and verify that data is being received.Snap16
  3. Optional step: Create a board and some cards

    At this point, you can create a board and some cards from your Watson IoT Platform dashboard. Boards and cards can be used to keep track of device data, for example the temperature, humidity and object temperature data being sent by the iotsensor. To set up a new board follow these steps.

    1. In your Watson IoT Platform dashboard click Create New Board in the upper right.
    2. Give the board a name and description.
    3. Click Next then Create.
    4. Click on the board you have just created.
    5. Click Add New Card in the upper right. 
    6. Select the style of visualization, and select the iotsensor as the data source.
  4. Create an iotsensor_device Schema

    To be able to create rules that are triggered based on the datapoints from your device properties, you must first map these properties in a device type schema.

    1. In the Watson IoT Platform dashboard, select Devices from the menu pane, then select Manage Schemas.Snap17
    2. Click Add Schema.
    3. In the Add a schema editor, select the iotsensor_device device type and click Next.Snap18
    4. Click Add property.
    5. Selected the From Connected tab.Snap9
    6. Select the following properties:
      • name
      • temperature
      • humidity
      • objectTemp
    7. Click OK to save the schema.
  5. Create iotsensor rules and actions

    This step creates the rules and actions which will trigger based on data from the iotsensor.

    1. In the Watson IoT Platform dashboard select Rules from the menu pane then click Create Cloud Rule.Snap13
    2. Click Create A Rule.
    3. Name the rule Temp too high.
    4. Select the iotsensor_device device type and then click Next.Snap141
    5. In the rule builder, click New Condition rule block to edit it.
    6. Select the temperature property and enter 21 as the static value to compare to.Snap161
    7. Click OK to save the condition. 
    8. Click the New Action block.
    9. In the Set The Action dialog, click Add action.Snap19
    10.  Add the email action and click OK.
  6. Activate the rule and send some data to test the rule

    1. In the Rules browser, activate the Temp too high rule.Snap23
    2. Open the iotsensor at http://watson-iot-sensor-simulator.mybluemix.net/ Note: If you are starting a new session, you must reconnect by using the same credentials as in step 2.
    3. Use the up arrow to raise the temperature to 22 degrees.Snap27
  7. View the dashboard alert and the email alert

    1. In the Watson IoT Platform dashboard select Boards from the menu pane, the select the Rule-centric Analytics card to open it.
    2. The rule is now included in the Rules I Manage card and alerts from this rule will appear in the Rule Alerts card.Snap28
    3. Select an alert instance to see the alert details, the triggering condition, the property datapoints at the time the rule was triggered, and the action that was taken. 
    4. Go to your email client to verify that the alert was sent as an email as expected.Snap29

1 Comment on "Using Rules and Actions with IBM Watson IoT Platform Cloud Analytics"

  1. […] Rules and Actions exercise will teach you set up rules and actions using real-time insights based on trigger […]

Join The Discussion