Skill Level: Beginner

IoT developers

High Level Architecture The image below represents the high level Architecture of the the tutorial. In this tutorial, you will learn how to use the device events from the Watson IoT platform with the Watson Dialog service. Pre-requisite step: Create Watson IoT service in BluemixFollow the steps present in the following recipe Visualizing data in […]


Software Requirements:

  1. Bluemix Account
  2. Watson IoT Platform Service


More than 256MB RAM might be required to deploy this application. If the memory usage exceeds 256MB in the free trial accounts (Bluemix Trial Account and Standard Account), the application might not work as expected.

We suggest that you upgrade to Pay-as-You-Go or Subscription account to enjoy the full-range Bluemix services.


  1. High Level Architecture

    The image below represents the high level Architecture of the the tutorial. In this tutorial, you will learn how to use the device events from the Watson IoT platform with the Watson Dialog service.

  2. Pre-requisite step: Create Watson IoT service in Bluemix

    Follow the steps present in the following recipe Visualizing data in Watson IoT Platform to register your device, send and view real-time data in the Watson IoT platform.

    You need to bind the Watson IoT Platform service you have created in Visualizing data in Watson IoT Platform recipe with the Bluemix application that you will create following steps described in this recipe. Steps to bind service is explained in Bind Watson IoT platform service with the Application section below.

  3. Install the application

    Click on the Create Toolchain Button below to deploy the application in Bluemix.


    Note: If you are a User using the United Kingdom Region in your Bluemix environment, then please make use of the following Deploy to Bluemix button, to deploy the setup under your United Kingdom Region. Users of US South  Region can ignore this step.


    Provide a Custom Name to your Application and click on Create to go ahead and deploy the application in your Bluemix setup.

    In the scope of Create Toolchain action, the following processes are executed automatically.

    1. Clones the application code into your Bluemix setup.
    2. Create the application in Bluemix.
    3. Creates the necessary services for this application.
      1. Watson Dialog service.
    4. Deploys the application in Bluemix.
  4. Starting the Application

    1. After the successful deployment, navigate to the Bluemix dashboard.

    2. You should now have the new Application, say iot-dialog-jeffdare-125, listed in your Bluemix Dashboard. Click on it, to open the application in Bluemix.

    You will notice that Watson Dialog service is already bound with this application. In the next step, you will learn how to bind the Watson IoT service with this application.

  5. Bind Watson IoT platform service with the Application

    In this step, you will learn how to bind the Watson IoT service that you created in the previous recipe(https://developer.ibm.com/recipes/tutorials/visualizing-data-in-watson-iot-platform/) with this application.


    1. Navigate to the Connections option on the left hand side pane
    2. Click on Add Existing (If you have already added Watson IoT Platform conforming to the Pre-Requisites) or click on Add New to Create a Watson IoT Platform and then add it to the Connections section.
    3. Note: the name of the Watson IoT service will differ from the one that is present in the screenshot.


    4. Click Add. This will restage the application to bind the new service to the application.

    5. Click Restage in the next screen to restage.
    6. The application will successfully restage and you should now be able to see both the services listed under the Connections option, within your Application dashboard


  6. Add Metadata for your device created in Watson IoT platform service

    The Watson IoT platform supports storing Metadata for your devices. The application created in the last step and bound to Watson IoT Platform service requires a specific Metadata associated with your device. Use the following steps to add a Metadata to your device.


    Go back to the Watson IoT dashboard, click on the device you created and add the following JSON metadata. For example,

    "Office Number": "Office MR102"



    After entering the metadata, click on Confirm Changes.

  7. Conversing with Dialog application

    1. Now go back to the Bluemix Dashboard, click on the URL highlighted to open the application.

     This is the Conversation IoT application. You can converse with this application and find the temperature of your office locations.

    First ask a question and see how the Dialog application responds to your questions.


     Next, it will respond you with the temperature of the office room.


    You can further ask other questions to the application.

  8. Creating/Editing your own Dialogs

    In this step, we will edit the Dialog so that we can see the changes in this application.


    1. Go to Bluemix application Dashboard.

    2. Click on the Edit Code present on the top right corner.

    3. Now it will open the Jazzhub Editor to edit the code online.

    4. Now go to dialogs -> temp.xml file


    5. Now let us change the welcome message. Go to line 7.

    6. Edit the line Hello, I am Tom, your office building concierge. to your custom message.



    7. Next, we need to commit this change and publish this change set.

    8. Go to the Git Repository tab present in the left sidebar.


    9. Now, give a commit message for this change. And click on Commit


    10. After the commit, this changeset will be present in the outgoing tab on the left sidebar.

    11. Now click on Push, to push the change sets to the master branch. This will also cause the application to restart for publishing the new changes.

    12. Now your application will automatically restart.


    13. You can click on “BUILD & DEPLOY” to follow the progression of the staging.



    After the successful restart of the application, you will be able to see the new custom welcome message in the dialog application.


  9. Validate the temperature using this Application

    In this section, you will learn how to add additional inference about the temperature. You will add statements that

    1. Validate the temperature, if the temperature is high or low in the room

    2. Recommend an action to the user.


    1. Go back to the Editor in Jazzhub

    2. To enable the validate code, please uncomment the code in app.js at line number

    a. Line 209 – 212

    b. Line 261 – 274


    3. After uncommenting the code, Commit the changes.

    4. Go to the Git repository to commit the changes and push the changes to the master branch.


    5. After push request, the application will automatically restart.

    6. Now, after the successful restart of the application, go back to the application to see the changes.





    Now, you can also try to change the MINIMUM, MAXIMUM(Line 259,260) level of the temperature and try different messages to change the way the conversation proceeds.


  10. Edit the Dialog to add a new script in the conversation

    In this step, you will learn to how to add a new script in the dialog template. We will add a script to respond to the user, when he replies with a “Thank You” to the conversation.


    1. Go to the Jazzhub editor.
    2. Go to file dialogs/temp.xml.
    3. Uncomment the lines from 81-98.
    4. After the changes, commit the changeset and push the code
    5. The application will restage and the push request.



  11. Advanced Changes in your Dialog service

    In this step, you will learn how to change this dialog application to read the humidity data point instead of the temperature. So in for this, the device has to send the following data



    humidity : 23



    1. Go to the Edit code in the online Jazzhub Editor

    2. Go to file app.js and go to line 147.

    3. Edit the datapointName to the new Data point. (Note: This must be the same as the data being published from the device).

    4. Now go to file dialogs/temp.xml

    5. Go to line 115, and edit the response statement The temperature at {location} is {value} degree with the new custom statement. You can also edit the validate code to validate the humidity value.

    6. Now go to the Git repository tab present on the left sidebar.

    7. You will be able to verify the changes you made in the code.

    8. Then click on Commit and then Push the change set.


    Now you will be able to see the new changes in your application.



  12. Conclusion

    Now after successfully completing this tutorial you have learnt

    1. How to create a Watson Dialog application

    2. Integrate the Watson Dialog service with Watson IoT platform

    3. Read events from Watson IoT platform and respond in the Watson Dialog service

    4. Edit the dialog xml

    5. Add custom code to add intelligence to the conversation.


    Please leave your feedback/queries on this recipe on the comments section below.

Join The Discussion