As a part of a cloud computing practicum, a team of six came together to build a home automation process using Home Assistant (HA) for three specific use cases: locks, curtains, and ventilation. We started testing with lights, so we kept those scripts in the repo for fun.
Our four primary objectives:
- Create a HA server deployed via docker in the cloud.
- Implement smart curtains to use with blackout curtains.
- Devise a solution for a smart central HVAC system to control airflow to different zones.
- Integrate with Google so client can use Google Assistant to invoke voice command, including running HA routines (e.g. "Go to bed," which checks front state and locks if needed, does nothing if locked).
Use our work as a foundation to build out your own home automation by adding additional use cases. At this point, in the world of home automation IoT, the sky is the limit: lights, locks, solar panels, televisions, alarms, cameras, vents, curtains, blinds, switches, sprinklers, so on and so forth.
Though most configuration sources found online highly recommend running HA on a local server (Raspberry Pi; take a look at this thread for an explanation as to why), our assignment was to deploy to a cloud service. As such, our CI/CD implementation is optimized for the cloud and automatically deploys repository changes to our AWS EC2 instance.
- Required Equipment
- Raspberry Pi - running Ubunutu or similar
- Kasa Smart Strip Plug
- Motorized Damper
- Yale Smart Lock
- ZemiSmart Curtain Motor with Track
- Required Accounts
- AWS Cloud Services
- tplink Kasa (mobile application account)
- Tuya Mobile App
- Tuya Iot Platform
- Google Assistant
- Duck DNS
- We also reccomend downloading
[this sheet](https://github.com/brandondombrowsky/BastCastle/blob/9c0a1b64dc4dcfcc75e6f66b2d07ce68fc3129b3/clipboard.txt)
for storing all information you will be copying and/or pasting in this process, and inputing the following information:<pi IP>
<network IP>
- Log into AWS Dashboard. Select EC2 from the services menu and click launch new instance.
- Select and record
<instance name>
. - Select the 'My AMIs' tab, click 'Shared With Me' and choose 'HA_AwsUbuntuDocker'.
- Create and save new pem key, noting
<key name>
and<key location>
. - Create new security group, record
<sg name>
. - Keeping the first security rule, add a second rule allowing custom TCP access to port :8123 from anywhere.
- Launch instance. On the following page, click 'connect to instance.' On this page, record the listed public IP as
<HA IP>
.
- Open the terminal locally. Navigate to the folder containing your key.
- Change the file permissions for the key using command
sudo chmod 600 <key name>
. - Access the EC2's terminal with command
ssh -i
ubuntu@`. - Run the following 3 commands in succession:
sudo apt update
sudo apt upgrade
sudo reboot
- Open your favorite web browser and navigate to
<HA IP>
:8123. You should be greeted by the Home Assistant login page. - Login using the credentials below: - user: admin - password: homeautomation
- Change the login information to your liking, recording
<HA user>
&<HA password>
.
For each smart device it is best to refer to the manufacturer's installation process, as most include proprietary apps to connect to your local network. When connecting the Kasa smart plugs, you will need to record the '' for each plug. To do this, find the device MAC adddress as listed in the Kasa app under the device info section of device settings.
From there, use your router to cross reference the MAC address with the associated IP.
- Open your router settings and set port forwarding. This process will vary by router, but these are the important settings:
- External port :58133
- Internal port :58133
- Internal IP:
<pi IP>
- Blue: local server (Pi) IP address
- Red: Wireguard tunnel port
- Open terminal and navigate to location of the pem key.
- Access the EC2's terminal with command
ssh -i <key name> ubuntu@<HA IP>
. - Install Wireguard using the command
sudo apt install wireguard
. - Create private key by running
wg genkey > wg-aws.key
. - Create public key by running
wg pubkey < wg-aws.key > wg-aws.pub
. - View private key by running
cat wg-aws.key
.- Record as
<aws private key>
- Record as
- View public key by running
cat wg-aws.pub
.- Record as
<aws public key>
- Record as
- Open a new terminal window locally. Do not close the terminal window connected to the aws instance.
Inbound: Outbound: All traffic
- In the new terminal window, connect to the local Pi device using the command
ssh <pi username>@<pi local IP>
and entering the device password. - Install Wireguard using the command
sudo apt install wireguard
. - Create private key by running
wg genkey > wg-pi.key
. - Create public key by running
wg pubkey < wg-pi.key > wg-pi.pub
. - View private key by running
cat wg-pi.key
.
- Record as
<pi private key>
- View public key by running
cat wg-pi.pub
.
- Record as
<pi public key>
- On your local machine, scroll to the section labelled towards the bottom of the clipboard file.
- Replace ,
<pi public key>
,<network IP>
, and<pi IP>
with the corresponding recorded information. For any smartplugs used, add the /32 to the allowedIPs list at the bottom (with each IP separated by a comma). - In your EC2 instance terminal, use your preferred text editor to create and edit a new Wireguard configuration file. Simply insert your favorite text editor in the place of 'vim' below.
sudo vim /etc/wireguard/HA-tunnel.conf
- Copy your edited
<ec2config>
text into the new document and save.
- On your local machine, scroll to the section labelled
<pi config>
towards the bottom of the clipboard file. - Replace
<pi private key>
and<ec2 public key>
with the corresponding recorded information. - In your Pi terminal, use your preferred text editor to create and edit a new Wireguard configuration file. Simply insert your favorite text editor in the place of 'vim' below.
sudo vim /etc/wireguard/HA-tunnel.conf
- Copy your edited
<pi config>
text into the new document and save.
- In your Pi terminal, start the tunnel with the following command:
sudo wg-quick up HA-tunnel
- In your EC2 instance terminal, start the tunnel with the following command:
sudo wg-quick up HA-tunnel
- In your EC2 instance terminal, ping your Raspberry Pi using the following command:
ping <pi IP>
- After a few seconds, press ctrl + c.
- If packets have "no packets have successfully transmitted," check the troubleshooting section.
- Navigate to Home Assistant dashboard at
<HA IP>
:8123. - Login using
<HA user>
&<HA password>
. - In the dashboard click Settings -> Devices and Integrations.
- Click "Add Integration."
- Type 'kasa' into the search bar and select TP-Link Kasa Smart.
- Paste
<device id>
of your smart plug and click submit. - Repeat 4-6 times for each additional plug.
If adding new devices after 1st install, you will also need to add their local IPs to the EC2 instance's wireguard config file. Follow the steps from EC2 configuration, but instead of copying and pasting the whole document, simply add the device's local IP to the list of allowed IPs towards the bottom of the document.
- Log into Tuya IoT platform account. Select "Cloud" from left toolbar and click "Create Cloud Project" on the following screen.
- Fil in the Create Cloud Project form as follows:
Project Name: Home Assistant
Description: optional
Industry: Smart Home
Development Method: Smart Home
Data Center: Western America Data Center
- Click "Create" button. Skip the configuration wizard and click Authorize.
- Record
<Access ID>
,<Access Secret>
, and<Project Code>
- Navigate to the "Devices" tab. Select "Link Tuya App Account" and click "Add App Account." A barcode should appear.
- Open the Tuya App on your mobile device. Click the "Me" tab on the bottom navigation bar and the barcode scan button on the resulting page
- Scan the barcode from step 5. A dialoue box will replace the barcode. Set "Device Linking Method" to Automatic Linking and "Device Permission" to Read, write, and Manage. Press "OK"
- Wait a moment. When the product name appears listed under devices, you will now the process has been successful.
When the product name appears listed under devices, you will now the process has been successful.
!reference image](https://user-images.githubusercontent.com/73506948/225527622-cc278b72-25e9-4c3e-abe9-eaee2cf7786e.png)
- Navigate to Home Assistant dashboard at
<HA IP>
:8123. - Login using
<HA user>
&<HA password>
. - In the dashboard click Settings -> Devices and Integrations.
- Click "Add Integration."
- Type 'tuya' into the search bar and select Tuya.
- Paste
<Access ID>
and<Access Secret>
of your curtains as well as your Tuya Mobile App login credentials. Click submit. Be patient, registration may take up to a minute.
- Select the proper area for your curtains
Home Assistant is compatible with Google Home/Assistant. This can be configured both ways: HA can be integrated into GH/A so that HA scripts can be run from GH/A and HA can send command requests to GH/A. Unfortunately, the process has too many variables for a succinct walkthrough; instead take a look at how this process works and view helpful guidesin our wiki.
Home Assistant has some wonderful (and simple) settings for securing device access. Take a look at some of them here.
- Home - Documention, videos, and products and how they work.
- Wireguard VPN Setup - The nitty gritty of setting up your environment.