Monthly Archives: May 2016

Smart Power Strip 2.0

So I guess you probably won’t buy my app if you don’t have anything to control . . .

I guess that’s fair.

So let’s fix that, even though hooking up the Raspberry Pi to the garage door opener is by far the easiest and least dangerous thing you can do.

Speaking of DANGEROUS, I AM NOT AN ELECTRICIAN! I AM NOT AN ELECTRICIAN! I AM NOT AN ELECTRICIAN!

There I said it 3 times so that makes it so.

Not that this one is much more complicated than changing out a outlet in a house, but I didn’t burn down my house, and I didn’t come to yours and burn it down either. If it does burn down that would be your fault.

With that out of the way . . .

First, before starting this project, make sure your Raspberry Pi is configured and you can hear the relay click when you send the Raspberry Pi commands. It royaly stinks to get this thing all screwed together and then find out you have to take everything apart to find out how you wired it wrong.

Here is what the final product looks like:

Power Strip 2.0

Power Strip 2.0

Power Strip 2.0 - Side

Power Strip 2.0 – Side

Power Strip 2.0 - Rear

Power Strip 2.0 – Rear

You have probably seen my first version of the Smart Power Strip and I tried to figure out a way to enclose the relay in something so it would be a little less dangerous and look a little better. I wanted to try to tuck it in the power strip itself, but there just isn’t quite enough room (at least at my skill level) to do that. I did find that the relay will fit into a golf ball plastic display case with some modification, but I still didn’t like having to mount it with double sided tape or something like that.

So I started to think, what was the coolest thing you could have sitting around to hide a Raspberry Pi along with a relay in, and the best thing I can think of is a subwoofer.

So I searched Amazon for the smallest, cheapest subwoofer I could find. And that would be refurbished computer speakers with a sub. $20. For once I was happy to buy refurbished because I was going to throw all the stuff that could possibly be broke away.

So when I got the speakers I instantly gutted the sub box and threw all the electronics in the trash.

Empty Sub Box

Empty Sub Box

I then took a store bought power strip I already had and WHILE IT WAS UNPLUGGED I took it apart and cut the power cord on the inside ( I suppose I could have just cut it on the outside and stripped the wires too)

Power Strip Power Cord

Power Strip Power Cord

I then went to Home Depot and bought a Double Gang Wall Outlet Box (the blue plastic box), 2 Wall outlets, and an extra 25′ of wiring like they use in the walls of your house, and wire nuts.

IMG_0810

IMG_0802

This is how it is wired without being in the box

IMG_0811

Here is the side with the “HOT” wires.

Hot

Hot

Notice that I am pointing at a tab with a screwdriver on the left and there is no tab on the outlet on the right when you remove the tab with a screw driver or pair of pointed nose pliers you are able to turn them on and off individually. That is what I will be doing with the relay.

I left the tab on the other one, because for this implementation I want 2 outlets to always be on as long as the power strip is plugged in, and those are the outlets I will plug the Raspberry Pi into.

There is no reason why you couldn’t break the tab and add another relay and control all four. In fact they make relay’s with 8 switches and you could control 8 outlets (in theory, I have NOT tested that configuration yet).

And here is the common wire side.

Common

Common

I accidentally broke the wrong tab off of the outlet, that’s why you see that ugly little jumper wire on the right.

Looking at the HOT side again you will notices I made the wires going from the outlet to the relay VERY short. I did this so I would have enough room to get the relay to fit in the Gang Box vertically. The wire in the left coming out of the first connection from the left goes straight in the outlet, the other HOT wire coming out of the fourth connection from the left on the relay had to jog to the right to go into the outlet.

On your first try I would recommend just using one outlet, break off the tab so you can control both outlets, but use the other half of the Gang Box to put all your connections in and then just plug the Raspberry Pi into a wall outlet, then come back later and reconfigure for two outlets. You want to make sure all your connections are solid to avoid sparks and possible fires so it’s nice to have enough wire to do that.

Then the second and fifth connections from the left on the relay you use some of the extra wire you bought to run a couple connections that you will connect to the Black/HOT wire on the power cord you got from a real power strip.

Hot

Hot

Looking at the Common side again, as long as you leave the tabs in tact (there really isn’t a reason not to) you can just run one wire back (with the extra wire you bought) for each outlet.

In the pictures you will see the green “ground” wire hooked up, this will be the first wire we connect when we assemble everything, but don’t do that until you get the power cord fed through the little hole in the back and bring it out the big hole where the blue box goes.

IMG_0803

IMG_0806

Now I fed the wires through the back of the Gang Box, but I bet all the electrician’s reading this post probably just had 3 – 4 cows. You definitely want to make as many connections as you can INSIDE the box (THAT’S WHAT THE HECK THEY ARE FOR!) but I didn’t SO YOU HAVE BEEN WARNED! If your house burns down I TOLD YOU NOT TO DO IT THIS WAY!

