Home Automation with SINRIC
Data science projects in pondicherry
Create New

Home Automation with SINRIC

Project period

06/11/2020 - 06/30/2020

Views

23

0



Home Automation with SINRIC
Home Automation with SINRIC

The Internet of Things (IoT) is the network of things or physical objects fixed with electronics, software, sensors, and network connectivity, which permit these objects together and transfer data. IoT allows physical objects to be sensed and controlled remotely across the actual network infrastructure, creating contingency for more direct integration between the computer-based systems and the physical world, and it gives further increases in the efficiency and economic benefit. Home automation systems are used to control home appliances or devices in smart cities and automatically curb the appliances using a remote control device inside or outside the homes. Nevertheless, although remote control provides comfort and ease of use, some major problems require consideration and refinement, such as how to provide an instinctive and user-friendly remote control scheme in the Internet of Things based smart homes. Case studies show that voice searches on the internet are taking over more and more than traditional text-based searches. It is important to note that by the end of the year 2021 about 80% of the searches on the internet are done through voice. What if we were able to use the power of IoT to control the physical device present at our Office/Home from anywhere in the world? Amazing! Is not it. Our project is exactly based on the above concept. By making use of Alexa Echo Dot (Smart Automation Device made by Amazon company) with the ESP8266 (wifi Module) we can pretty much control any electrical/electronic devices. To name a few office lights, fans, doors, and even locks can be controlled over this method. We are using a network device (ESP8266) which is more secure than controlling Bluetooth or Zigbee locally.

Why: Problem statement

From a simple plugin device to centrally controlled heating, we are controlling everything manually. Conventional wall switches are located in several parts of a house and this necessitates manual operations to turn on or off these switches to regulate various appliances. Tragedies happen like thefts especially late in the dark when the user's reception. This occurs often because home does not provide any secure system. Computer Systems enables remote lighting through to complex micro-controller or computer-based networks with varying degrees of intelligence and automation. Home automation provides security, energy efficiency, and simple use hence, it is adopted more. It also provides a foreign interface to home appliances to supply control and monitoring on an online browser.

How: Solution description

To overcome this problem, we introduced a project called Home automation with Amazon echo and SINRIC. The following is the block diagram for our proposed system.

The voice input is given by the user to Alexa. The input is then transmitted from Alexa to the AWS cloud. Here the input is saved as a signal and then passed over to the SINRIC cloud (Switched-mode power supply). It is then sent to Node MCU. Node MCU acts as a major role in our system since it helps to receive wifi and support the entire system. The signal is then forwarded from Node MCU to Channel Relay, then to the socket extension box. From here the signal is transmitted to home appliances where the fan, light, and other electronic devices are connected.

In this project, the main use of raspberry is that the home appliance pi such as fan, light, dryer, etc., are connected to the raspberry pi device. Whenever the home appliances get switched on, the user gets an email notification. We have used 5V in this relay. In this project, we are using only a solid-state relay for its simplification when it is compared to a mechanical relay.

Alexa (Echo) with ESP32 and ESP8266 | Random Nerd Tutorials

 

How is it different from competition

This project explains the system which is designed with voice recognition for controlling all home automation systems to make a smart home with low electricity energy and human energy consumption. Our system does not consist of moving parts, hence Solid-state Relay is used in the project. Solid State Relay does not have any moving parts hence it is used in our proposed system Adding wireless fidelity to embedded systems will open up various possibilities such as worldwide monitoring and control, reliable data storage, etc. This system comprises wireless sensor nodes and a controller section for surveillance. Remote user alerts, live video streaming, and portability are the prime features of the system. WiFi-enabled IoT(Internet of Things) module processes the sensor-based events and sends the sensor status to the controller section.

Who are your customers

IoT based security surveillance systems can be fetched in buildings or houses. This system is user- friendly, we can use it through a laptop or a mobile phone application. Most of the corporation and government sector based companies can use this automation by using Alexa and SINRIC.

