IFTTT Maker Channel: Tweet temperature and humidity


#1

This sample project is about interacting with a third party service like the IFTTT Maker Channel. This channel allows executing multiple actions like sending tweets, posting to Facebook, doing push notifications, sending emails or SMS, and many many other actions you must check. As an illustrative example, this project will tweet the temperature and humidity periodically. Also it will allow reading the humidity and temperature remotely, changing the tweet interval, and sending test tweets.

Hardware

For this example project we will use a NodeMCU board, that is based in the ESP8266 chip, along with a DHT11 sensor. The NodeMCU board will be connected to the DHT11 sensor in the digital pin D1. You can use however any other board that you want as the code will be practically the same.

Software

We will use the Arduino IDE for programming the NodeMCU and the thinger.io libraries for connecting to the platform. Please, take a look to this post if you need help starting with the ESP8266 and the Arduino Environment.

Picture

The hardware is really simple. Just a NodeMCU connected to the DHT11 sensor.

Before Programing

For this project we need to have an account in the IFTTT site. Please register now if you don’t have an account. After we are registered we are going to create a new recipe. A recipe let us configure a trigger event to start doing some action. In our case we are going to send an event to the Maker Channel in order to send a tweet. So the first step now is to create a recipe.

The first thing to do is select what is going to trigger the recipe. Click on this and search for the Maker Channel. Once you find it, client on its icon. You may be prompted to connect to this channel in this step.

Now it is time to select the trigger type for the Maker Channel. This channel only has one trigger type, so click on Receive a web request.

The trigger requires some configuration. In this case we must fill a event name that will represent our action. For example, we can name it as temperature. You can choose whatever you want, but remember this name for its configuration in the thinger.io platform. Then click on Create Trigger.

At this stage we have configured yet the channel trigger, basically consisting on defining a event name. Now you must click on the word that to start configuring the action to be executed if we submit this event.

Now you can select any action you want, like sending an email, a push notification, and so on. In this example we are going to send tweets, so search for twitter and click on its icon. You may be prompted to connect to this channel. You need to grant rights to the IFTTT app so it can send tweets with your account.

The twitter channel has some different actions like you can see in the following picture. We are going to click on the Post a Tweet box.

We are almost done… Now we can see how the tweet looks like. The maker channel allows sending up to three different values named as Value1, Value2, and Value3. Those parameters are also called ingredients of the recipe. We are going to use this parameters for sending the temperature and humidity of our DHT11. So, type something like in the following picture, and when you are done click on Create Action.

Now we can see a summary of our recipe, that basically consists on sending a tweet when the temperature event is triggered. So, click on the Create Action button to complete the IFTTT part.

Now we need to link the thinger.io platform with the IFTTT event we have created. This is an easy step. Just go the the Endpoints section in your console. Click on Add Endpoint and configure the Endpoint similar to the following picture. Notice that our endpoint id is temperature_tweet, that is necessary for the thing code. Also we have introduced here the event name we set in IFTTT Maker Channel, which was temperature, and also we need to set our Maker Channel Secret Key, that should be available in your maker channel. After you are done click on the Add Endpoint button.

So we are done configuring the platform. We just basically created a recipe in the IFTTT page to send tweets based on our calls to the temperature event. And also we have configured an endpoint called temperature_tweet in the thinger.io platform so the device can call it easily. So now we can start programming our device for reading the DHT11 sensor and calling the endpoint we have created.

Sketch Code

The sketch code is relatively simple. We have started using the ESP8266 example from the thinger.io libraries and added the headers and configuration for the DHT11 sensor. Then we have defined some thing resources, like dht11 that allows reading the current temperature and humidity, the tweet_interval, that allows configuring remotely the tweet interval, and finally, the tweet_test resource, that forces a tweet post.

