fbpx

Automation using Google Assistant

Introduction:

  • Google Assistant AI “Ready to Help wherever you are” just one tap in your smartphone.
  • Google Assistant can support Voice input and test input.
  • Google assistant help’s to get the information to user’s based on request from user’s,
  • Apart from just passing information from internet. Google assistant can communicate with hardware like esp8266 or anyother IoT device and help you to control and monitor the device in your home or office.

Major Objective is to control and monitor the electrical device using google assistant.

Requirements:

Software:

  • Google Assistant Device (Smart Phone) 
  • IFTTT (If This Then That) 
  • Adafruit.
  • Arduino.

Hardware:

  • ESP8266-12E / ESP-32.
  • Relay Board.
  • Electrical Load.    

Block Diagram:     

Adafruit IO.

Adafruit IO is a IoT platform build using MQTT  protocol ,is the easiest way to get your projects onto internet of things.

  • create a account in adafruit and click on IO option to direct dashboard
  • click on action to create a new feed
  • enter the feed name (be-careful in feed name which is used to establish connection between IFTTT & adafruit)

 Its time to create IFTTT application to access the adafruit

IFTTT:

IFTTT is the free way to get all your apps and devices talking to each otherIFTTT app brings over 600 app service together including devices like Google Home, Amazon Alexa, Nest, Philips Hue, and your iPhone, which help you to Control everything around you with your voice and Amazon Alexa or Google Assistant Get Started with IFTTT

  • create  IFTTT account.
  • in search bar check for google assistant and select it
  • select connect option to enable the google assistant service in IFTTT
  • Now create the applete to control the device from IFTTT
  • Search for esp8266 applete 
  • enable the esp8266 led control applete by clicking the connect
  • To enable the esp8266 it required adafruit authorize to enable the connection between google assistant and adafruit feed
  • config the google assistant command in IFTTT to control the esp8266
  • command to turn on the device : sat on led
  • command to turn off the device : sat off led
  • Successfully configed the IFTTT 
  • Command from google assistant
  • google assistant commands are reflected in adafruit feed.

Block Diagram:       

Circuit Diagram:

program:

#include <ESP8266WiFi.h> 
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WIFI_SSID "<Your Wifi SSID>" 
#define WIFI_PASS "<Your WiFi Password>" 
#define MQTT_SERV "io.adafruit.com" 
#define MQTT_PORT 1883 
#define MQTT_NAME "<Your Adafruit IO Username>" 
#define MQTT_PASS "<Your Adafruit IO Key>"
WiFiClient client; 
Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS); 
Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, MQTT_NAME "/f/onoff");
void setup() 
{ 
Serial.begin(9600); //Connect to WiFi 
Serial.print("\n\nConnecting Wifi... "); 
WiFi.begin(WIFI_SSID, WIFI_PASS); 
while (WiFi.status() != WL_CONNECTED) 
{ 
delay(500); 
} 
Serial.println("OK!"); //Subscribe to the onoff topic 
mqtt.subscribe(&onoff);
pinMode(LED_BUILTIN, OUTPUT); 
}
void loop() 
{ 
  //Connect
  //Reconnect to MQTT 
  MQTT_connect(); 
  //Read from our subscription queue until we run out, or
  //wait up to 5 seconds for subscription to update  
  Adafruit_MQTT_Subscribe * subscription; 
  while ((subscription = mqtt.readSubscription(5000))) 
  { 
    //If we're in here, a subscription updated... 
   if (subscription == &onoff)
   { 
    //Print the new value to the serial monitor
    Serial.print("onoff: "); 
    Serial.println((char*) onoff.lastread);
    //If the new value is "ON", turn the light on.
    //Otherwise, turn it off.
    if (!strcmp((char*) onoff.lastread, "ON"))
    {
     //active low logic 
     digitalWrite(LED_BUILTIN, LOW); 
    }
    else
    {
     digitalWrite(LED_BUILTIN, HIGH);
    }
   } 
}

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!");
}

Leave a Reply

Your email address will not be published. Required fields are marked *