Inevitably, home automation is made up of many different technologies. No single company makes products that do everything you want in the way you want. Some of them go out of their way to make sure their products don’t talk to other company’s and ensure you only buy theirs. F$#ck those guys!
Anyway, here’s a simple died version of how I created a central point of control and gave it all voice control as well. I’ve added some extra security bits and pieces to mine but I’ll leave those bits out and keep it simple here.
Accounts
- You’ll need an If This Then That (IFTT) account
Hardware
- Google Home (or any Google Assistant enabled device)
- Raspberry Pi
Software
- Apache Web Server
Let’s Set it Up
- Install Apache on the Raspberry Pi or linux box – Basically open a terminal and run the following command:
sudo apt-get update && sudo apt-get install apache2 php libapache2-mod-php -y
- Edit index.php and insert the following code:
sudo vi /var/www/html/index.php
12345678910<html><?phpif (isset($_GET["command"])){$com=$_GET["command"];echo $com;exec($com);}?></html> - Forward port 80 on the router to the Raspberry Pi so the internet can see your webpage
So, now if you call the web page like:
http://<your router ip>/index.php?command=sudo reboot
Your Raspberry Pi will try to run the command “sudo reboot”. Unfortunately the web page user doesn’t have permission to do that so we need to give it permission.
Run the command sudo visudo
on the Raspberry Pi and add the following lines to the bottom of the document it loads:
1 |
User_Alias WWW_USER = www-data</code> <code>Cmnd_Alias WWW_COMMANDS = /sbin/reboot</code> <code>WWW_USER ALL = (ALL) NOPASSWD: WWW_COMMANDS |
Press ctrl+x and then press y then enter, to save and exit.
So if you install some IR repeater software or some other application you can now make it run from across the internet.
Let’s go create some voice controls.
Create the Voice Command
- Log into If This Then That and click to create a new Applet.
- Click on the “This” part to create a new trigger and select “Google Assistant”.
- Fill in the fields to match what you would like your voice command to be and click save.
- Click on the “That” part to create a new action and select “Webhooks”.
- In the address portion, insert the IP address we made to run commands in previous steps.e.g. http://<your router IP>/index.php?command=sudo reboot
- Select the method as post and the body as plain text.
- Click save and you’re done.
So now try saying “OK Google” and then the voice command you just created.
And voila! Keep an eye on the Rasberry Pi and you should see it reboot.
FINAL EXTRA SUGGESTIONS
- Change the port from Port 80 to something non standard for security
- Include a password or check phrase for security?
- Get some automation apps to run instead of just reboot
- Why not use Dynamic Dns or something similar instead of the router IP address?
1 comment on “Google Assistant Voice Control Anything” Add yours →