sujayy1983 / Home-Device-Automation-Framework

Flask based scalable 'Home automation framework'. Discover and program devices in your home network. Visualize your network with D3 visualization and shutdown device(s) that do not need to be in the Home network.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Author: Sujayyendhiren Ramarao

Description: Automate all the REST API based home network devices. 
    
            Key features of this micro web app:
             (i) Keeps learning all the devices in home network and their OS properties (If a device is hardened then OS info maynot be populated).
                 D3 JS visualization displays a group of nodes/devices in a color based on their OS i.e. all IOS devices have same color and similarly all Linux 
                 devices are represented in same color. This is a good of turning of Wifi on devices that do not need to be on the network.
             (ii) Discovered device IPs are automatically picked for Phillips Hue and Bose soundtouch based on keyword matches of those device hostnames.
             (iii) This App can be leveraged as Wireless doorbell. We are free to add any mp3 (one or more) of our choice to play as a doorbell. If we open this app on our handheld device (when we are in home network Wifi range) we are free to click one of the doorbell options. 

Note: Please refer INSTALL.md for installation details on Raspberry Pi3. This implementation is tested for python 3.x. 
      It should ideally work for 2.7.x as well. In case of issues please do email me (sujayy1983@gmail.com).

What does this micro app offer ?

  1. Home network discovery and caching
  • D3Js Forcelayout visualization of discovered devices. Hover mouse over any node to view IP address and hostname of device. Discovered home network

  • Caching of discovered info that can be leveraged by other parts of automation Previous caching was done by storing json data. But now we are storing it in sqlite db file. One is generated by this master and another is transferred periodically by slave raspberry pi (if configured).

  1. Basic Hue Light controls - Already configured lights are discovered and displayed on the UI

Following details in the configuration/configuration.yml are leveraged in the code to check device hostname for these keywords and on fulfillment of the following conditions correspodning device IP is used in REST APIs as Philips Hue IP. This lets us choose different combinations of hostnames with a combination of preferred strings.

  hostdiscovery:
  - philips
  - hue

Philips Hue view

  1. Bose Soundtouch - Device info display

    BoseSoundtouch view

Following details in the configuration/configuration.yml are leveraged in the code to check device hostname for these keywords and on fulfillment of the following conditions correspodning device IP is used in REST APIs as bose soundtouch IP.

hostdiscovery:
  - sound
  - touch
  1. Os detection of discovered devices Note: Few entries are intentionally removed for security reasons. OS detection of home devices

  2. Virtual door bell. Assuming that the app is running on a Raspberry Pi and is running 24*7. You'll need to add speaker and add a couple of mp3 files. This app has an option called 'Virtual Door bell'. Virtual door bell can be played from any handheld device. When a handheld device is in Home WiFi range, we can inform a person at home by clicking on one of the buttons(mp3 files). The directory 'mp3' is created once we run this app or we can create it manually before starting the app. All the mp3 files placed in 'mp3' directory are listed in the "Wifi Door bell" webpage as clickable buttons.

sudo apt-get install -y alsa-utils  mpg321 lame
sudo modprobe snd_bcm2835

Wifi based doorbell

  1. Enable a service on the server. On my Raspberry Pi 3 I have AIY Google voicekit setup. The service is enabled or disable via this app.

Google AIY service control

  1. Check internet connectivity.

Traceroute

  1. Initial analysis of Kaggle labelled datasets This tells us maximum occurrences per column
    • Upload a csv dataset using upload options.
    • Select a dataset and select top occurrence count in rows.

What does this tool leverage

  1. Tested on MAC with Python 3.6 and Python3.4 on Raspberry Pi3.
  2. Flask + jinja2 + html + bootstrap + D3js + nmap + scapy

Installation

Please refer INSTALL.md

Future plans

  1. Code is grouped in classes but nor object oriented. Need to refactor it.
  2. More home automation devices shall be integrated here.
  3. Voice activated controls (Leveraging google assistant) integrating with AIY Google kit.
  4. Kaggle analysis is in early stages. Need to add more punch to it.
  5. Release unittest options. For now it is evolving.
  6. Plan to add proximity detection by integrating with camera(s).
  7. Intrusion of new device should raise alarm (voice).

Issues

  • Container network and home network are different please do not build docker image yet.
  • No logging in the initial commit
  • Improvements in REST abstraction
  • Code assumes that ip address ending with '.1' is Gateway. In the next version default gateway from netstat -r shall be picked.
  • Traceroute failure case needs to be differentiated if it is failure to reach the destination vs internet connectivity issue.

Docker implementation

Tested container build on MAC. On Raspberry Pi docker is usable only with Hypriot flavor. Network discovery and many features maynot work yet.

Build docker image
docker build -t homeautomation .
Run docker container
docker run -d --name="HomeAutomation" -p 80:80 sujayy1983/homeautomation

Report issues and suggestions

About

Flask based scalable 'Home automation framework'. Discover and program devices in your home network. Visualize your network with D3 visualization and shutdown device(s) that do not need to be in the Home network.


Languages

Language:HTML 38.1%Language:Python 34.6%Language:CSS 27.3%