There is also some code in the loop that basically checks if it is necessary to send a tweet according to the current time and our latest tweet time. The interesting part on this code is the call_temperature_endpoint function. This function call the endpoint we have configured in the thinger.io platform, and fill also the parameters required for our IFTTT recipe. If you remember, we were using value1 and value2 on our tweet content (the ingredients of our recipe). These parameters are filled in the code with the temperature and humidity that we are reading from the DHT11. These values are stored in a pson structure, that basically is like a json document but for microcontrollers. This structure is converted in the server to a json format that the IFTTT platform can understand. So our device efficiently call our thinger.io endpoint with the recipe parameters, and the platform automatically trigger the IFTTT event that will post the tweet. Notice that although those parameters starts with a capital letter in our recipe, they should be all in lowercase, as in the example.

So you can update the following sketch with your username, your device id, your device credential, and also the Wifi SSID/Password to start running this sample project.

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include "DHT.h"

#define USERNAME "your_user_id"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"

#define SSID "your_wifi_ssid"
#define SSID_PASSWORD "your_wifi_password"

// dht config
#define DHTPIN D1
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

unsigned long previousMillis = 0;      // to know when to post the temperature
unsigned int minutes_interval = 60;              // variable in minutes for posting the temperature

void call_temperature_endpoint(){
  digitalWrite(BUILTIN_LED, LOW);
  pson tweet_content;
  tweet_content["value1"] = dht.readTemperature();
  tweet_content["value2"] = dht.readHumidity();
  thing.call_endpoint("temperature_tweet", tweet_content);
  digitalWrite(BUILTIN_LED, HIGH);
}

void setup() {
  dht.begin();
  pinMode(BUILTIN_LED, OUTPUT);

  // turn off led
  digitalWrite(BUILTIN_LED, HIGH);
  
  thing.add_wifi(SSID, SSID_PASSWORD);

  // resource for reading sensor temperature from API
  thing["dht11"] >> [](pson& out){
    out["humidity"] = dht.readHumidity();
    out["celsius"] = dht.readTemperature();
    out["fahrenheit"] = dht.readTemperature(true);
  };

  // resource that will allow changing the tweet interval
  thing["tweet_interval"] << [](pson& in){
    if(in.is_empty()) in = minutes_interval;
    else minutes_interval = (unsigned int) in;
  };

  // this resource will allow sending the tweet as requested
  thing["tweet_test"] = [](){
    call_temperature_endpoint();
  };
}

void loop() {
  thing.handle();
  unsigned long currentMillis = millis();
  if(minutes_interval>0 && currentMillis - previousMillis >= minutes_interval * 60000) {
    previousMillis = currentMillis;   
    call_temperature_endpoint();
  }
}

Web Control

Although this sketch will start running and posting tweets every hour (by default), we can also access to the device api dashboard to interact with our defined resources in the code. You can access to the current temperature and humidity, you can see and change the current tweet interval period, and you can test your implementation by directly forcing a tweet post. You should see something similar to the following picture in your device dashboard.

Result

If we have done all the steps fine, we should see some tweets appearing in our timeline every hour (or what you have configured in the tweet_interval resource). You can force some testing tweets by manually running the tweet_test resource. In our case, our tweets are as in the following picture:


Сooperation with IFTTT?
Сooperation with IFTTT?
#2

It is possible to communicate the other way around? For example, trigger a relay in the esp8266 based on a location channel on Ifttt.


#3

This feature will be available late this week! I am working right now on this =)

I’ll keep you updated when this feature is available.


#4

thanks, I’ll be waiting!


#5

I´ll post an example about controlling a led from an Android Smartwatch, but is almost the same for de Android Location channel :wink:


#6

Nice! thats the next thing ill do then (with a pebble time).


Make your IoT things react to hundred of IFTTT Events
#7

Hi @psukez, I have posted a video example controlling a led from the IFTTT Do button in the smartwatch. Probably today I have some time to publish the how-to. But you can use any IFTTT trigger to enable a led, a relay, a servo, or any other function of your microcontroller =)


