Some months ago, I started a project for fun, called Open Home Automation. The goal is to have a free (as in free speech), open-source home automation system. The list of functionalities is not yet fixed and I do no know exactly what I am going to do with it.
As for now, it provides the following functionalities:
- Monitoring from your Android Cell-Phone through a dedicated application
- Sending alert through e-mail
The following functionalities are under development:
- Logs of events
- Support of alarm
- Detection of door/window opening
Where to get it?
For running all that, you will need:
- An reliable internet connection.
- A Raspberry-PI connected through the internet with raspbian. You can get yours on adafruit.
- A webcam that is compliant with motion. I am using the Logitech C270.
- An android-compatible phone. I used the Virgin Mobile HTV EVO3D and the Samsung Galaxy S3. Works well on both.
- A brain and some time. Most difficult thing to find.
We will assume your raspberry-pi is running raspbian and the internet connection is working.
Download the source
Before doing anything, you need to checkout the sources from the git repository. Make sure git is installed on your raspberry go invoking the following command:
apt-get install git-core
Then, import the repository in your home directory:
Installing required software
You need to install the software dependencies: motion, lighttpd and a mail server. For the mail server, I am using postfix, you can use another one (e.g. exim).
apt-get install postfix lighttpd motion
We let you configure the mail server, the main objective is that you are able to send an e-mail through your machine. You can try the following command, it should send you an e-mail.
echo "Hello from my raspberry" | mail -s "test raspberry" email@example.com
If that works, it means that your mail server is correctly configured and you can go ahead!
Configuring the system
You need to create a configuration file in /etc/automated.conf.
The configuration file looks that this:
MOTION_STREAM_IP=127.0.0.1 MOTION_STREAM_PORT=8081 AUTOMATED_PORT=1234 AUTOMATED_ADDR=127.0.0.1 ENABLE_EMAIL=1 RECIPIENTS="firstname.lastname@example.org email@example.com" SYSTEM_NAME="my house" ENABLE_LOGGING=1 LOGFILE=/var/log/automated.log MAX_REPORTED_EVENTS=15
So, let’s describe each configuration variable:
- MOTION_STREAM_IP – the IP of the system which is running motion. Likely, this is localhost
- MOTION_STREAM_PORT – the port number to connect to the motion stream. Just specify what you put in the motion configuration for the webcam stream.
- AUTOMATED_PORT – the port for the daemon
- AUTOMATED_ADDR – the address for the daemon
- ENABLE_EMAIL – enable e-mail configuration (or not)
- RECIPIENTS – recipients for the email notification. Each different recipient is separated with a space.
- SYSTEM_NAME – identifier of your system. this will be added to the notification e-mails.
- ENABLE_LOGGING – log events
- LOGFILE – file where events are recorded
- MAX_REPORTED_EVENTS – the number of max logged events reported to the mobile app
You will then need to configure lighttpd in order to relay the incoming request to the local daemon.
To do so, you need to first activate mod_cgi and makes sure the server requires a login.
For that, edit the file /etc/lighttpd/conf-enabled/05-auth.conf and add the following lines:
auth.require = ( "/httpcontrol" => ( "method" => "basic", "realm" => "Restricted Area", "require" => "user=julien" ) )
Finally, you need to make a symbolik link between the httpcontrol from the sources directory to /var/www/
ln -s $HOME/linux-automation/httpcontrol
The configuration of motion is in the file /etc/motion/motion.conf. Likely, you will need to add/update the following configuration directives:
- webcam_port – you can put whatever you want but 8081 is the value we use by default in our default configuration file
- on_picture_save use the following value: /path/to/sources/config/motion/motion-detected-with-picture.sh %f
- on_motion_detected – put the following value /path/to/sources/config/motion/motion-detected.sh
You can for sure tweak the other options, this will not have a significant impact on the software.
Starting the daemon
Testing the http server
Testing the mobile application
Automating system start
You might want to automate the system restart in case it crashes or have any issue. To do so, you can automate that using a cronjob that will check if the system is running and restart it if needed.
On my side, I am doing that with a cronjab added to the root user. To add the cron, modify the crontab by invoking the following command
Then, add the following line to check every 5 minutes that the system is activated
*/5 * * * * if [ $(ps ax|grep automated |grep -v grep|wc -l) -eq 0 ]; then /location/to/sources/automation/config/startup-script start ; fi
Frequently Asked Question
Why the picture takes some time to come?
In fact, I am using a bad crappy hack to get the picture from the motion stream. So, sometimes, retrieving the picture from the stream just fails and nothing is then sent to the mobile app. One definitive solution would be to remove the dependency to motion and write our own acquisition data and motion detection routines.
Is this program free
It requires efforts – setting up, etc. But there are no financial fees, the more costly thing is to have a brain and be able to read the installation instructions. Also, an expertise in UNIX or Linux systems might help as well.