ESP8266 With DHT11 to AlexaPI to Dashboards!

Introduction: ESP8266 With DHT11 to AlexaPI to Dashboards!

About: My name is Joao Duarte, and I am an IT Consultant, Electronics enthusiast,Maker and Gamer. I’m from the south of Portugal, and besides of the geek things, I also like fishing, travelling with my wife, ...

Hi guys!
In this insctructables I will be teaching how you can request Alexa about the Temperature and Humidity readings from your DHT sensor, and also how can you integrate the data from the sensor into different Dashboards.

Sorry but since I'm uploading this project for IoT Builders Contest, and the deadline is today, I'm without time to make a video showing how things work, but I will definitely do one! This was mostly made in just one day so please tell me if you found any errors!

The purpose of this is, while you are at home, you can ask Alexa about your sensor values, and while you are outside your house, you can check your dashboards. Note that this project can be scaled to many other capabilities since you can use any type of sensor you want, and even add actuators to it.

So why am I doing this???

In the first place, the idea of arriving home and talk to it, in my opinion, is just mind blowing!

Imagine for example people that have reduced mobility, how this kind of interactions can change their lives. A simple example, like automating a ceiling light, an heater/dehumidifier or any other electrical device can make a huge difference.

Of course the lazy ones can also benefit from it xD

I've also made this project to participate in the IoT Builders contest (Please use the button in the right corner to VOTE :D), so I have added some other features, like monitoring your Raspberry Pi performance using a cloud SaaS from BMC named BMC Truesight Pulse, and also how to set Alarms and Actions to increase your system reliability using this platform.

Step 1: Description of Used Applications and Services

As you might noticed looking at the front picture of this Instructables, we are using a lot of applications and services in order to get things working, so here I will post a short description of every application I used to do this project (the descriptions posted here are from the applications and services providers websites):

IBM Bluemix

Bluemix™ is the latest cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix is an implementation of IBM's Open Cloud Architecture based on Cloud Foundry, an open source Platform as a Service (PaaS). Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them.

And then.... Why would we need it???

As you read on the description with Bluemix you create and deploy cloud applications. For this project we will use Node-Red. Node-red will be like the brain of our project. It will be used to receive Alexa commands, receive our sensor values, and send the command back to Alexa so we get a response based on those values. Also the main advantage of having Node-red on Bluemix is that in order to comunicate with Alexa you will need to send HTTPS requests and since Bluemix is a certified organization you won't have issues with this.


Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.

Browser-based flow editing:
Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click. JavaScript functions can be created within the editor using a rich text editor. A built-in library allows you to save useful functions, templates or flows for re-use.

Cayenne MyDevices

Cayenne is the world’s first drag and drop IoT project builder that empowers developers, designers and engineers to quickly prototype and share their connected device projects. Cayenne was designed to help users create Internet of Things prototypes and then bring them to production.
There are several major components in the platform:

Cayenne Mobile Apps – Remotely monitor and control your IoT projects from the Android or iOS Apps.

Cayenne Online Dashboard – Use customizable widgets to visualize data, set up rules, schedule events and more.

BMC Truesight Pulse

BMC’s TrueSight Pulse solution is the newest addition to BMC’s Digital Enterprise Management set of solutions designed to make digital business fast and seamless, and optimize every environment from mainframe to mobile to cloud. The TrueSight Pulse solution supports this vision by providing second-by-second monitoring for IT Ops and DevOps teams that need to quickly centralize events, alerts, and notifications from today’s modern platforms, which includes deep visibility for Amazon Web Services.


This is a client for Amazon's Alexa service. It is intended and tested to run on a wide range of platforms, such as Raspberry Pi, Orange Pi, CHIP and ordinary Linux desktops.

Step 2: Requirements and Materials:

To make this project you will need to have the following hardware:

  • A Raspberry Pi with a fresh image installed( Any Pi model should work, but I recommend a version above 2 for best perfomance)
  • Sound Ouput (I used my Tv with a HDMI cable, but you can use any kind of speakers)

After you gather all the hardware, you will need to have a registered account in the following service providers:

Step 3: Don't Look at the Big Picture!!!

As I told you before, this Instructable uses a lot of applications and integrations, and most of them could almost be considered a Instructables by themselves(most of them really are!!). So in order for you to don't get too lost I'm segmenting this into smaller steps, and I'm also posting the links to the different tutorials you must follow:

  • Alexa running in your Raspberry PI. I'm not creating a step for this point, since you can find all the information in this TUTORIAL.

  • Wire DHT11 to ESP-12e Dev Board.

  • Connect the Esp-12e Dev Board to IBM Bluemix.

  • Publishing DHT values and deploying Node-Red application on IBM BlueMix.
  • Set up your Alexa Skill.

  • Send values to Cayenne App.

  • Install TrueSight Pulse in your Raspberry and set up the Dashboards (Advanced).