#8

@alvarolb really cool! I`ll be waiting for the how-to


#9

Hi @psukez ! Just posted a example in this how-to:

Make your IoT things react to hundred of IFTTT Events

Let me know if you make something cool! And share it with the community =)


#10

Hi All, I configured everything according to tutorial except I m using arduino ethernet shield instead of esp8266. querries run. I can read data from arduino but. maker channel event can be triggered. Secret key is correct. what can be the problem.

thanks…


#11

one more question,
I want to control particuler arduino pin with posting a twit. foor example I will post “home turn on light” then arduino’s pin state become HIGH, if I post “home turn off lights” pin state is LOW.

is that possible. if so can you share tutorial that…

thanks…


#12

Hi! It should work also with the Arduino Ethernet. Just make sure the maker event name and secret key are configured fine in the endpoint. Also check the endpoint name you are calling in you sketch (that should be the identifier used in the thinger platform, not in the IFTTT). It may be also useful to check the IFTTT channel to see if there is any debug information about your calls.


#13

This is possible by using the following twitter trigger:

And using the IFTTT Maker channel as trigger, similar to described in this post:

With the twitter trigger I have mentioned, you can react to mentions you get, and get the text of the tweet. So, suppose you have a twitter account for your home that is @home. You could write “@home, turn lights on”. So every time you got a mention, your device resource is called with the text, and the user that have mentioned you. From this point, it is quite easy to check the user mentioned you (to be sure the user have the right credential to execute the action), and evaluate the text to detect what is the request.

I have tested this integration with IFTTT, configuring the maker event as the following:

And defining a resource in the device like this:

thing["mention"] << [](pson& in){
    const char* user = in["user"]; 
    const char* text = in["text"];
    Serial.println(user);
    Serial.println(text);
};

Which results in an output similar to the following result every time you got a mention:

alvarolb84
@thinger_io reacting to a twitter mention!

However, It seems that twitter does not allow you to write tweets with the same status, so if you turn on and off quite frequently from twitter, you must add a trailing number, or a different hashtag to pass the twitter filter.


#14

thats valuable information. I believe I can manage device side according to my desires :slightly_smiling:


#15

Hi @alvarolb,
I just got my first NodeMCU 0.9v (I think) and I’m a n00b about how it functions and how it works.
I’ve got it working with tinger.io, connected via wifi and such.
But, I’d like to make a simple/smart doorbell.
That would work like this:

  1. someone rangs
  2. NodeMCU sends notification via Pushbullet or IFTTT or Pushover or any other service
  3. Getting notified on my Android device

And later on when I get that working, I would add this features:
4. Ringing sound through my Raspberry Pi 1 or 0
5. Capturing the screen from my camera
6. Sending that screenshot to my Android device via IFTTT…

This worked well with Raspberry Pi 1, without problem, tho I’d like to do the first part with NodeMCU if that’s possible.

So, where I’m stuck is:

  1. how to write a code that NodeMCU sends notification to IFTTT when the button is pressed

Thanks! :slight_smile:


#16

dear sir i have a doubt what shoud be the device credential in the code can any one please help me what device credential mean
i am using a maker channel i want to trigger events from node mcu
shahsoumil519@gmail.com
please reply as soon as possible


#17

Hi @Soumil_Shah. The device credential is like the password you set when you create a device in the console.


#18

Everything done same as said but , there is no tweeting of temperature? Is the IFTTT Maker key is Applet ID? plz help me


#19

@alvarolb Everything done same as said but , there is no tweeting of temperature?. In the dashboard it is showing but in the twitter it is not tweeting ???


#20

Hi @Ravi,

I have checked the integration and it is working fine.

Please, share your code (except credentials), and please share also your maker channel configuration. Please, review the endpoint names you are using, review the maker channel credentials, and verify that you did not include trailing spaces or something similar…