Press ESC to close

Or check our Popular Categories...
I

IOT with Firebase : Home Automation Light Control

3 Min Read
16

Integrating Google Assistant with Internet of Things can make our IOT based devices more smarter. It gives voice to our IOT devices with the power of Artificial Intelligence, Natural language understanding & many more.

IOT with Firebase


Project Demo of IOT with Firebase: 

IOT Overview:

In this tutorial i will give overview of all steps we need to follow for creating IOT based device that can be controlled via Google Assistant.

What’s different from other posts on Internet ?

On Internet you can find many tutorials which shows IOT home automation using google assistant. But most of them uses private vendor Apps & APIs like Adafruit, Blynk, IFTTT.
All stated above have some basic functionality only. Here we can’t customize our chat bot (to be integrated in Google Assistant) according to our requirements. In our project we are using Google Firebase, Dialog Flow & actions on Google. Best thing here is all 3 are Google products, using Dialog Flow we can customize our chat bot according to our needs. Additionally, there is no need to create a android app, we can directly use android device google assistant to control smart device.
Steps below follows the video to help:
If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials

Hardware Setup :

Hardware Required :

1. Firstly, Arduino Node MCU – buy which have 5v pinout only, else relay need external supply
2. Secondly, 5v Relay Module
3. Thirdly, Jumper Wires
4. Fourthly, Breadboard
5. Lastly, LED (for testing purpose)

Circuit Diagram:

Connect Arduino D2 pin to relay input, Arduino 5 VCC & GND to relay VCC & GND respectively.
Do other connections exactly as shown in diagram given below.

Connecting Arduino with Firebase:

For connecting arduino nodemcu with firebase realtime database we need to use Firebase Arduino Library, setting up this library has been done in previous tutorial check out here.

Transcript / Cheat Sheet :

#include <ESP8266WiFi.h;
// Set these to run example.

#include <FirebaseArduino.h>
#define FIREBASE_HOST e-adawd.firebaseio.com
#define FIREBASE_AUTH qULRQbnuzJ3——–LlKtpXic1UQ1FxHvM
#define WIFI_SSID kavin
#define WIFI_PASSWORD 12345612
String status;
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(connecting);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(.);
delay(500);
}
Serial.println();
Serial.print(connected: );
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
// get value
status = Firebase.getString(on);
if(status==1){
digitalWrite(4,HIGH);
Serial.println(LED ON);
}
else {
Serial.println(LED OFF);
digitalWrite(4,LOW);
return;
}
}

Setting Up Dialog Flow/Api.ai agent :

Go to https://dialogflow.com/ and login with same credentials you are using for firebase console.
1. Create a New agent : Type agent name and click create button.
2. Go to Entities Tab : Here need to create 2 custom entities, 1 for lights off and other for light on.

For entity @on :

Entity Name : on
Enter Reference Value : 1
Enter Synonym: TURN ON; POWER ON; SWITCH ON;

For entity @off :

Entity Name : off
Enter Reference Value : 0
Enter Synonym: TURN OFF; POWER OFF; SWITCH OFF;

3. Now we are done with setting up custom entities, Let’s create an Intent – Go to Intent Tab & click create Intent button.
  • Type Intent  Name : Light Control
  • Now Go to training phrases option and type given below phrases.

Tip : More Training Phrases you type, more intelligent you chat bot will be.

OK Google turn off the lights

OK Google turn on the lights

turn on the lights

switch on lights

power on lights

turn on lights

turn off lights

switch off lights

i want to turn off light

i want to power off light
  • Once done with all training phrases, you action and parameters table should look like :
REQUIRED PARAMETER NAME ENTITY VALUE IS LIST
@on
@off
  • Now at bottom you will find Fulfillment option, here choose enable web-hook call for this intent.
  • That’s it we are done with setting up Dialog Flow agent, click on save button and start training your agent, once agent training completed we need to switch to fulfillment tab.

Let’s cover Fulfillment and Firebase tools part in next Post.

If you guy’s facing any issue feel free to comment out, i will try to sort it out as soon as possible.

 

Categorized in:

16 Comments

  1. Unknown on September 11, 2018

    is it will reconnect again and again if wifi off and on after?

  2. thiennguyen on October 26, 2018

    Thank you so much , your video very useful

  3. kavin sharma on October 27, 2018

    i m really glad to help you out 🙂

  4. kavin sharma on October 27, 2018

    yes sure, code includes a infinite loop for that

  5. Unknown on January 12, 2019

    Can this be done using an Arduino Uno or Nano as well?

  6. Unknown on January 12, 2019

    If so, what are the changes that should be made to the code?

  7. Unknown on January 30, 2019

    can this be ON and OFF with a single entity name like switch and dialog like switch on, switch off?

  8. Unknown on February 24, 2019

    Nice project, can you post for multiple device control?

  9. migueltec on May 2, 2019

    estoy tratando de resolver eso, pero por lo que veo si se puede, osea que solocambia de 0 a 1 en un mismo nombre de firebase si es asi creo que si.

  10. Unknown on July 24, 2019

    Could you provide me with a API v2 compatible index.js?

  11. Naowas Morshed on September 10, 2019

    Getting this error in Serial monitor

    connected: 192.168.31.5

    Exception (28):
    epc1=0x4021509e epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    >>>stack>>>
    ctx: cont
    sp: 3ffffda0 end: 3fffffc0 offset: 01a0
    3fffff40: 3ffeff28 4020fb10 3fffff8c 40205a6e
    3fffff50: 00000100 3ffeec08 00000000 3ffeed58
    3fffff60: 3fffdad0 00000000 3ffeeba4 40205b9e
    3fffff70: 3fffdad0 00000000 3ffeeba4 40201126
    3fffff80: 00000000 00000000 ffefeffe 00006e6f
    3fffff90: 00000000 00efeffe feefeffe feefeffe
    3fffffa0: feefeffe 00000000 3ffeed28 40206a80
    3fffffb0: feefeffe feefeffe 3ffe8578 4010054d
    <<<stack<<<

  12. Eiwaa Groups on January 6, 2020

    Great post!
    I haven’t known about it before. This article is very helpful!
    Thank you so much! home automation in abu dhabi

  13. Jennet on February 1, 2020

    Gathering Room Projectors are principally used to give introductions and reports in meeting rooms for the most part. fixed projector screen

  14. Rodney Tapley on February 13, 2020

    Fantastic blog you have here. You’ll discover me looking at your stuff often. Saved! flexible track lighting

  15. Unknown on February 20, 2020

    Getting this error in Serial monitor

    connected: 192.168.31.5

    Exception (28):
    epc1=0x4021509e epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    >>>stack>>>
    ctx: cont
    sp: 3ffffda0 end: 3fffffc0 offset: 01a0
    3fffff40: 3ffeff28 4020fb10 3fffff8c 40205a6e
    3fffff50: 00000100 3ffeec08 00000000 3ffeed58
    3fffff60: 3fffdad0 00000000 3ffeeba4 40205b9e
    3fffff70: 3fffdad0 00000000 3ffeeba4 40201126
    3fffff80: 00000000 00000000 ffefeffe 00006e6f
    3fffff90: 00000000 00efeffe feefeffe feefeffe
    3fffffa0: feefeffe 00000000 3ffeed28 40206a80
    3fffffb0: feefeffe feefeffe 3ffe8578 4010054d
    <<<stack<<<

  16. Shyan on March 17, 2020

    Home Automation
    People are installing home automation systems because of their immense benefits. In an automated home, every appliance/gadget such as thermostats, lights, cameras is linked with a controllable network.

Comments are closed.