13. Led/Relay Control By Google Assistance

Overview of IFTTT

If This Then That, also known as IFTTT. it is a free web-based service to create chains of simple conditional statements, called applets.
An applet is triggered  by  changes  that  occur  within  other  web  services  such as Gmail, Facebook, Telegram, Instagram, or Pinterest.
For example, an applet may send an e-mail message if the user tweets using a hashtag, or copy a photo on Facebook to a user's archive if someone tags a user in a photo.
In addition to the web-based application, the service runs on iOS and Android. In February 2015, IFTTT renamed its original application to IF, and released a new suite of apps called Do, which lets users create shortcut applications and actions. As of 2015, IFTTT users created about 20 million recipes each day. All of the functionalities of the Do suite of apps have since been integrated into a redesigned IFTTT app.
IFTTT is the free way to do more with hundreds of the apps and devices you love, including Twitter, Dropbox, Evernote, Nest, Fitbit, Amazon Alexa, and Google Assistant.
On IFTTT,  we call those services. To see all of  the services on IFTTT, check out    our services list.
We bring services together into Applets. Applets are specific things that can happen when you connect services  things your apps can't do on their own.
For example, you could use an Applet to sync Amazon Alexa to-dos with your Google Calendar. Or one that lets you create events in your iPhone Calendar, via Google Assistant.

Overview of Adafruit io:

Adafruit.io is a cloud service - that just means we run it for you and you don't have to manage it. You can connect to it over the Internet. It's meant primarily for storing and then retrieving data but it can do a lot more than just that!
What can Adafruit IO do for me?
  • Display your data in real-time, online
  • Make your project internet-connected: Control motors, read sensor data, and more!
  • Connect projects to web services like Twitter, RSS feeds, weather services, etc.
  • Connect your project to other internet-enabled devices.
  • The best part? All of the above is do-able for free with Adafruit IO
Adafruit.io can handle and visualize multiple feeds of data. Want to display data from a temperature-humidity sensor alongside data from an air quality sensor and add a button to turn on the air-conditioner in your room?
No problem! Dashboards are a feature integrated into Adafruit IO which allow you to chart, graph, gauge, log, and display your data. You can view your dashboards from anywhere in the world.

Triggers
Use triggers in Adafruit IO to control and react to your data. Configure triggers to email you when your system goes offline, react to a temperature sensor getting too hot, and publish a message to a new feed.

Integration with IFTTT and Zapier
Want to make your project react to an email, display trending tweets, or turn on the front  lights  when  your   pizza   is   on   the   way?   We   baked   in   integrations   with IFTTT and Zapier to connect your project's sensors to  hundreds  of  web  services.

Connection of LED

Led have two terminals, first is positive terminal and second is Negative Terminal. The Negative Terminal is connected to the Ground pin of ESP8266 module and Positive Terminal is connected to the 220ohm Resistance and the other side of resistance is connected to the D2 pin of ESP8266 Module.

Circuit Diagram:

Method to Connect NodeMCU to Google Assistant:

Step1: Search Adafruit.io in browser and open it.


Step2: click on Get started for free and create account. After sign up then open a new window as shown in figure.


Step3: Then click on action and create a new dashboard.


Step4: Creating a Dashboard and open it as shown in figure.


Step5: after open the created dashboard click on + icon (appear in right-hand upper side) to create a new block.


Step6: click on Toggle and enter feed name and click on next step as shown in figure.


Step7: Done block setting and click on Create block as shown in figure. Then you see a block in dashboard.


Step8: Now click on key icon and get Authorization key and Username. copy the Active key and username and paste it in the code according to figure and Also change the feed name in the code.


Program:


#include  <ESP8266WiFi.h> 
#include "Adafruit_MQTT.h" 
#include "Adafruit_MQTT_Client.h" #define led     D2
#define WLAN_SSID        "WI-FI CAMPUS"              // Your SSID #define WLAN_PASS        "kuchbhi@123"          // Your password
/************************* Adafruit.io Setup *********************************/ #define  AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                 // use 8883 for SSL
#define AIO_USERNAME    "manish8294"             // Replace it with your username
#define AIO_KEY         "5af681ae9811463d9873cc8f7e747fc3" // Replace with your Project Auth Key
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server. WiFiClient client;

// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing  in  the WiFi client  and  MQTT server and  login details.
Adafruit_MQTT_Client        mqtt(&client, AIO_SERVER, AIO_SERVERPORT,AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe Light1 =  Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME"/feeds/relay1"); // FeedName


void MQTT_connect();
 void setup()
{
Serial.begin(115200); pinMode(led, OUTPUT);
// Connect to WiFi access point. Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(WLAN_SSID); WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) { delay(500);
Serial.print(".");
}
Serial.println(); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP());
// Setup MQTT subscription for onoff feed. mqtt.subscribe(&Light1);

}
void loop()
{
MQTT_connect(); Adafruit_MQTT_Subscribe *subscription;
while  ((subscription  =   mqtt.readSubscription(20000)))   { if (subscription == &Light1) {
Serial.print(F("Got: ")); Serial.println((char *)Light1.lastread);
int Light1_State = atoi((char *)Light1.lastread); digitalWrite(led, Light1_State);
}
}
}
void MQTT_connect()
{
int8_t ret;
// Stop if  already  connected.  if  (mqtt.connected())   { return;
}
Serial.print("Connecting to MQTT... "); uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds..."); mqtt.disconnect();
delay(5000); // wait 5 seconds retries--;
if (retries == 0) {

// basically die and wait for WDT to reset me while (1);

}
}
Serial.println("MQTT Connected!");
}



Methods for Connecting Google Assistance and Adafruit

Step1: Search IFTTT in browser and open it. After open Then create an account.


Step2: After creating an account. Then click on Create more applets. 


Step3: Then open a new window. Now click on +This Icon. First of all, we create Applets for LED high. 


Step4: click the +this icon then opens a new window and search goggle assistance and open it.

Step5: when you open Google, assistance open a new window for choose trigger. Then, you click “say a simple phrase” icon.

Step6: complete all trigger Fields. In this field you enter who want to say goggle for led On or off and what do you want the assistance say in response.  according to below image and click on Create trigger.


Step7: after Creating the trigger new window is open.in this window you click on +that icon and search Adafruit and open it as shown in figure.


Step8: after open the Adafruit. You have chosen action then click on “send data to Adafruit IO” and complete all action fields according to image. In feed name you enter Adafruit feed name (created in Adafruit.io or using above steps) and data is feed according to Led on and Off. For Led On enter 1 and for Led Off enter 0. Here, we create for led High.


Step9: click on create action in above step and then click on finish for finish it.
Then you create Applets from Led On.


Step10: using above step to make applet for LED High. For Making Applet for LED low for same procedure as shown in below images.



Comments

Popular posts from this blog

18. GPS Tracker Using Blynk App

6. Some IoT Platforms

16. Wi-Fi Button