Raspberry Pi Home Automation with Google Assistant integration — Part 1 (Software)
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
- Install NodeJS $ curl -sL deb.nodesource.com/setup_8.x | sudo bash - $ sudo apt-get install nodejs -y
- 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
- Clone frontend
$ git clone git@github.com:sidhantpanda/raspberry-pi-home-frontend.git $ cd raspberry-pi-home-frontend $ npm install && npm build
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
- 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!
Part 2: Raspberry Pi Home Automation with Google Assistant integration — Part 2 (Hardware)