Step 4: Wire DHT11 to ESP-12e

This is the most easiest step in the whole instructable.

Just wire your DHT11 as shown in the attached images, depending if you have an assembled DHT11 module or just the DHT11 itself.

Step 5: Connect Your Esp-12e Developer Board to IBM Bluemix.

Here is where things start to get a little complited. However I found a source of information that can help you a lot throughout this process. You can find all the information regarding this Step HERE, but I'll try to summarize everything in it.

After you make an account, log in. First time you log in, a window asking you to set up environment should be displayed.

Environment Setup

Here choose a name for your organization and a region. It is recommended that you choose US South because some features are only available within that region.

Now after you set up your environment go to the Catalog, and choose Internet of Things Platform.

Iot Plat

Choose free plan, and Click create.

If you go back to main dashboard, you should see Internet of Things Platform under services.
We want to connect our device to Bluemix. In order to do that, launch Internet of Things Platform dashboard.

Iot Plat2

On the left side of the dashboard, click devices.

Within devices click Add Device

Iot Plat3

You can choose to add a new device or to create a device type. Since we don’t have any device types created yet, we have to create one. We will call this type ESP8266. We have to do this only once for each device type. After we create this type, we have to use it whenever we want to add a new ESP8266 device. Click create device type and name it ESP8266. Description is optional. Click next. There are some other fields (serial number, manufacturer, model…) that you can select but they are not mandatory. Continue with this process until you can click the create button. We still haven’t added any particular devices, we have just created a template, a device type, that we have to choose each time we want to add a new device. Now choose ESP8266 device type and click next. We need to add a device ID. Device ID should be the MAC address of your ESP8266 module. To obtain address, you can use this program:

#include <ESP8266WiFi.h>