IMG_0815

IMG_0800

IMG_0799

Connect only the Common wires together and mount them SECURELY (to avoid sparks and fire) with a wire nut. Make sure the wires are not loose in the wire nut.

Connect all the HOT wires together and mount them SECURELY (to avoid sparks and fire) with a wire nut. Make sure the wires are not loose in the wire nut.

Finally mount the box.

IMG_0796

And tuck the Raspberry Pi in the bottom.

IMG_0793

IMG_0795

I love the IDEA of wireless, but since I have to replace my Access Points about every 6 months, I prefer the reliability of using CAT5, so you can use a WIPI adapter if you like, but I also make a second whole in the back (3 all together, one other one for the Raspberry Pi power cord) and run CAT5 to the Raspberry Pi. I saved the little plugs from the back when I gutted the original electronics, you can re-use them to hold the CAT5 and run it through the original power cord hole.

Now for testing, AGAIN, I AM NOT AN ELECTRICIAN. But I would suggest taking it outside, hooking it up to a really long extension cord and then plug the extension cord to the wall and make sure it doesn’t explode. Also it would be best if the plug you plug it into would happen to be a GFI so it pops the little breaker if any of your connections are wrong.

Then if all goes well you would try it inside, again hooking it up to a GFI in case of problems. Then test it out for a weekend. Don’t take it to your summer home and test it out by leaving it there for a month unattended, that would not be very smart.

There you go! Now you have NO EXCUSE not to buy my app. (Except for the known fact that Android people don’t pay for things)

Raspberry Pi Configuration Commands Quick Sheet

email:frank.evo2@gmail.com

——— DO NOT DOWNLOAD RASPBIAN JESSIE LITE IT IS BROKEN ! ! ! ! ————
I just love new upgrades!!! (Luckily I checked the page today 4/10/2017)
The lite version does not have pkexec which you will need to make it so you can run commands on the Raspberry Pi from your phone!

———- DO DOWNLOAD THE FULL VERSION ! ! ! ! ————–
Maybe my download was corrupt, if so I will update this page later, just didn’t want you to waste your time ! ! !

Just verified that process still works with FULL BLOWN JESSIE VERSION ! ! !

The command:
www-data ALL=(ALL) NOPASSWD: ALL

Looked like it might have changed, but it did not, it is still correct.

Raspbian image repository if you need it – http://downloads.raspberrypi.org/raspbian/images/

!!!!!!!! ADDED PICTURES FOR ENTIRE PROCESS BELOW !!!!!!!!

– If you need to expand the os or change password or change location info

sudo raspi-config

– Upgrade and Update –

sudo apt-get update

sudo apt-get upgrade

– Web Server (Apache) install –

sudo apt-get install apache2 -y

– PHP Install –

sudo apt-get install php5 libapache2-mod-php5 -y

– Permissions to run php scripts in web directory –

sudo pkexec visudo

go down to the very bottom and add:

www-data ALL=(ALL) NOPASSWD: ALL

ctrl-o (Save)

enter (Confirm)

ctrl-x (Exit)

– GIT INSTALL –

sudo apt-get install git-core

– My Python and PHP scripts needed by the hub and free app –

Make sure you are in the /home/pi directory.

Make a directory called git:

sudo mkdir git

Go to that directory:

cd git

Get my scripts from Git:

sudo git clone https://github.com/z4x4van/Home-Automation-Production.git

Go to Home-Automation-Production directory:

cd Home-Automation-Production

Python scripts go in the /home/pi directory – I will show you a shortcut

PHP scripts go in the /var/www directory for Wheezy – I will show you a shortcut
or
PHP scripts go in the /var/www/html directory for Jessie – I will show you a shortcut

—-Warning—-Warning—-Warning—-Warning—-Warning!

I am about to give you a command that takes you out of safe mode and into full on admin mode that will let you break anything without asking “Are You Sure?”

But this allows you to get to root which makes copying files to the right directory doable from a single command.

Make sure you type exit as soon as your done copying the files!

So while in the /home/pi/git/Home-Automation-Production directory type:

sudo su

YOU ARE NOW IN ADMIN MODE!

Now type:

(UPDATE! raspbian JESSIE has moved the location where to put PHP files)

cp *.php /var/www/html – to put the php files where they go.

(Wheezy PHP files)

cp *.php /var/www/ – to put the php files where they go.

(UPDATE! use command below for both Wheezy and JESSIE python files)

cp *.py /home/pi – to put the Python files where they go.

NOW TYPE:

exit

You can now go to these directories and make sure they have:

