Control Your Appliances with XinaBox and Google Home

Control Your Appliances with XinaBox and Google Home

Learn how to control AC electrical appliances conveniently using your voice, using XinaBox’s xChips, Blynk and Google Assistant.

XinaBox produces a range of 80+ modular xChips, which include cores/CPUs, sensors, power, communication, output, and storage, using a connectivity standard without wires, soldering, breadboards or hardware knowledge.

xChip CW01 (ESP8266 Core) is a Microprocessor and Wi-Fi module, enabling users to send/receive data to/from the cloud.

xChip OC03 (PCA9554A) is a low-voltage control relay module capable of switching AC and DC loads up to 40V.

The XinaBox is integrated with Google Assistant/Home through IFTTT to Blynk App which allows to control the appliances over the Internet anywhere, although other IoT platforms can also be used.

Whenever a Google Assistant/Home app is commanded with your voice with some predefined custom phrase, the app sends request to IFTTT to make actions predefined on IFTTT applet. In this case IFTTT trigger Webhooks service in response, which uses HTTP to update status of pins in Blynk App.

The project can also be made using Amazon Alexa as voice service; Ubidots and other IoT platforms can also be used given that they support HTTP Webhooks.

By the end of this guide, you will be able to build your own voice-controlled home automation projects.

Requirements

  • 1x CW01 - Wi-Fi Core(ESP8266/ESP-12F)
  • 1x OC03 - Relay Out(PCA9554A)
  • 1x IP01 - USB Programming Interface (FT232R)
  • 1x XC10 - 10-Pack xBus Connectors
  • 1x 5V Power Supply
  • 1x 5V Relay module. The relay module SRD-05VDC-SL-C is used in this tutorial, but any 3.3V or 5V relay module can be used with changes in the code and connections.
  • 1x light bulb. A 11-W Fluorescent light bulb was used in this tutorial.
  • 1x Light bulb socket
  • Google Assistant App and Account
  • Blynk App and Account
  • IFTTT and Account

Step-by-Step

  1. Hardware Setup
  2. Installing Arduino Libraries
  3. Setting Up the Blynk App
  4. Setting Up IFTTT
  5. Result
  6. Summary

1. Hardware Setup

1. Connect xChips CW01, OC03 and IP01 together using the XC10 xBus connectors. You may connect it as shown in the diagram below. Please see this guide on how to assemble xChips generally.

2. Connect VCC and GND of the Relay module to the Power Supply VCC and GND.

Relay module pinout

IMPORTANT NOTE: The Relay module pinout can be different depending on what relay module is used. Double check before connecting.

3. Connect IN/Signal pin of the Relay module to the GND or VCC (Depending on the trigger type) passing though xChip OC03 connectors. My Relay module is LOW-level trigger, therefore I have to connect to GND passing though xChip OC03 connectors.

Connections of Signal, GND and VCC pins of Relay module

4. Connect NO of the Relay module to the Neutral of the light bulb socket, and connect COM of the Relay module to Neutral of AC plug (See Relay module pinout image above).

5. Connect the Hot wire of the AC plug with the Hot wire of the light bulb socket.

DANGER! ELECTRIC SHOCK HAZARD. CALL AN EXPERT TO DO THIS.

2. Installing Arduino Libraries

1. Install Arduino IDE 1.8.8.

2. Install these libraries into Arduino IDE:

NOTE: If you are not familiar with how to Install libraries, please refer to the link: Installing Arduino libraries

3. Setting Up the Blynk App

1. Download the Blynk App.

2. Create your Blynk account and receive an Auth Token. For details see this guide.

3. Create Button Widget:

4. Select V5 pin:

4. Setting Up IFTTT

1. Login to your IFTTT account. Click on This:

2. Select Google Assistant. Choose Say a simple phrase.

3. Enter your phrase and response sentence. Create trigger:

4. Now click on That. Select Webhooks. Choose Make a web request.

5. Enter URL in the format of: https://188.166.206.43/AuthToken/update/D0. Replace AuthToken with the Blynk Auth Token, and replace D0 with V5.

6. Choose the Method to be PUT, the Content Type to be application/json and enter ["1"] in the Body field.

7. Similarly, do the same for turning the lights off. Enter ["0"] in the Body field.

5. Code

*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define DELAY_TIME 1000


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <xOC03.h> // https://github.com/xinabox/arduino-OC03
#include <xCore.h>

xOC03 OC03;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V5
BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  if(pinValue==1)
  {
    Serial.println("Lights turned on");
    OC03.write(HIGH);
  }else if(pinValue==0){
    Serial.println("Lights turned off");
    OC03.write(LOW);;
  }
  
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  #ifdef ESP8266
    Wire.pins(2,14);
  #endif
    
  // Start the I2C Communication
  Wire.begin();
  
  // Start the OC03 port expander
  OC03.begin();

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}

6. Result

7. Summary

In this project we have shown you how to make Home Automation projects using voice to control appliances with XinaBox, Blynk and Google Home/Assistant app.

Previous article Instant Control of Appliances with XinaBox and Blynk
Next article Riverdi and XinaBox - Hello World