Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Nic
Published © GPL3+

Raspberry Pi / Hologram SMS Controlled AC Power Switch

Using the Nova Hologram, IoT Relay and a Raspberry Pi, easily make a remote smart switch so you can turn devices on/off remotely.

BeginnerFull instructions provided1 hour2,987
Raspberry Pi / Hologram SMS Controlled AC Power Switch

Things used in this project

Story

Read more

Schematics

Schematics

Code

SMS Controlled AC Relay

Python
#Simple remote AC power control 
#Go to Nova Hologram and get a phone number which is $1
#Be sure to get a device key which is free on the Nova Hologram website
#For the code to run automatically on power-up, edit the .bashrc script using #sudo nano and at the bottom add "sudo python project_name.py" where "project_name" is the name of your project.

import time 
import datetime
import subprocess
from Hologram.HologramCloud import HologramCloud
import RPi.GPIO as GPIO

GPIO.setwarnings(False) #turn off warnings
GPIO.setmode(GPIO.BCM) #initialize gpio mode and set pins to off by default
GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW) # Relay is normally on, GPIO.LOW means modem power is on
print 'Home Modem/Router Reboot SMS Controller' #welcome message for console
hologram=HologramCloud(dict(), network='cellular') #setup hologram cloud
hologram.enableSMS #tell hologram to listen for sms
recv=None #if we dont set initial variables the loop breaks
cmd=None
while True: #start the loop
	recv = hologram.popReceivedSMS() #this works, makes the recv variable equal an incoming message
	if recv is not None: #works, run the following code when a message comes in
		print 'SMS From: ', recv.sender #print the sender of the sms
		cmd = recv.message #works, makes the cmd variable the payload of the message.
		print cmd #works, prints only what the sms message is.
		if cmd == 'Reset' or cmd == 'reset': #Checks for Reset or reset (one of them is capital because sometimes an iPhone will capitalize the first letter)
			print 'Start command received' #let the console show we know the SMS had the word start and we will process it
			GPIO.output(17, GPIO.HIGH) #Set normally on relay to off
			time.sleep(10) #Wait ten seconds sec, relay off
			GPIO.output(17, GPIO.LOW) #Set relay back to normally on
			subprocess.call (["hologram","send","--sms","--destination","+1xxxxxxxxxx","Completed!","--devicekey","{U>sZ#6s"])#Sends SMS text "Completed!"
			print 'Command complete' #let the console know we are done
	if recv is None: #Runs the following code when there is no message
		print 'No Command, sleep 60 seconds', datetime.datetime.now() #Prints timestamp, handy for troubleshooting
		time.sleep(60) #60 seconds checks for new messages
		print '' #prints a blank line in the console between timestamps when we have no messages for easier reading

Credits

Nic

Nic

1 project • 2 followers
Thanks to Benstr and Jeremy Fidler.

Comments