/home/pi – powerOn.py powerOff.py togMe.py

(UPDATE! raspbian JESSIE has moved the location where to put PHP files)

Wheezy:
/var/www – powerOn.php powerOff.php togMe.php

Jessie:
/var/www/html – powerOn.php powerOff.php togMe.php

If they are there Your Raspberry Pi is now ready!

You can now go get and install the HUB app first which will give you an IoT Chat Room Code, this is what your Hub monitors while waiting for commands from the Remote app on your phone.

When you install the Remote app on your phone it will ask for this code so it can talk to the hub.

The best way to make sure your Phone is communicating to your Hub is to try to adjust the volume on your hub by going to the slide out menu on the left side of your phone and select a volume level. Acknowledgements are enabled by default so you do not need to enable them first.

If that works you are ready to start configuring some new devices as I show you in the YouTube video’s.

———- PICTURES OF ENTIRE PROCESS ———–

Go here

Select Raspbian

Download this

Wait til done

Unzip image using 7zip

Select downloaded zip file

Extract it

let finish

when you have a .img file

Use disk imager on windows machine

write image to micro sd card

when write is complete, eject micro sd card from PC and put in Raspberry Pi

Open terminal app

Update Raspbian

Upgrade Raspbian

Upgrade can take a while, so watch some TV or do something else for a half hour.

Install Apache Server

Install PHP

Open file to set permissions

Scroll to end of file and add permission line

ctrl-o to save
ctrl-x to exit

Install GIT:

Install GIT

Make a GIT directory in /home/pi (you should already be there)

Go into GIT directory:

GIT directory

Get my files from GIT:

Get my files from GIT

Go into new directory with my files:

Home-Automation-Production

Enter into dangerous admin mode:

sudo su

Copy PHP files:

cp *.php /var/www/html

Copy Python files:

cp *.py /home/pi

EXIT OUT OF ADMIN MODE!

exit

DONE! You can make sure the files are where they need to be if you want:

file check

PHP files

Bonus:

– Setting Static IP for Raspberry Pi (Not a must) –

ifconfig

This reveals your router information, the bit you want is after eth0 (the ethernet connection). . . .

eth0 Link encap:Ethernet HWaddr b8:27:eb:b3:fc:2c

inet addr:192.168.1.81 Bcast:192.168.1.255 Mask:255.255.255.0

Write down the following information. . . (Or take a picture)

inet addr – 192.168.1.81 (Pi’s Current IP Address)

Bcast – 192.168.1.255 (The Broadcast IP Range)

Mask – 255.255.255.0 (Subnet Mask Address)

We need a little more information before we proceed. Use the command. . .

netstat -nr

We need:

‘Gateway’ Address – 192.168.1.254

‘Destination’ Address – 192.168.1.0

EDITING CONFIGURATION

sudo nano /etc/network/interfaces

Simply change the line that reads:

iface eth0 inet dhcp

to

iface eth0 inet static

Then directly below this line enter the following (Please Note. You will need your own addresses we gathered in Part B, more details below). . . .

address 192.168.1.81

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

gateway 192.168.1.254

email:frank.evo2@gmail.com

Home Automation Remote and Hub Welcome Page

Thank’s for visiting my Blog!

I think Home Automation will be on the same list as keyless car entry, tv remotes and DVR’s, you don’t really NEED them, but you will wonder how you got along without them.

So let’s get to it.

Things you need to do this Home Automation thing:

— Raspberry Pi Hardware —

IMG_0926
1. Raspberry Pi (around $35)
IMG_0928
2. A Micro SD Card (16 GB or higher) with Raspbian and configured the way I show you here.
(If the process seems too daunting, it is harder than I wish it was,
I sell pre configured 16 GB Micro SD cards for $15 – contact me through e-mail)
IMG_0930
3. Power Cord for the Raspberry Pi (not included with just the Raspberry Pi) ($7)
You can use a cord for a Android phone if you have extras.
IMG_0927
4. A relay ($4)
IMG_0925
5. Wires to connect the relay to the Raspberry Pi ($9)
6. Ethernet Cable
7. HDMI Cable (to hook up to a TV or Monitor)
8. Keyboard and Mouse.
9. My Free App to test with. (it only works with devices on the same network)

My app uses the Broadcom GPIO pin layout numbering system:

GPIO LAYOUT

Broadcom GPIO Pin Layout

Things that will make your setup complete:

1. A webcam – this is mainly if you get the garage door app, as you see in my video’s I have
a webcam in my garage that I can use to check on things. It is a surprisingly dependable
process, but buttons get pushed accidentally, our phones don’t have military grade GPS in
them, you will get so used to not ever opening or closing your garage door and you will
cancel the timer and forget that you have to actually manually shut it.