void setup() {
  String clientMac = "";
  unsigned char mac[6];
  clientMac += macToStr(mac);

String macToStr(const uint8_t* mac){
 String result;
   for (int i = 0; i < 6; ++i) {
    result += String(mac[i], 16);
   if (i < 5)
    result += ':';
 return result;

void loop() {


After you get the MAC address of your ESP8266, complete the Add Device form with all the required fields.

Iot Plat

When you get into this window, copy all the data in this table. You will need to used it in your code!!!

Iot Plat

You can register up to 20 devices for free plan of the Internet of Things Platform.

Iot Plat

Step 6: Deploying Node-Red Application on IBM BlueMix.

Before we upload our ESP-12E with the code that will allow us to publish our sensor values, we will need to deploy the application Node-Red into our Bluemix environment.

To do this please follow this tutorial from IBM -

After you finished the tutorial above you should have something like this in your IBM Bluemix Dashboard:

Iot Plat

Now press the highlighted hyperlink to open your Node-Red application.

Before you import my Node-Red flows, you will need to install the cayenne node in order to publish via MQTT the sensor values to Cayenne dashboards. You can find all the info HERE.

Import my flow!

[{"id":"fbaf05bd.5c0948","type":"http in","z":"45954f22.d8f4f","name":"Echo request","url":"/red","method":"post","swaggerDoc":"","x":105,"y":168,"wires":[["bfa35eb.eb09ba"]]},{"id":"bfa35eb.eb09ba","type":"switch","z":"45954f22.d8f4f","name":"Sort Request Type","property":"payload.request.type","propertyType":"msg","rules":[{"t":"eq","v":"LaunchRequest","vt":"str"},{"t":"eq","v":"IntentRequest","vt":"str"},{"t":"eq","v":"SessionEndedRequest","vt":"str"},{"t":"else"}],"checkall":"true","outputs":4,"x":165,"y":219,"wires":[["912aa61f.b43b68"],["59df4911.173ba8"],["2f19c843.2b1178"],["912aa61f.b43b68"]]},{"id":"dc18a76d.6b09b8","type":"template","z":"45954f22.d8f4f","name":"Format response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n  \"version\": \"1.0\",\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": \"{{payload}}\"\n    },\n    \"shouldEndSession\": true\n  }\n}","x":928.111083984375,"y":227,"wires":[["68697a7d.28d264"]]},{"id":"68697a7d.28d264","type":"json","z":"45954f22.d8f4f","name":"","x":1100.111083984375,"y":227,"wires":[["baf0c9e5.7eeff8"]]},{"id":"baf0c9e5.7eeff8","type":"http response","z":"45954f22.d8f4f","name":"","x":1253.777759552002,"y":227.00000381469727,"wires":[]},{"id":"912aa61f.b43b68","type":"template","z":"45954f22.d8f4f","name":"Launch statement","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"welcome to HomeAssistant! To begin, use one of the provided phrases within 3 seconds","x":688,"y":183,"wires":[["dc18a76d.6b09b8"]]},{"id":"ea322877.d9b428","type":"ibmiot in","z":"45954f22.d8f4f","authentication":"apiKey","apiKey":"19a57710.b0ea99","inputType":"evt","deviceId":"5CCF7FD53E8F","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT","service":"registered","allDevices":"","allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":"","qos":0,"x":99.36270141601562,"y":504.22723388671875,"wires":[["ba0e393.172a3c8","dfc11e8.7be77e"]]},{"id":"59df4911.173ba8","type":"switch","z":"45954f22.d8f4f","name":"Sort by Intent","property":"","propertyType":"msg","rules":[{"t":"eq","v":"Goodbye_Intent","vt":"str"},{"t":"eq","v":"Input_Intent","vt":"str"},{"t":"else"}],"checkall":"true","outputs":3,"x":193.765625,"y":277.75,"wires":[["2f19c843.2b1178"],["bc3d9dee.28ba2"],["912aa61f.b43b68"]]},{"id":"bc3d9dee.28ba2","type":"switch","z":"45954f22.d8f4f","name":"Sort by Input Intent","property":"payload.request.intent.slots.mcu_inputs.value","propertyType":"msg","rules":[{"t":"eq","v":"sensor value","vt":"str"}],"checkall":"true","outputs":1,"x":250.3280029296875,"y":325.6611022949219,"wires":[["e982422d.f4bed"]]},{"id":"2f19c843.2b1178","type":"template","z":"45954f22.d8f4f","name":"Goodbye statement","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Goodbye! See you next time","x":691.765625,"y":224.75,"wires":[["dc18a76d.6b09b8"]]},{"id":"b1f4fa5c.3aa8c8","type":"comment","z":"45954f22.d8f4f","name":"Sent to Alexa","info":"","x":694.38671875,"y":132.76953125,"wires":[]},{"id":"e982422d.f4bed","type":"function","z":"45954f22.d8f4f","name":"Get Sensor Values","func":"msg.payload = \"The temperature of the room is \" + global.get(\"temp\") + \"º Celsius\" + \" and the relative humidity is \" + global.get(\"hum\")+\"%\";\nnode.warn(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":692.0989990234375,"y":264.75,"wires":[["dc18a76d.6b09b8"]]},{"id":"73bc0188.e99d","type":"comment","z":"45954f22.d8f4f","name":"Sensor Values Stored in Global Variables","info":"","x":633.765625,"y":414.75,"wires":[]},{"id":"ba0e393.172a3c8","type":"switch","z":"45954f22.d8f4f","name":"","property":"payload.d.temp","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","outputs":1,"x":278.38671875,"y":462.73828125,"wires":[["4417d07d.f0721"]]},{"id":"4417d07d.f0721","type":"function","z":"45954f22.d8f4f","name":"Retain Temperature Value","func":"var input =msg.payload.d.temp;\nglobal.set(\"temp\",input);\nnode.warn(global.get(\"temp\"));\nmsg.payload = input;\nreturn msg;","outputs":"1","noerr":0,"x":655.4946899414062,"y":452.1388854980469,"wires":[["4ecb171d.8941b8","3da68fd4.aa764"]]},{"id":"dfc11e8.7be77e","type":"switch","z":"45954f22.d8f4f","name":"","property":"payload.d.hum","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","outputs":1,"x":277.765625,"y":503.75,"wires":[["cbb378a7.14eea8"]]},{"id":"cbb378a7.14eea8","type":"function","z":"45954f22.d8f4f","name":"Retain Humdity Values","func":"var input =msg.payload.d.hum;\nglobal.set(\"hum\",input);\nnode.warn(global.get(\"hum\"));\nmsg.payload = input;\nreturn msg;","outputs":"1","noerr":0,"x":645.765625,"y":495.75,"wires":[["f58a38e8.81d548","7e4cdd53.2ea1c4"]]},{"id":"4ecb171d.8941b8","type":"debug","z":"45954f22.d8f4f","name":"","active":false,"console":"false","complete":"false","x":1043.3828125,"y":496.0234375,"wires":[]},{"id":"f58a38e8.81d548","type":"debug","z":"45954f22.d8f4f","name":"","active":false,"console":"false","complete":"false","x":1032.765625,"y":552.75,"wires":[]},{"id":"3da68fd4.aa764","type":"cayenne sensor","z":"45954f22.d8f4f","client":"e9139986.f43cc8","qos":"0","name":"","datatype":"","dataunit":"","channel":"1","datatypeEx":"temp","dataunitEx":"c","x":1050.3828125,"y":453.30859375,"wires":[]},{"id":"7e4cdd53.2ea1c4","type":"cayenne sensor","z":"45954f22.d8f4f","client":"e9139986.f43cc8","qos":"0","name":"","datatype":"","dataunit":"","channel":"2","datatypeEx":"hvac_hum","dataunitEx":"p","x":1053.765625,"y":594.75,"wires":[]},{"id":"31e1e2d5.258b4e","type":"comment","z":"45954f22.d8f4f","name":"Send Sensor Values to Cayenne","info":"","x":1045.765625,"y":413.75,"wires":[]},{"id":"19a57710.b0ea99","type":"ibmiot","z":"","name":"TEST","keepalive":"60","cleansession":true,"appId":"","shared":false},{"id":"e9139986.f43cc8","type":"cayenne-client","z":"","broker":"e4b2fc8d.0bab2","username":"9386d3d0-b6ed-11e6-bb76-1157597ded22","clientid":"58a93f90-ceb8-11e6-97cc-8758d0339dd8","name":""},{"id":"e4b2fc8d.0bab2","type":"mqtt-broker","z":"","broker":"","port":"1883","clientid":"58a93f90-ceb8-11e6-97cc-8758d0339dd8","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

You should end with something like this picture:

Iot Plat

To get this flow working there are somethings you will need to edit by yourself to match your device.

  1. Edit the IBM IoT node. You will need to edit the API Key and Device ID to match the ones you defined in the STEP5.
  2. Cayenne Nodes. This will be explained in the near end of this instructables.

Its time to upload our code to our ESP-12E so we start publishing our sensor values!

Step 7: Uploading and Editing Our Code to ESP-12E

So here is the code you will need to upload to your ESP-12E dev board.

#include "DHT.h"
#include <ESP8266WiFi.h>
#include <PubSubClient.h> // <a href=""> <a href="</a"></a>>

//-------- Customise these values -----------
const char* ssid = "*******";<br>const char* password = "********";

#define ORG "*******"
#define DEVICE_TYPE "*******"
#define DEVICE_ID "********"
#define TOKEN "*********"

<p>#define DHTPIN 4     // what digital pin we're connected to<br>#define DHTTYPE DHT11   // DHT 11 or 22 depeding wich sensor you have</p>
//-------- Customise the above values --------

char server[] = ORG "";
char topic[] = "iot-2/evt/status/fmt/json";
char authMethod[] = "use-token-auth";
char token[] = TOKEN;
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;

WiFiClient wifiClient;
PubSubClient client(server, 1883, NULL, wifiClient);

void setup() {
  Serial.println("DHTxx test!");

  Serial.print("Connecting to "); Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {

  Serial.print("WiFi connected, IP address: "); Serial.println(WiFi.localIP());

int counter = 0;
void loop() {
  // Wait a few seconds between measurements.

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");

  Serial.print("Humidity: ");
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(" *C ");
   if (!client.connected()) {
 Serial.print("Reconnecting client to ");
 while (!client.connect(clientId, authMethod, token)) {

String payload = "{\"d\":{\"Name\":\"ESP8266\"";
 payload += ",\"temp\":";
 payload += t;
 payload += "}}";
 Serial.print("Sending payload: ");
 if (client.publish(topic, (char*) payload.c_str())) {
 Serial.println("Publish ok");
 } else {
 Serial.println("Publish failed");
 payload = "{\"d\":{\"Name\":\"ESP8266\"";<br> payload += ",\"hum\":";
 payload += h;
 payload += "}}";
 Serial.print("Sending payload: ");
 if (client.publish(topic, (char*) payload.c_str())) {
 Serial.println("Publish ok");
 } else {
 Serial.println("Publish failed");


To get this working first of all you will need to install the library PubSubClient.h. You can find all the details HERE.

Next within the comments with Customise these values, are placed the values that you will need to edit.

Connect your Dev Board to your PC or MAC and upload the code with the modified values.

After you uploaded the code, open the Serial Monitor from Arduino IDE and change the baudrate to 115200.

You should see something similar to this but with your values:

Iot Plat

(Don't know why the first Publish of humidity sometimes fails....)

Now if you open IBM BlueMix Watson console you should see the values from the DHT sensor being published, and the same thing for Node-Red.

Iot Plat

Iot Plat

Step 8: Setup Alexa Skill

Login to your Amazon Developer account:

- Open the Alexa Tab and open Alexa Skill Kit.

- Add a New Skill

Now give it a name that you want, and an Invocation Name.

In the Interaction Model tab copy the following intent Schema:

  "intents": [
      "intent": "Input_Intent",
      "slots": [
          "name": "mcu_inputs",
          "type": "RSP_IN"

Press Add a Slot Type. In the Enter Type field write RSP_IN. In the code field enter sensor value.

Within Sample Utterances copy and past:

Input_Intent tell me the {mcu_inputs}
Input_Intent get {mcu_inputs}

You should have something like this:

In the Configuration tab pick your geographical region and enter your service end-point.

Be careful here because the end point needs to start with https.

Last thing you will need to configure before test is the SSL Certificate.

Choose the option that says: My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority.

TEST it!

Type get sensor value in the Utterances field and you should get a response from alexa!

Step 9: Send Values to MyDevices Cayenne Dashboard.

After you register and open your dashboard press Add New - Device / Widget.

Press the Bring Your Own Thing Button.

Now copy the information that you get to your Cayenne Nodes in your Node-Red application.

In these nodes also set the Temperature Node data Type to Temperature and the Data Unit to Celsius. In the Humidity one set the Data Type to HVAC.Humidity and Data Unit to %.

If you look now to your Cayenne Dashboard you will see your values being published!

Be creative and use this integration to control devices based on your sensor readings. You can also add different sensors and connect them to almost every actuator too!

Step 10: BMC TrueSight Pulse (Advanced But Not Hard)

In this step I'm also demonstrating how you can integrate your Node-Red application into a cloud Monitoring service named BMC Truesight Pulse.

First after you register, you will need to add a device to monitoring.

In this case I'll be using the RaspberryPI where I have the AlexaPI installed. You can monitor for free up to 5 windows or linux machines, so feel free to used it!

Go to Installation withing Settings and copy the code to your Raspberry and press enter.

You should now have your Dashboard showing your Raspberry PI values.

You can also tweek this to send notifications and trigger alerts based on criteria you define, so explore this since this is an incredible free monitoring app!

To add now a graph of your temperature and humidity you will need to add 2 metrics. To do this go to Settings-Metrics-Add Metric.

Now copy the bellow flow to your Node-Red application and modify the function node to set your username and API key for your BMC Truesight Pulse Dashboard.

[{"id":"3b4be360.61595c","type":"function","z":"760e79ba.3095c8","name":"Write command function ","func":"//Dispacher for Pulse\nvar msg1 = { payload:\"curl https:\\/\\/\\/v1\\/measurements \\\\-u <EMAIL>:<APIKEY> \\\\-X POST \\\\-H \\\"Content-Type: application\\/json\\\" \\\\-d '{\\\"source\\\": \\\"raspberrypi\\\",\\\"metric\\\": \\\"PI_TEMP\\\",\\\"measure\\\": \"+global.get(\"temp\")+\"}'\" };\nconsole.log(msg1);\nreturn msg1;\n","outputs":1,"noerr":0,"x":447.765625,"y":696,"wires":[["9339355a.4b77c8","c2700316.b7184"]]},{"id":"5c5f75ec.6312ec","type":"debug","z":"760e79ba.3095c8","name":"","active":true,"console":"false","complete":"false","x":922.765625,"y":690,"wires":[]},{"id":"e545118e.24a0a","type":"debug","z":"760e79ba.3095c8","name":"","active":true,"console":"false","complete":"false","x":925.765625,"y":727,"wires":[]},{"id":"4bf1848f.072ddc","type":"debug","z":"760e79ba.3095c8","name":"","active":true,"console":"false","complete":"false","x":926.765625,"y":762,"wires":[]},{"id":"9339355a.4b77c8","type":"debug","z":"760e79ba.3095c8","name":"","active":true,"console":"false","complete":"false","x":676.765625,"y":754,"wires":[]},{"id":"c2700316.b7184","type":"exec","z":"760e79ba.3095c8","command":"","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":678.765625,"y":695.5,"wires":[["5c5f75ec.6312ec"],["e545118e.24a0a"],["4bf1848f.072ddc"]]},{"id":"4c0736da.bdbe68","type":"inject","z":"760e79ba.3095c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":219.765625,"y":696,"wires":[["3b4be360.61595c"]]},{"id":"318199d1.021f56","type":"comment","z":"760e79ba.3095c8","name":"Send Sensor Values to BMC Truesight Pulse (Advanced)","info":"","x":623.765625,"y":644,"wires":[]}]
IoT Builders Contest

Participated in the
IoT Builders Contest

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020