Introduction: Raspberry Pi Home Automation Server
The raspberry pi is an amazing little computer for the price. Now that you have a raspberry pi lets put it to work!
A web-server does not require much computing power or disk space. With a little php and occasional python we can tailor the apache web-server to keep track of an whole array of sensors.
Total Cost $54 (plus 2x5V power supplies):
Raspberry pi model B $25: http://www.newark.com/raspberry-pi/raspberry-modb-512m/raspberry-pi-model-b-board/dp/51Y5087?ost=51Y5087
You will need a free gmail account in order to send texts or emails when the sensors trigger. Obtain your account from www.gmail.com
Win32DiskImager should be installed on a pc (to write the .img file to a 4gig or larger sd card).
Putty or an equivalent ssh terminal program should be installed on a pc in your network.
A compatible sensor should be ordered from tindie like:
Note: To program a sensor follow this instructable: https://www.instructables.com/id/ProgramESP8266/
Step 1: Theory
- The raspberry pi server is connected directly to the router or through a usb wifi adapter.
- The router will assign an ip address to the server via dhcp
- When the raspberry pi server starts it will create an apache server located at:
http://192.168.0.X/Paulware where 192.168.0.X is its address assigned by the router
- When the raspberry pi server starts it runs /etc/rc.local which runs a python .py program:udpBroadcast.py which sends a message every 1 minute, broadcasting its udp address on the local network. This broadcast will be read by each sensor and that is how the sensors determine where to send their information to.
You can determine the address assigned by the router by looking at your router page, or by connecting the raspberry pi hdmi socket to a home television, attaching keyboard and mouse to pi and typing the command: ifconfig at the line terminal.
Step 2: Configure the Server
In order to send text or emails when the sensor triggers you need to enter the gmail username and password.
To configure your gmail username and password:
- With a browser, open http://192.168.0.X/Paulware/configure.php where 192.168.0.X is assigned by your router
- Enter your gmail username and password
Note: Do not use the "@gmail.com" in the username.
Step 3: Configure Gmail So That the Raspberry Pi Will Be Able to Send Emails.
As explained here: https://support.google.com/accounts/answer/6010255, gmail needs to be configured to allow a python program to send email.
- Log in to your gmail account (chrome is the recommended browser if you have it installed)
- Go to this page: https://www.google.com/settings/security/lesssecureapps
- Select the "Turn on" radio button
Step 4: Add a Sensor to the System
- With a browser, open http://192.168.0.X/Paulware where 192.168.0.X is assigned by your router
- Add the MAC address for sensor you purchased from tindie, and you have already programmed using this instructable: https://www.instructables.com/id/ProgramESP8266/
- Enter the type of the sensor and the action you want to occur when the sensor triggers.
- Test the action to check if the correct action will occur when the sensor triggers.
Step 5: To Make Your Home Server Accessible From the Outside Internet
Go to your router configuration page (which is different for different routers)
Port forward port 80 from 192.16.0.X (assigned by router).
Note: This is an optional step. The server will be able to send emails/texts without this step.
Step 6: Using the Wifi Dongle
If you would rather use a wifi dongle than plug directly into the router, you can follow the ada fruit tutorial on wifi setup. https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis
I usually use putty to get the line terminal they mention in step 2.
Step 7: Make Your Own Sensor.
You can use the init.lua without change.
The sensor.lua should be modified to change the SSID and password to match your local network, and the function readSensor should be modified to read your particular sensor.
The senor.lua file have the sensor wait until the raspberry pi's address is broadcast over udp. When this address is received the sensor will then send its value to the raspberry pi server.
Once your sensor is working, post it at http://www.esp8266automation.com/ for sale and general review by others.