Overview

Skill Level: Intermediate

The User should have basic understanding of Watson IoT Platform (WIoTP)

IntroductionIBM Watson IoT Platform Cloud Analytics enables you to perform analytics on real-time data from your IoT devices to gain insights about their health and the overall state of your operations. The Watson IoT Platform Cloud Analytics is designed to handle real-time device data feeds and perform actionable analytics on top of them. The incoming data […]

Ingredients

Step-by-step

  1. Introduction

    IBM Watson IoT Platform enables you to perform analytics on real-time data from your IoT devices to gain insights about their health and the overall state of your operations. The Watson IoT Platform Cloud Analytics is designed to handle real-time device data feeds and perform actionable analytics on top of them. The incoming data is interpreted through a virtual data model that can be augmented with asset master data from an asset management system.

    In addition, user-defined rules are applied to the real-time streaming data to identify conditions that need attention. The action engine lets you define automated responses to the detected conditions, such as sending an email, triggering an IFTTT recipe, executing a Node-RED workflow, or using webhooks to connect to a variety of web services. And finally, real-time data is also displayed in a configurable dashboard for an at-a-glance view of the location, data, metrics, and alerts for your IoT devices.

    WIoTP_Cloud_Analytics_v2

    Click here to read through the detailed documentation on IBM Watson IoT Platform Cloud Analytics, to further understand on Managing Rules & Actions, Actions available, etc.

     

  2. What will you learn in this Recipe?

    In this recipe, you will learn how to create actions for the rules that you have created in IBM Watson IoT Platform Cloud Analytics.

    The recipe will detail you through:

    For creating the Watson IoT Platform service in IBM Bluemix and creating Schema’s, Rules in WIoTP, you can refer to the following recipes:

    1. Real Time Data Analysis Using IBM Watson™ IoT Platform Analytics
    2. Vehicle telematics analytics using IoT Real-Time Insights

     

  3. Actions in Watson IoT Platform Cloud Analytics

    Actions in IBM Watson IoT Platform Cloud Analytics can be used to perform a whole lot of things like sending messages to service personal, creating device service requests, create work orders and much more.

    The supported actions in IBM Watson IoT Platform Cloud Analytics are

    1. IFTTT
    2. Send Email
    3. Webhook
    4. Node-RED

    In the following sections, we will see in detail on how to configure each of the action. But, before we move on, make use of the following Create Toolchain button to quickly deploy relevant services on to Bluemix, that shall be utilized in the scope of this recipe.

    Deploy relevant services on Bluemix

    Click on the Create Toolchain button provided below, provide a Custom Name to your application and choose to click on Create button, to quickly deploy the Watson IoT Platform, Node-RED application and Cloudant NoSQL DB, as part of the Bluemix starter app.

    Toolchain-8

    Note: If you are a User using the United Kingdom Region in your Bluemix environment, then please make use of the steps mentioned in the IoT Recipe Deploy Internet of Things Platform Starter service on Bluemix to deploy the setup. Alternatively, you can also try using the Deploy to Bluemix button, to deploy the setup under your United Kingdom Region, provided your Jazzhub account is validated. Users of US South Region can ignore this step.

    deploy

    Post successful deployment, you shall have all three of the above mentioned services, up & running in your Bluemix environment.

    Open the Bluemix Dashboard and click on the Application service that you have currently deployed. You should see the Watson IoT Platform listed under the Connections. Click on the WIoTP service and choose the click on Launch button to launch the WIoTP Dashboard.

    Access the Node-RED application

    Access the Node-RED application by clicking on the View App option available, post deploying your application and then choosing the option Go to you Node-RED flow editor, to access the editor.

    Parallelly, you can also access the Node-RED editor directly by accessing the following URL

     http://<your-application-name>.mybluemix.net/red

    The Node-RED editor has the default set of nodes and in the scope of this Recipe, you would need Watson IoT Node(s), as well.

     

  4. IFTTT

    IFTTT is used to automate everything from your favorite applications to websites to app enabled accessories. IFTTT has triggers and actions. Triggers are used to trigger the actions.

    IFTTT action in Watson IoT Platform is used to trigger an IFTTT recipe when a rule is triggered. IFTTT action uses the Maker Channel on the IFTTT.

    In this tutorial, you will learn how to integrate Watson IoT Platform Cloud Analytics with IFTTT. So when a Rule is invoked in Watson IoT Platform Cloud Analytics, it will create a To-Do in the Service Personal’s Evernote.

    Refer to the Watson IoT Platform Cloud Analytics documentation on IFTTT to further understand the managing of Rules & Actions with IFTTT

  5. Configure the Maker Channel in IFTTT and create a Recipe in IFTTT

    1. Go to Maker Channel

      if1

    2. Click on Connect
    3. Now your Maker Channel will be connected. Copy your Key that is generated. It will be used later in the tutorial.
    4. Next, click on Receive a web request. Lets create a new IFTTT recipe. Click on Create a new Recipe.
    5. In the Choose Trigger Channel, search for “Maker“. Select Maker.

      if2

    6. Click “Receive a web request“.
    7. Enter the Event Name “rti-trigger“.

      if3

    8. Select That. Now Choose Action Channel.
    9. In this tutorial, we will use the Evernote Action Channel to create new ToDo for every trigger from Watson IoT Platform Cloud Analytics.
    10. Search for “Evernote” and select on Evernote.
    11. Select Append a to-do to note .

      if4

    12. Enter the Title of the action and the content of the To-Do
    13. You can use Event Name and 3 values that you can pass from WIoTP.

      if5

    14. Value1″ is the value passed from WIoTP. We will configure that in the next section.
    15. Click Create Action.
    16. Review the recipe and click Create Recipe.
  6. Configure Watson IoT Platform Cloud Analytics for Action(s)

    This section helps you with the steps to configure Action(s) on the Watson IoT Platform Cloud Analytics. 

    Note: You need to have a Device-Type in place, before you can go ahead with creating new set of Actions using the following set of steps. If you do not have a Device-Type already in place, then, make use of this recipe to create a Device-Id and Device-Type for yourself.

    1. On the Watson IoT Platform Cloud Analytics Dashboard, click on RULES on the left hand column and then click on the Actions tab
    2. Click on Create An Action on the top right corner, or alternatively, you can choose to click Add a rule action, if no actions exists already

      Actions_Tab

    3. Fill in the Action Type Name & Description.
    4. In the Type dropdown, select IFTTT. Click on Next to continue

      Create_Action-Action-Type

    5. Enter the Key that you generated when you created the Maker Channel in Step 3 of Configure the Maker Channel in IFTTT
    6. Enter the Event “rti-trigger” that you created in Step 7 of Configure the Maker Channel in IFTTT.
    7. Three (3) Values can be passed from WIoTP to IFTTT Maker channel. In this tutorial, we will use Value1 to pass the device event message that triggered the action. For more information on Variable substitution like message, please refer to the section below.

      Create_Action-Configure

    8. Now, when the Rule is invoked in the IoT Real Time Insights, it will trigger the Maker Channel in IFTTT which in turn creates the To-Do in Service personal ‘s Evernote.

      Note : You can use Variable substitution to dynamically include the device data in Values 1-3

      In Value 1-3

      {{timestamp}}       : The timestamp from the message{{tenantId}}        : The ID of the Real-Time Insights service{{deviceId}}        : The ID of the device.{{ruleName}}        : The name of the rule that includes the action.{{ruleDescription}} : The description of the rule that includes the action.{{ruleCondition}}   : The rule condition that triggered the action.{{message}}         : The raw device message that included the data point value that triggered the rule

      Click on Finish to complete the creation of Action
       

      At this step, we have successfully configured the IFTTT action in the Watson IoT Platform Cloud Analytics. Next step, details how to setup Email Action

    Refer to the Watson IoT Platform Cloud Analytics documentation on IFTTT to further understand the managing of Rules & Actions with IFTTT

  7. Send Email

    When a Rule Threshold is broken, this action can be used to send an Email to the concerned personal.

    1. On the Watson IoT Platform Cloud Analytics Dashboard, click on RULES on the left hand column and then click on the Actions tab
    2. Click on Create An Action on the top right corner
    3. Fill in the Action Name & Description.
    4. In the Type dropdown, select Send Email.

      Create_Action-Action-Type_Email

    5. Enter the Subject of this email.
    6. Enter the Email Recipient ID in the To field, if any, in addition to you. If you want to include others, you can enter their Email IDs in the CC field.
    7. If you do not want the device data to be included in the email contents, then plan to Turn Off the ‘Include Data’ option

      Create_Action-Configure_Email

    8. Click on Finish to complete creating the Action

    Now the Send Email action is setup. You can bind this action to the Watson IoT Platform Cloud Analytics Rule.

    Add_New_Cloud_Rule_Summary

    At this step, we have successfully configured the Send Email action in the WIoTP. Next step, details how to setup WebHook Action

    Refer to the Watson IoT Platform Cloud Analytics documentation on Email, to further understand the managing of Rules & Actions with Email.

  8. Webhook

    Webhook action is used to make an HTTP request to a WebHook enabled web service. For example, this can be used to create a new Work Order in an Asset management system when a device reports an abnormal reading.

    1. On the Watson IoT Platform Cloud Analytics Dashboard, click on RULES on the left hand column and then click on the Actions tab
    2. Click on Create An Action on the top right corner
    3. Fill in the Action Name & Description
    4. In the Type dropdown, select Webhook action

      Create_Action-Action-Type_Webhook

    5. Enter the URL of the Target Webhook Server
    6. Select the HTTP Method to execute on the Webhook Server
    7. Enter Username / Password to pass the credentials to the Webhook Server. Include only if required
    8. Add Header as Key / Value pairs

     

    The Following properties are only available when the Method is selected for OPTIONS, PATCH, PUT, POST and DELETE

    1. Select the Content-Type for the Webhook request. Available options are JSON, XML, WWW form URL encoded, or plain text.
    2. Body for the webhook call.
    3. Edit the Body Message with the content as needed

      Create_Action-Configure_Webhook

    You can use Variable substitution to dynamically include the device data in the URL, Headers and Body of the Webhook call.

    In URL, Head, and Body

    {{timestamp}}       The timestamp from the message{{tenantId}}        The ID of the Real-Time Insights service{{deviceId}}        The ID of the device{{ruleName}}        The name of the rule that includes the action

    In Body only

    {{ruleDescription}} The description of the rule that includes the action{{ruleCondition}}   The rule condition that triggered the action{{message}}         The raw device message that included the data point value that triggered the rule

    At this step, we have successfully configured the Webhook action in the IoT Real-Time Insights. Next step, details how to setup Node-RED

    Refer to the Watson IoT Platform Cloud Analytics documentation on Webhook, to further understand the managing of Rules & Actions with Webhook.

  9. Node-RED

    Use Node-RED action to invoke the Node-RED flow when a threshold is breached in IoT Real-Time Insights Rules. For more information on creating Node-RED flows, refer to Node-RED recipe.

    1. On the Watson IoT Platform Cloud Analytics Dashboard, click on RULES on the left hand column and then click on the Actions tab
    2. Click on Create An Action on the top right corner
    3. Fill in the Action Name & Description
    4. In the Type dropdown, select Node-RED

      Create_Action-Action-Type_Node-RED

    5. In the URL field, enter the URL of the target Node-RED HTTP input node
    6. Enter the Username / Password to pass the credentials to the Node-RED. Include only if required
    7. Edit the contetnt of the Body field of Node-RED, as needed

      Create_Action-Configure_Node-RED

    You can use Variable substitution to dynamically include the device data in the URL & Body

    In URL, and Body

    {{timestamp}}       The timestamp from the message{{tenantId}}        The ID of the Real-Time Insights service{{deviceId}}        The ID of the device{{ruleName}}        The name of the rule that includes the action

    In Body only

    {{ruleDescription}} The description of the rule that includes the action{{ruleCondition}}   The rule condition that triggered the action{{message}}         The raw device message that included the data point value that triggered the rule 
    TIP : Use the below Node-RED flow to get a sample flow for using the Node-RED action 
    1. Click on the Menu button on the top right corner of the Node-RED flow
    2. Select Import and then Clipboard
    3. Copy the content below and paste in the Clipboard and Select OK
    4. Click Deploy. The flow is now active. When a Rule is invoked in IoT Real-Time Insights, this Node-RED flow will be invoked
      [{"id":"9b67744e.89b88","type":"debug","name":"","active":true,"console":"false","complete":"false","x":421,"y":227,"z":"1f3a9428.039e64","wires":[]},{"id":"4f95546d.dad284","type":"http response","name":"Action Response","x":450,"y":91,"z":"1f3a9428.039e64","wires":[]},{"id":"92660a90.f0d7f8","type":"http in","name":"Action Receiver","url":"/action","method":"post","swaggerDoc":"","x":103,"y":192,"z":"1f3a9428.039e64","wires":[["9b67744e.89b88","4f95546d.dad284"]]}]

      nodered

     

    Now, the Node-RED action is successfully setup, you can bind it with a Rule.

    Configure_SpeedRule_Summary

    At this step, we have successfully configured the Node-RED Action.

    Refer to the Watson IoT Platform Cloud Analytics documentation on Node-RED, to further understand the managing of Rules & Actions with Node-RED.

  10. Conclusion

    In this recipe, we have learned how to create various Actions in the IBM Watson IoT Platform Cloud Analytics. Now developers can use this recipe as a template to build powerful analytics solutions.

    As a next step, look at the list of analytical and cognitive recipes published around Watson IoT Platform to analyze the IoT events.

    If you have any comments/feedback on this recipe, please leave them below.

2 comments on"Perform Actions in IBM Watson IoT Platform Cloud Analytics"

  1. ShivaKumar@1995 July 04, 2017

    Hey ! I wanted to refer to your recipe to create a node-red app and I saw that the json format code for importing the blocks to the node-red app aren’t fully visible. Please could you help me view it? Thank you

Join The Discussion