Raspberry Pi Home Automation with Google Assistant integration — Part 1 (Software)

Sidhant Panda
2 min readNov 2, 2018

--

Got a Pi collecting dust at home? Let’s get some lights and fans automated! I say lights and fans, but you can automate any electrical switch in your home.

First, we’ll go through all the software requirements

1. Install NodeJS

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
$ sudo apt-get install nodejs -y

2. Clone backend

We’ll install pm2 to manage our backend server

$ npm install pm2 -g
$ git clone git@github.com:sidhantpanda/raspberry-pi-home-backend.git
$ cd raspberry-pi-home-backend && npm install
$ pm2 start bin/www

3. Clone frontend

$ git clone git@github.com:sidhantpanda/raspberry-pi-home-frontend.git
$ cd raspberry-pi-home-frontend
$ npm install && npm build

4. Install and configure nginx

We’ll use nginx to expose our frontend and use it as a reverse proxy for our backend service

$ sudo apt-get install nginx
$ sudo vim /etc/nginx/sites-enabled/default

Now, look for the root for the web server and edit it to the path of the build directory of the frontend repo. Add `proxy_pass` for all the /api/* routes to the web server to the NodeJs process being run by pm2:

--  root /var/www/html;
++ root /path/to/repo/build;
++ location /api/ {
++ proxy_pass http://localhost:5000;
++ }

location / {
...

Now, save the file, quit vim and restart nginx

$ sudo service nginx restart

4. Run on boot

To make the service restart automatically on boot, edit the `/etc/rc.local` file

$ sudo vim /etc/rc.local

Just add the following to the end of the file just before exit 0:

...pm2 start /path/to/backend/repo/bin/www
/etc/init.d/nginx start
exit 0

That’s it!

Let’s move to the hardware tutorial.

--

--