2. A Hub that is a phone with phone service – YOUR HOUSE ACTUALLY TEXT’S YOU!! It will tell
when and who has arrived or left your house (if they also have the app) it can tell you
if your garage door is open, it can tell you if the front or back door is open, it can
tell you what the battery level is on your hub, it can tell you when scheduled commands
(front lights on (scheduled)) are run.

3. A garage door alarm sensor ($20) – essentially a magnet attached to the bottom of your
door that can tell the Raspberry Pi, FOR A FACT! ,if the door is shut or open. I REALLY
don’t need a webcam in the garage anymore, I just use it for demo’s.

Of course you don’t have to worry about the above things if you don’t have:

1. A Android device (Gingerbread or higher) with my Hub App (With cloud service included)
installed.
2. My Garage Door App.
3. My Remote App.

Paid App version history:

Version 2.1 will hide the Action Bar until you tap the screen then you can access the menu, tap the screen again to hide it. This allows the whole screen to be black except the info bar.

Version 2.1 will also include a menu option to enable self sustain mode. This allows the hub to monitor it’s battery level and turn on or off a smart outlet or smart power strip outlet when the battery get’s over 98% or below 30%. (you must enter in the Raspberry Pi IP address and gpio pin number on the hub)

Version 2.0
The hub must remain on at all times, I made most of the screen black to avoid burn in, but the Action Bar remains visible to allow access to the menu. I highly recommend installing it on an old phone (kitkat or higher) that you don’t use anymore (Next version I will add functionality to hide Action Bar until you swipe down on the screen, that should make it so there will be no screen burn in).

Things you should LOVE about this app:
The hub is not proprietary! I am not locking you in to any system that requires you use their special hub and if they go away so does the use for their hub, so in the trash it goes! With my setup you still have a functioning android device. You also use Raspberry Pi’s which you can use for other things besides this app which I show you on my blog.

YouTube Video Demo’s

Part 1
Part 2
Part 3
Part 4
Part 5
Part 6

That is the easy part, your welcome.

Now the difficult part the raspberry pi side: (Again, I sell pre-configured 16 GB Micro SD
cards for $15 – contact me through e-mail)

Raspberry Pi Configuration Process

Once you get the Raspberry Pi configured you will then need to download my python and php scripts to the Raspberry Pi from Git.

To install Git on the Raspberry Pi:

sudo apt-get install git-core

My Python and PHP scripts needed by the hub app.

Make sure you are in the /home/pi directory.

Make a directory called git: sudo mkdir git

Go to that directory: cd git

Get my scripts from Git:

sudo git clone https://github.com/z4x4van/Home-Automation-Production.git

Go to Home-Automation-Production directory: cd Home-Automation-Production

Python scripts go in the /home/pi directory – I will show you a shortcut

PHP scripts go in the /var/www directory – I will show you a shortcut
(UPDATE! raspbain JESSIE has changed this location to /var/www/html

(If this directory doesn’t exist you skipped the Raspberry Pi Configuration Process step which has you install a Apache Web server and PHP).

—-Warning—-Warning—-Warning—-Warning—-Warning!

I am about to give you a command that takes you out of safe mode and into full on admin mode that will let you break anything without asking “Are You Sure?”

But this allows you to get to root which makes copying files to the right directory doable from a single command.

Make sure you type exit as soon as your done copying the files!

So while in the /home/pi/git/Home-Automation-Production directory type:

sudo su

YOU ARE NOW IN ADMIN MODE!

Now type: cp *.php /var/www/ – to put the php files where they go.

(UPDATE! raspbian JESSIE has moved the location where to put PHP files, use above for
Wheezy, Use command below for JESSIE)

Now type: cp *.php /var/www/html – to put the php files where they go.

(UPDATE! use command below for both Wheezy and JESSIE python files)

And type: cp *.py /home/pi – to put the Python files where they go.

NOW TYPE: exit

You can now go to these directories and make sure they have:

/home/pi – powerOn.py powerOff.py togMe.py

(UPDATE! raspbian JESSIE has moved the location where to put PHP files)

Wheezy:
/var/www – powerOn.php powerOff.php togMe.php

Jessie:
/var/www/html – powerOn.php powerOff.php togMe.php

If they are there Your Raspberry Pi is now ready!

You can now go get and install the HUB app first which will give you an IoT Chat Room Code, this is what your Hub monitors while waiting for commands from the Remote app on your phone.

When you install the Remote app on your phone it will ask for this code so it can talk to the hub.

The best way to make sure your Phone is communicating to your Hub is to try to adjust the volume on your hub by going to the slide out menu on the left side of your phone and select a volume level. Acknowledgements are enabled by default so you do not need to enable them first.

If that works you are ready to start configuring some new devices as I show you in the YouTube video’s.