Introduction: Raspberry Pi Home Automation

Picture of Raspberry Pi Home Automation

Raspberry Pi is a single board computer for 35$ it is very versatile and given its small size it can fit in basically anywhere. I will walk you through the process of making a Home automation system using MyPi app. This app is very simple and is free to download on IOS/Android/Windows.

Step 1: Parts

Picture of Parts
  1. Raspberry Pi :- Any Raspberry Pi will do but if you take any other than model 3 then you will have to buy a usb internet adapter or go wired like i had to in my Raspberry Pi 2. This tutorial shows the steps of wireless home automation only. Raspberry Pi Model 3
  2. Relay Module :- I have used 2 channel relay but you can go upto 8 channel relay as supported by the MyPi app. Any more relays than 8 channel will require another app or a new webpage. 2 Channel Relay Module
  3. Jumper Wires :- To connect the relay to the Raspberry Pi. Female to Female Jumper Cables
  4. Power Adapter :- Any micro usb adapter will work as long as it is 5v 1A. 5v 1A Micro Usb Adapter

Total:- 52$

Step 2: Setting Up Your Raspberry Pi

Picture of Setting Up Your Raspberry Pi

Connect the Raspberry pi to an internet and assign the pi a static ip address.

Open the terminal in the Raspberry Pi, And type

pi@raspberry :~ $ Sudo apt-get Update (this may take time)

pi@raspberry :~ $ cd /home/pi

pi@raspberry :~ $ ls

pi@raspberry :~ $ wget

pi@raspberry :~ $ ls (check the above file should be added in the directories)

pi@raspberry :~ $ unzip (this will unzip the the directory)

pi@raspberry :~ $ python3 mypi_server.pyc

Wire the relays 5v to Pi's 5v

Gnd to Pi's Gnd

Channel 1 to pin 7

Channel 2 to pin 11

Step 3: Setting Up the App

Picture of Setting Up the App

Open your MyPi app and go to settings.

Put your Pi's Ip address and change the port to whichever port the pi is searching devices on (after the last command it should say listen for incoming connections on port and then the port number).

Go ahead and test your system by switching on or off in the app and check if the relay is switching on off.

Do not turn off the Raspberry Pi right now proceed to the next step so that the Pi runs this script every time its powered on.

Step 4: Making This So That It Runs This From the Start

Picture of Making This So That It Runs This From the Start

Disconnect from the app by selecting disconnect in the MyPi app.

In the Raspberry Pi type .....

Open your MyPi app and go to settings...........
pi@raspberry :~ $ sudo nano /etc/rc.local

in the directory go between where it is written "fi" and exit 0 and type

python3 /home/pi/mypi_server.pyc &

save and exit the file ( the'&' is in the code not a mistake). After this reboot the Pi by typing

pi@raspberry :~ $ sudo reboot

Step 5: Final Testing

You no longer need to keep your Pi attached to a monitor. After the reboot just open the app and press connect you should be connected to your Pi and be able to control the relays.

Please post your pictures if you made this yourself.

Feel free to ask questions.



jade7272 made it! (author)2017-11-18

here is my Raspberry Pi Setup

jade7272 (author)2017-11-12

there is also a good tutorial with a bit different setup with a great mqtt and rrd4j as well as auto start in a bit different config at

Good start though

marda57 (author)2017-11-07

Very good work but I ave a compilation problems

RuntimeError: Bad magic number in .pyc file

how can I fix it

DivyanshJ2 (author)marda572017-11-08

Do you mind sending a picture of this and are you facing this issue in step 2 or step 4??

marda57 made it! (author)DivyanshJ22017-11-08

In the step 2

My pi is RasPi 3 Model B

PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"

NAME="Raspbian GNU/Linux"


VERSION="8 (jessie)"



DivyanshJ2 (author)marda572017-11-08

Version 8 of Jessi is released on April 2015 as stated on Internet. You should try updating the pi and then try again. This should solve the problem. :D

DivyanshJ2 (author)marda572017-11-08

I can't see the image clearly because of the compression. But do you mind repeating the step 2 and downloading the .pyc file again because it might haven't downloaded properly or you might haven't unzipped the file. Please repeat the step and very sorry but can you send me the image again on my email I can't see it. My email address is Really sorry for the inconvenience.

jduf (author)2017-11-03

Is it evolutive ?

How can I add new controls/commands on the interface and the server ?

Seems that solutions based on nodered are more customizable.

DivyanshJ2 (author)jduf2017-11-03

Unfortunately not right now, but I am currently working on a new app with support of my upcoming project. As I am right now in high school please expect at least a month on the update. But if you require any kind of assistance like figuring the code or about the app please share.

fatsquirel (author)2017-11-02

hello .

there's a typo in the line:

"in the directory go between where it is written ""f1"" and exit 0 and type"

DivyanshJ2 (author)fatsquirel2017-11-02

sorry for the inconvienience. Thanks for correcting me it is "fi"

PoojaJ18 (author)2017-11-02

Oh Wow....its greattt....sumthng interesting and easy to use home automation server...

Swansong (author)2017-11-01

That would be really convenient to have set up :)

About This Instructable




Bio: I am a high school student interested in coding and electronics. I am currently trying to teach myself python. As I am in high school ... More »
More by DivyanshJ2:Raspberry Pi Home Automation
Add instructable to: