HOME Automation and Energy Prediction

2,009

21

2

Published

Introduction: HOME Automation and Energy Prediction

HAEP (Home Automation and Energy Prediction System) is a Project about Home Automation system which is built around the idea of Measuring and Predicting the Energy consumption of the House. It has been several years since Home Automation has stepped in our lives and made our better than it was ever before. If you were a fan of The Jetsons cartoon series growing up, you likely have dreamt of flying cars, a fully automated home, and a world where anything is available at the push of a button. Cars certainly aren’t flying yet, but automated driving isn’t too far away. And neither is the ability to control many aspects of your home with a few clicks. Ultimately, at some point, our various home appliances could be connected, allowing us to control them all from our phones or another type of device. For now, some appliances can be controlled by using a Wi-Fi connection, but you need separate smartphone apps or devices to tell them what to do.

Major goal of this Project is to perform analytics on the collected data and predict the Energy Consumption for next Day or Month. We people waste a lot of energy in our daily usage either by not turning the lights off when not in use or by utilizing old and inefficient appliances that consume large amount of energy. Energy needs to be conserved not only to cut costs but also to preserve the resources for longer use.r away. And neither is the ability to control many aspects of your home with a few clicks.

Step 1: Walking Through System

  1. User will Switch On/Off the Device using the Android App built for the System.
  2. Data from Android goes to Firebase document on Cloud.
  3. Arduino is continuously listening for the change of data in the Firebase Document.
  4. Based on the Field value in Firebase Document it changes the State of the Device.
  5. Arduino keeps on collecting Current Temperature and Humidity.
  6. These values are sent to the Firebase Document for analytics purpose.
  7. Now the data is Collected by the Python Script running on the Server.
  8. A Linear Regression Model is ran on the collected data and next day prediction is done.
  9. The value is then sent to Android App via Firebase again.

Step 2: Components

HARDWARE
  1. Arduino UNO
  2. ESP8266/01
  3. LED's
  4. DHT11
  5. Wires
  6. Power Source

SOFTWARE

  1. Firebase Account
  2. Python
  3. Scikit-Learn

Step 3: Connecting and Coding Arduino to ESP

ESP has only 8 Pins out of which only two can be used for GPIO purposes. So to overcome the shortage of pins and also at the same time getting connected to Internet i have Serially connected the ESP to Arduino so that Arduino can exchange packets through ESP.

So Arduino is coded to collect data from sensors and then it all to ESP and also receive data from ESP via Serial Comm.

Similarly ESP is coded to receive all the sensor data from Arduino and push it to Firebase and send the incoming packets from Firebase to Arduino to perform required action.

