Build your own Smart Thermometer (and more!) with BigClown and Actions on Google

The goal of this project is to build your own Smart Thermometer powered by BigClown which will communicate with you using Google Asssistant.


Setting up the BigClown kit

First of all, we will setup our hardware. I will be using BigClown Climate Monitor Kit (if you want to measure CO2 levels too you can get the CO2 Monitor Kit which includes the Climate kit) to get data for the app.

What is BigClown? BigClown is really cool IoT Kit, the kit is composed of modules which are connected using their Plug’n’Make system, no need for soldering or wiring, you just plug the modules together and it simply.. works!

They are currently running an Indiegogo campaign, already raised 109% (32000$) and have two weeks more to go, so go support them!

Key features of BigClown (Source: BigClown Indiegogo campaign)
Plug’n’Make (Source: BigClown Indiegogo campaign)

I won’t cover exact steps on how to get BigClown working, because they have really good documentation. Just follow these steps. You can stop after the Enclosure part, or you can continue and see the stats in mobile app too!


Firebase part

We will be using Firebase Realtime Database to get free and easily accessible online storage. You don’t need to create new project in Firebase, Dialogflow already taken care of that, after signing in, just select the project with the same name as your Dialogflow project. From the left menu select Database and then Get started. Select the rules tab, delete the content and paste following:

This will give Node-Red access for writing our data to the database. These rules are not recommended to use in any production app (anyone can write anything), but for our project it is fine. Go to back to Data tab of the database and here you will find the Firebase database URL, save it, we will use it later.


Setting up the Node-RED

Node-RED is great tool for connecting the hardware, software and cloud. We will be using it to connect our BigClown kit to Firebase, from where we will get our data to Google Assisant. In Node-RED, you work with nodes, which you chain and connect together to get desired result.

After finishing the documentation steps, your Node-RED setup should looks like this:

Switch to debug tab on the top right side of the page. This is your log for everything yours Node-RED is doing. Everytime the temperatures, humidity etc. changes, you should see the change there. The structure of each message is following: Date, node, and then the highlighted red text, in which is the ID, it is in this format: node/…/…/…/(measure). From the input section on left, drag the mqtt node and put it inside the white area (Flow 1). Set the value of the node to the ID. Find the json node and connect the left side to the mqtt node.

Now, let’s install module for accessing Firebase from Node-RED. From top right menu, select Pallete, then install and search for node-red-contrib-firebase. Click install.

This will give you the option to insert new Firebase nodes. Grab the firebase.modify node and connect it with the JSON node. Click on it to set it up. It should look like this:

Firebase node setup to get the Bigclown data to Firebase (you can find your project ID in Firebase)

Repeat this step untill you got all your sensores connected to Firebase. Change the child path for each measure to this:

  • Temperature path: bigclown/temperature
  • Light intensity: bigclown/light
  • Humidity: bigclown/humidity
  • Atmosferic pressure: bigclown/pressure

We will use these paths to access the data from Firebase database in Dialogflow.

Final look at Node-RED setup:

Creating the Dialogflow project

Dialogflow will be our service for understanding human language and enable us to trigger our code from commands we define.

Access the Dialogflow console after making an account on console.dialogflow.com. After registration, you will get to main console page, click on the Create agent button.

Check the Dialogflow V2 API switch, configure your time zone and language if you need to. Leave the Google Project as it is. Give your agent a name you want and click create. It should now look like this:

Intents

Congratulation! You have succesfully created your first Dialogflow project. Let’s continue the good work with creating the first intent. Intent defines the action which should be launched from user action. When you create your first intent Dialogflow gives you nice explanation of what each parametr does.

Give your intent a name in the top part of the console. And save it (CTRL + S works for Dialogflow 😃), we will come back to it later.

Entities

From the menu on the left part of the console open Entities and create first entity. Entity is like an object identifying part of the sentense which contains some value for us. For example, our app will give us current values of temperature, humidity, light intensity and atmospheric pressure, so lets call our entity Measures. Then add first entry. Reference value is the “name” for one entry, and synonyms are… synonyms. The more you write here, the better. Repeat for each of measures we want to add. Add “All” entity to the end. We will use this one to tell all current values. Our entity should look like this:

Save this and move back to intent we created. Click on the training phrases. Here we will write the phrases which will trigger this intent. Try to write as many as you can, and use the entity we created. Good training phrases for this projects could be:

What’s the current temperature?

What’s the humidity in the air?

Current light intensity

Status of the room

.. and so on.

Notice that Dialogflow automaticly highlightes the entiny in our sentences. Move to the Action and parametrs and enter the action name, it can be same as intent name. We will use this to identify intent in our code. Click on responses and a switch the “Set this intent as end of conversation”. In the fullfilment section select the “Enable webhook call for this intent” and save the intent.

Current state of intent

Fulfillment

Here is where the brain and login of our app will be. In the datacenter far far way. Fulfillment helps us to get response back from the server. Our server will be taken care of by Firebase Cloud Functions. Selected the Fulfillment in left menu and enable webhook. Now follow the “Set up and initialize Firebase SDK for Cloud Functions” from this documentation of Firebase Cloud Functions for setting it up. Just be sure to connected to the same Firebase project. Basic knowledge of JavaScript is recommended for this part, but you can just copy the snippets and move to the next part. Paste this inside the index.js file located in functions folder:

Save the index.js file and use command “firebase deploy” inside command line to upload your function to Firebase Cloud Function. In the output of the command, you can see the message like this:

functions[dialogflowFirebaseFulfillment]: Successful create operation.
Function URL (dialogflowFirebaseFulfillment): https://us-central1-{yourProjectId}.cloudfunctions.net/dialogflowFirebaseFulfillment

Copy the URL and paste it as the URL in webhook. Save the fulfillment and select integrations.

Testing

Work is mostly done! In integrations, select “Integration settings” in Google Assistant and then click on “Test”, this will open up the Actions on Google console. From the left side, select “Simulator”, in there, you can test and debug your actions without using your phone or Google Home. In the input, write the invocation phrase “Talk to my test app” (You can change the name in Overview tab) and hit enter. Your bot will welcome you, then ask what you want. You can try any phrase you have written inside the get-information intent. Final result:

With this testing, you app is now available at all your devices in which you are signed in and have Google Assistant installed, including Google Home.

If you have any problems or questions, please write me down in the comments, I am sure we can solve them 😃

Today you have learned how to use many new things — great IoT kit BigClown, Node-RED for managing IoT devices, Firebase for Cloud Functions and Realtime Database, Dialogflow for understanding human language and Actions on Google for working with Google Assistant. That’s a great work for one project, congratulations!


What’s next?

Your basic bot is now finish, but don’t worry, this is not the end if you want to. Here are some other tips you can do to make this better:

  • Customise the messages, name of the bot, add persona! We build today just minimal version of what can be done. Add your bot some personality, customise the messages the suit your needs.
  • Add more functions, just with few more lines of code, the bot can tell you if for example the temperature is going up or down, give you warning if some of the values are too high or something else.
  • Go and make something different. Today you learned how to make a Smart Thermometer, but that doesn’t mean you have to stay there, go and build other beautiful things, now you know the basics how 😃

I hope this was useful to you and see you around in some other article!