Home Automation with Raspberry Pi and Google Assistant
The Internet of Things is the most trending technology today, alongside wearables and robotics. The concept is simple: Devices in your home (or wherever they are) have the capability to communicate with each other via the internet. Home Automation is a category under IoT, where one can control appliances like lights, door locks and air conditioning through the Web interface or smartphone applications. Here, I have developed a Web based Raspberry Pi Home Automation system, which would allow you to control the lights from anywhere in the world using normal HTTP protocols.
Raspberry Pi is one of the most popular microprocessor used in IoT projects. Its support through multiple GPIO pins and User-friendly Interface and support for python scripts make it the most viable technology to use. In this projects I have the following components
- Raspberry Pi 3 Model B
- Relay
- Jumper Wires
- Light bulb connected to a plug
This is all that you would need to make a successful Home Automation system. I used Adafruit I/O interface to make HTTP requests and send ON/OFF information to the Raspberry Pi running python script, and then connected the Google assistant to Adafruit using IFTTT
The Python Script:
import RPi.GPIO as GPIO
from Adafruit_IO import Client
import time
ADAFRUIT_IO_USERNAME = "username"
ADAFRUIT_IO_KEY = "key"
GPIO.setmode(GPIO.BCM)
GPIO.setup(2,GPIO.OUTPUT)
def switch_on():
GPIO.output(2, False)
current = 'ON'
def switch_off():
GPIO.output(2, True)
current = 'OFF'
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
while True:
data = aio.receive('toggle-switch')
if data.value == 'OFF' and current != 'OFF':
switch_off()
elif data.value == 'ON' and current != 'ON':
switch_on()
time.sleep(1)