Project Phases and Schedule

Phase 1: Creating an account on Amazon Alexa and Sinric.
With Sinric Pro, connect your IoT development board to Alexa with a reliable skill - No more glitchy emulation. Sinric Pro supports all Amazon IoT device types and offers Python, C++, NodeJS libraries with examples to get you up-and-running within minutes. For advanced users, you can create your own custom devices, set up rooms, and routines, and monitor all your devices via REST API. 

 

Getting started:

1. Visit https://sinric.pro

2. Create a free account and log in

3. From the Alexa app or dashboard, Install & Enable the "Sinric Pro" Smart Home Skill

4. Create a new device light1,light2, and fan. Note the authorization token, signing key, and device-ID for your new device.

5. Amazon Alexa app will show a push notification that it discovered your new device.

 

6. Upload this example sketch or use our existing Python or C++ libraries to your project board:
https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries

 

Replace the token, signing key, and WiFI credentials with your own.

7. That’s It!

Phase 2: Wiring up the circuit

A circuit of the wire for the distribution of electricity. An electrical device of the light and fan connected to the relay and microcontroller to the ALEXA.The wiring connection will provide a path for electrical current to flow.

Resources Required

Software Required:

  1. Arduino IDE

  2. Blynk (Android or IOS app)

  3. Amazon Alexa (Android or IOS app)

Alexa (Echo) with ESP32 and ESP8266 | Random Nerd Tutorials

AWS cloud

The user gives the voice input to Alexa, where Alexa is one of the products of amazon, so amazon provides the AWS cloud, hence the AWS cloud is used where it is an open source cloud and has no storage limit. In this project, the use of AWS cloud stores the voice of the user, and it gives the voice signal to SMPS [switch mode power supply].

Hardware Required:

  1. Amazon Echo dot.

  2. Node MCU esp8266.

  3. 5v Relay (4 or 8 channel).

  4.  LED

Channel Relay switches are used to open and close circuits electromechanically. It can control one electrical circuit. They are connected to Mode MCU. The relay is of two types, they are mechanical relay and solid-state relay. Both the relays consist of low-level switching and high-level switching.

Mechanical Relay consists of moving parts which is considered a drawback.

Download:
Project Code Code copy
/* Your file Name : switch_example.ino */
/* Your coding Language : arduino */
/* Your code snippet start here */
/*
 Version 0.4 - April 26 2019
*/ 

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h> //  https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries
#include <ArduinoJson.h> // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries (use the correct version)
#include <StreamString.h>

int device_1 = 5;
int device_2 = 4;
int device_3 = 0;
int device_4 = 2;

ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
WiFiClient client;

#define MyApiKey "8bb09a2b-aa5b-42b9-a6ae-995941758339" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
#define MySSID "Learny" // TODO: Change to your Wifi network SSID
#define MyWifiPassword "LearnY123" // TODO: Change to your Wifi network password

#define HEARTBEAT_INTERVAL 300000 // 5 Minutes 

uint64_t heartbeatTimestamp = 0;
bool isConnected = false;


// deviceId is the ID assgined to your smart-home-device in sinric.com dashboard. Copy it from dashboard and paste it here

void turnOn(String deviceId) {
  if (deviceId == "5d774a0ff1dce8012dfd2116") // Device ID of first device
  {  
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
    digitalWrite(device_1, LOW);
  } 
  else if (deviceId == "5d774a24f1dce8012dfd211f") // Device ID of second device
  { 
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
    digitalWrite(device_2, LOW);
  }
  else if (deviceId == "5d774a33f1dce8012dfd2124") // Device ID of third device
  { 
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
    digitalWrite(device_3, LOW);
  }
  else if (deviceId == "5d774a3ff1dce8012dfd2129") // Device ID of fourth device
  { 
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
    digitalWrite(device_4, LOW);
  }
  else {
    Serial.print("Turn on for unknown device id: ");
    Serial.println(deviceId);    
  }     
}

void turnOff(String deviceId) {
   if (deviceId == "5d774a0ff1dce8012dfd2116") // Device ID of first device
   {  
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
     digitalWrite(device_1, HIGH);
   }
   else if (deviceId == "5d774a24f1dce8012dfd211f") // Device ID of second device
   { 
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
     digitalWrite(device_2, HIGH);
  }
  else if (deviceId == "5d774a33f1dce8012dfd2124") // Device ID of third device
   { 
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
     digitalWrite(device_3, HIGH);
  }
  else if (deviceId == "5d774a3ff1dce8012dfd2129") // Device ID of fourth device
   { 
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
     digitalWrite(device_4, HIGH);
  }
  else {
     Serial.print("Turn off for unknown device id: ");
     Serial.println(deviceId);    
  }
}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
    case WStype_DISCONNECTED:
      isConnected = false;    
      Serial.printf("[WSc] Webservice disconnected from sinric.com!\n");
      break;
    case WStype_CONNECTED: {
      isConnected = true;
      Serial.printf("[WSc] Service connected to sinric.com at url: %s\n", payload);
      Serial.printf("Waiting for commands from sinric.com ...\n");        
      }
      break;
    case WStype_TEXT: {
        Serial.printf("[WSc] get text: %s\n", payload);
        // Example payloads

        // For Switch or Light device types
        // {"deviceId": xxxx, "action": "setPowerState", value: "ON"} // https://developer.amazon.com/docs/device-apis/alexa-powercontroller.html

        // For Light device type
        // Look at the light example in github
          
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject((char*)payload); 
        String deviceId = json ["deviceId"];     
        String action = json ["action"];
        
        if(action == "setPowerState") { // Switch or Light
            String value = json ["value"];
            if(value == "ON") {
                turnOn(deviceId);
            } else {
                turnOff(deviceId);
            }
        }
        else if (action == "SetTargetTemperature") {
            String deviceId = json ["deviceId"];     
            String action = json ["action"];
            String value = json ["value"];
        }
        else if (action == "test") {
            Serial.println("[WSc] received test command from sinric.com");
        }
      }
      break;
    case WStype_BIN:
      Serial.printf("[WSc] get binary length: %u\n", length);
      break;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(device_1, OUTPUT);
  pinMode(device_2, OUTPUT);
  pinMode(device_3, OUTPUT);
  pinMode(device_4, OUTPUT);
  
  
  WiFiMulti.addAP(MySSID, MyWifiPassword);
  Serial.println();
  Serial.print("Connecting to Wifi: ");
  Serial.println(MySSID);  

  // Waiting for Wifi connect
  while(WiFiMulti.run() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  if(WiFiMulti.run() == WL_CONNECTED) {
    Serial.println("");
    Serial.print("WiFi connected. ");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }

  // server address, port and URL
  webSocket.begin("iot.sinric.com", 80, "/");

  // event handler
  webSocket.onEvent(webSocketEvent);
  webSocket.setAuthorization("apikey", MyApiKey);
  
  // try again every 5000ms if connection has failed
  webSocket.setReconnectInterval(5000);   // If you see 'class WebSocketsClient' has no member named 'setReconnectInterval' error update arduinoWebSockets
}

void loop() {
  webSocket.loop();
  
  if(isConnected) {
      uint64_t now = millis();
      
      // Send heartbeat in order to avoid disconnections during ISP resetting IPs over night. Thanks @MacSass
      if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
          heartbeatTimestamp = now;
          webSocket.sendTXT("H");          
      }
  }   
}

// If you want a push button: https://github.com/kakopappa/sinric/blob/master/arduino_examples/switch_with_push_button.ino  
View on Github
Home Automation with SINRIC

Comments

Leave a Comment

Post a Comment

Are you Interested in this project?


Do you need help with a similar project? We can guide you. Please Click the Contact Us button.


Contact Us

Social Sharing