Hey guys, so this weekend I was looking for something new to deploy in my lab. I came across Home Assistant.
What is it?
Home Assistant is an open source automation platform for smart home enabled devices. It allows for multiple vendors “smart” devices to interoperate between each other using Home Assistant as a hub for that communication.
I wanted to be able to speak to my google assistant to turn on my PC and heater in my outside office. To do this I utilise my TP-Link smart plug and also Wake on LAN to wake my PC from shutdown using a magic packet.
Below are the steps I took to install and configure this setup.
Step 1: Deploy Home Assistant.
I utilise Docker in my network so I will deploy the ready made docker container by running the following command.
docker run -d --name="home-assistant" -v /path/to/your/config:/config -e "TZ=America/Los_Angeles" -p 8123:8123 homeassistant/home-assistant
Step 2: Configuring Smart Devices
To be able to control your smart devices you will need to configure Home Assistant to see your devices. To detect your smart plug and also be able to use WoL enter the following in the configuration.yaml which is located in the root of your Home Assistant install.
switch: - platform: wake_on_lan mac_address: "XX-XX-XX-XX-XX-XX" name: Gaming PC - platform: tplink host: XXX.XXX.XXX.XXX name: Smart Plug
Once this is entered you will be able to see the following on your dashboard under switches.
From there you will be able to toggle your smart plug on and off and also turn your WoL enabled PC to switch on.
To integrate your Home Assistant setup with IFTTT and enable voice commands the following steps will need to be followed.
Step 1: Configured External Access
For IFTTT to communicate with HA you will need to be able to access its API externally from your network. To do this I originally intended to utilise by NGINX reverse proxy but due to the way my reverse proxy is configured to structure its domains it causes problems. To rectify this I had to port forward the exposed port of the HA docker container (not ideal but w/e).
To secure the API we can set a password in the configuration.yaml, to do this include api_password: XXXXX in the config. This will then prompt you to login.
Step 2: Creating the Script
To get the smart plug and WoL features working together we have to create a script to trigger both actions. To do this we do the following.
This script will reference the id of the switches for the smart plug and also the WoL switch.
Step 3: Configuring IFTTT
To setup IFTTT for Google Assistant integration we will have to create a Google Assistant applet which triggers a web request. The below screenshot shows the setup I use to reference the script we created in the previous step.
To get the id of the script you can navigate to HA > Configuration > Scripts > [Script you created] this will then shows the script id in your web browsers URL box. This can then be added to the body of the HTTP POST request.
To test your setup you can either speak to your Google Assistant using the trigger word you set or type it.
If the applet is correctly working you should see the switches become active on your dashboard. If not your will receive a toast stating an error.
Any questions let me know below!