Introduction: 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
- 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
- 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
- Jumper Wires :- To connect the relay to the Raspberry Pi. Female to Female Jumper Cables
- 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
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 www.ioslinks.com/mypi/server.zip
pi@raspberry :~ $ ls (check the above server.zip file should be added in the directories)
pi@raspberry :~ $ unzip server.zip (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
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
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.
Enjoy!!

Participated in the
Wireless Contest

Participated in the
Raspberry Pi Contest 2017
32 Comments
7 months ago
RuntimeError: Bad magic number in .pyc file
HELP!!!!Question 2 years ago on Step 1
I have 4 channel relay module board.
Please provide the code for it
Question 2 years ago
for more butons in app mypi
Question 2 years ago on Step 5
for more butons in app
3 years ago
It worked for me...
Question 3 years ago on Step 5
I made It!!
please help me to Make online when I'm out my network
tanks
Question 3 years ago on Step 3
I got the "authentication failed, wrong password" error alot and if I restart Pi and app it works....Now have another problem, after connecting, it will not send commands to Pi - I get an error "you are using old version of MyPi server, please update to the latest version"
the link above only has this one version
4 years ago
When I run python3 mypi_server.pyc
I get the error RuntimeError: Bad magic number in .pyc file
4 years ago
Hi sir does the MyPi Application runnable for Android OS?
Reply 4 years ago
Yes
Reply 4 years ago
sir does the controller Mypi application need an internet or just a network of a router?
Reply 4 years ago
It works on just the network of the router. Through the app you connect to the pi's using its ip address and so it can just work of the router's network.
Reply 4 years ago
can i control the relay even if i'm outside of the house? for example when i'm in school can i turn on/off the relay?
Reply 4 years ago
That is not integrated right now but you can look forward to that in 2-3 days I am going to update this instructable and add a few more functions like that. You can follow my channel or just check back in few days to see the update.
Reply 4 years ago
im gonna wait with the update controller Mypi sir by connecting to wifi internet to be able to turn on/off relay even you are not home...
Reply 4 years ago
That will be great...
Reply 4 years ago
Can you message me sir? if it is already update for the wifi connection of the controller
Mypi
Reply 4 years ago
Final few things and trial is left. Max it will take 2 days and you will see the existing instructable updates.
Reply 4 years ago
thank you sir :)
Reply 4 years ago
Hi sir what's the update of your Mypi application?