Step 4: Setting Up Firebase

  1. Download FirebaseArduino form Library Manger of Arduino IDE.
  2. Open File > Examples > FirebaseArduino > FirebaseRoom_ESP8266
  3. In FirebaseRoom_ESP8266: Replace WIFI_SSID and WIFI_PASSWORD with WiFi credentials
  4. Go to https://firebase.google.com/console/ and create a new Firebase Project
  5. Go to Database
  6. Copy the Database hostname (Database URL without https:// and trailing /)
  7. In FirebaseRoom_ESP8266: replace FIREBASE_HOST with the Database Hostname
  8. Go to ⚙ > Project Settings > Database > Database secrets
  9. Click Firebase Secrets > Show
  10. Copy the Database Secret
  11. In FirebaseRoom_ESP8266: Replace FIREBASE_AUTH with Database Secret
  12. Select the board Board > ESP8266 Modules > NodeMCU 1.0
  13. Select the serial port Port > /dev/tty...
  14. Select the upload speed Upload Speed > 115200
  15. Click Sketch > Upload

for more help read the Documentation: http://firebase-arduino.readthedocs.io/en/latest/

Step 5: Setting Up Python and Performing Analytics

First let me describe you our Data. So whenever user switches on/off any appliances we store the time-stamp at which it has been switched on and store it in firebase along with the current temperature and humidity of the room is also fetched from DHT11. Next time when user switches off the same device again a timestamp is generate and stored in the firebase. Now we have our data in firebase, we will calculate the difference using the python script and to obtain the duration for which device was switched on. We will multiply this with unit energy rate of the area to get the Total Price.

Our features includes Day, Temperature and Humidity whereas our labels include Duration for which our device was switched on.

We will be performing Linear Regression on the incoming Data. Its an Unsupervised Machine Learning Algorithm. Most basic type of regression and commonly used predictive analysis. Linear regression attempts to model the relationship between two variables by fitting a linear equation to observed data. One variable is considered to be an explanatory variable, and the other is considered to be a dependent variable.

Equation: Y = aX + b

Step 6: Android App

App is developed in Android Studio so i will post the link of my repo to check it out.

To add Firebase to your app you'll need a Firebase project and a Firebase configuration file for your app.

  1. Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Add project.
  2. Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
  3. When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.
  4. At the end, you'll download a google-services.json file. You can download this file again at any time.
  5. If you haven't done so already, copy this into your project's module folder, typically app/.

Add the SDK

If you would like to integrate the Firebase libraries into one of your own projects, you need to perform a few basic tasks to prepare your Android Studio project. You may have already done this as part of adding Firebase to your app.

First, add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository:

buildscript {

// ...

dependencies {

// ...

classpath 'com.google.gms:google-services:3.1.1' // google-services plugin

}

}

allprojects {

// ...

repositories {

// ...

maven {

url "https://maven.google.com" // Google's Maven repository

}

}

}

Add Firebase to Your Android Project

Prerequisites

A device running Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 11.8.0 or higher

The latest version of Android Studio

If you don't have an Android Studio project already, you can download one of our quickstart samples if you just want to try a Firebase feature. If you're using a quickstart, remember to get the application ID from the build.gradle file in your project's module folder (typically app/), as you'll need this package name for the next step.

Note: If you are upgrading from a 2.X version of the Firebase SDK, see our upgrade guide for Android to get started.

Add Firebase to your app

If you're using Android Studio version 2.2 or later, the Firebase Assistant is the simplest way to connect your app to Firebase. The Assistant can connect your existing project or create a new one for you with all the necessary gradle dependencies.

If you're using an older version of Android Studio or have a more complex project configuration, you can still manually add Firebase to your app.

Use the Firebase Assistant

To open the Firebase Assistant in Android Studio:

Click Tools > Firebase to open the Assistant window.

Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).

Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.

That's it! You can skip ahead to the next steps.

Manually add Firebase

To add Firebase to your app you'll need a Firebase project and a Firebase configuration file for your app.

Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Add project.

Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.

When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.

At the end, you'll download a google-services.json file. You can download this file again at any time.

If you haven't done so already, copy this into your project's module folder, typically app/.

Note: If you have multiple build variants with different package names defined, each app must be added to your project in Firebase console.

Add the SDK

If you would like to integrate the Firebase libraries into one of your own projects, you need to perform a few basic tasks to prepare your Android Studio project. You may have already done this as part of adding Firebase to your app.

First, add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository:

buildscript {

// ...

dependencies {

// ...

classpath 'com.google.gms:google-services:3.1.1' // google-services plugin

}

}

allprojects {

// ...

repositories {

// ...

maven {

url "https://maven.google.com" // Google's Maven repository

}

}

}

Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:

apply plugin: 'com.android.application'

android {

// ...

}

dependencies {

// ...

compile 'com.google.firebase:firebase-core:11.8.0'

// Getting a "Could not find" error? Make sure you have

// added the Google maven respository to your root build.gradle

}

// ADD THIS AT THE BOTTOM

apply plugin: 'com.google.gms.google-services'

You should also add the dependencies for the Firebase SDKs you want to use. We recommend starting with com.google.firebase:firebase-core, which provides Google Analytics for Firebase functionality.

https://github.com/jha-prateek/Home

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Water Contest

      Water Contest
    • Clocks Contest

      Clocks Contest

    2 Discussions