Using IFTTT and Alexa Voice Service AVS on a RaspberryPi to control HomeAssistant

This is the next post in my multipost of using a Raspberry-Pi 3 as the center of my Home Automation world.

Firstly I set a Raspberry-Pi 3 up in headless mode, then installed Pi-Hole to block adverts at local DNS level, so saving you much needed bandwidth. Next, I installed Home-Assistant, and then Homebridge, which allowed me to use Siri to access my various bulbs in the house. Lastly I installed Amazon AVS but all it does is tell me the time, weather, flash forcast, todo lists etc.

Here’s the previous posts:

Using IFTTT
Now due to it’s limitation, I can’t simply say “Alexa, find my devices” to find the lights that I can control in my home. So I need IFTTT. If you’ve never used IFTTT then I strongly advice playing with it, I initially used it many years ago to copy images from the new posts on Reddit.com/r/eathporn and /r/spaceporn to my google drive, which then synced to a folder on my mac & pc, which gave me a new backdrop each and every day. I ended up with about 7GB of photo’s over a year or so which was pretty neat. Anyhow I digress.

I would highly recommend backing up your Pi’s SD card at this time so you can easily revert. Do this with some form of img making software, or just using the terminal in a mac.

So lets understand how this needs to work remembering that Alexa doesn’t allow anything local directly, so I need to use the cloud process of IFTTT to integrate it.

I want to be able to say “Alexa turn off the lights” or something to that affect. Alexa needs to process the command, then talk to IFTTT’s server, IFTTT hears “Turn off lights” and then needs to contact my RaspberryPi which is somewhere in the world and is connected to the internet via a dynamic ip (changes whenever my ISP wants it to), and my PI to realise that IFTTT is talking to HomeAssistant, then HomeAssistant to interpret that command and turn the lights off.

To be able to do this, I need to make my PI have direct access to the internet. This will mean I need to make sure my network is safe from intruders trying to get in. If you’re following this, you should make sure all your systems are firewalled, you understand risks, and you read up on your own router and understand the security involved. It wouldn’t hurt for you to google how to protect your network whilst using port forwarding. Make sure you have a strong HomeAssistant API password and haven’t left it at the default of password. If you change it at this point and also have homebridge installed, remember to update it in homebridge’s config.json file.

I had to uninstall the PiHole whilst doing this, I found too many conflicts and it kept dropping out, your mileage may vary, but I’d uninstall it for the time being as if you keep it you’ll have to alter lighttp’s port, plus you’re asking quite a lot of your Pi at this point. pihole uninstall uninstall lighttp but you might as well leave the other dependancies.

I also installed UFW (uncomplicated firewall) on my Pi. When you do this, have a read of the documentation on how to allow ports, for instance, the first time I enabled it, I hadn’t allowed VNC or SSH ports, so couldn’t connect to my Pi, I had to plug in a monitor and keyboard to turn off UFW. I seriously facepalmed at such a stupid thing to have done.

So to install:
sudo apt-get install ufw
sudo ufw allow 22 for SSH, 8123 HASS, 5900/5901/5902 VNC. You get the idea.
sudo ufw enable to start the firewall. Here’s a list of ports.

Now we need to setup SSL on the Pi for HA access, this is rather long winded, but it’s well written here and really well here.

Once this has been installed correctly you can access your Pi from the outside world. This is handy when using the IOS app for HomeAssistant, or just the website address like http://pukit.duckdns.org:8123.

This may take you a few goes to get going, don’t forget to allow any ports you need to through your UFW firewall or if in trouble, sudo ufw disable for a short time.

Now the fun begins, make an account on IFTTT and lets make a new applet. Lets link our Amazon Alexa to IFTTT, click top right drop down by your username and click services:

Click through, enter your Amazon account details and you’ll be set to use your Alexa with IFTTT, now time to make some Applets.

Click top right, drop down by your username and new applet, you’ll be presented with this:

Type Alexa and click on the logo:

Click first option, say specific phrase and type in the phrase you want to use, I’m using goodnight:

Click next, then on that:

Search for maker:

Now we have to enter some stuff for IFTTT to talk to our HA install. The very clever guys over at HomeAssistant have built in a REST API system into your HA install, so if you send commands via the URL it does stuff, now neat is that!

Here’s my example. Replace the with your HA config API password and the pukit.duckdns.org with your url address, you may need to change the group you use, but i’m grouping all the lights to turn off at the goodnight command:

Now with lights on, you should be able to say, “Alexa, trigger goodnight” to turn off your lights! I’ve also setup triggers for different colour moods and various others, it’s great. Now I can use Alexa for my flash forcast of news, weather, operate alarms, timers, todo lists, and operate the household lights.

Leave a Reply