Integrating Home Assistant with Adafruit IO Created by Brent Rubell
Total Page:16
File Type:pdf, Size:1020Kb
Integrating Home Assistant with Adafruit IO Created by Brent Rubell Last updated on 2020-01-23 03:42:14 PM UTC Overview Home Assistant (https://adafru.it/DQw) is an open source home automation software which tracks the state of the smart-devices in your home so you don't have to. It easily integrates with most smart-devices (Google Cast, Philips Hue, Nest, Sonos, etc) and even interfaces with smart-assistants like Alexa or Google Assistant. Adafruit sells a lot of different types of sensors. Following this guide will let you quickly connect them to Home Assistant using an Adafruit Feather. We're going to set up an Adafruit Feather ESP8266 with a BME280 sensor to create a temperature, pressure, and humidity logging node. Then we'll install, set up, and configure Home Assistant on a Raspberry Pi. We'll configure the Feather to broadcast its sensor data to both Home Assistant and Adafruit IO (https://adafru.it/eIC) using ESPHomeYAML (https://adafru.it/DQx). While Home Assistant (https://adafru.it/DQw) is fantastic at displaying data in real-time, you might want to manipulate and log the data. We'll be using Adafruit IO (https://adafru.it/eIC) to perform real-time and long-term logging for visualization of data, and export the data from sensor feeds. Parts © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 3 of 33 Assembled Adafruit Feather HUZZAH with ESP8266 With Headers $18.95 IN STOCK Add To Cart Note: While you can run HassOS on a Pi Zero W, we do not suggest using one with this guide. The process of flashing firmware from a Pi Zero W is difficult. Compiling and uploading the Feather's firmware from a Pi Zero W takes significantly more time than a Pi 3B+. Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM OUT OF STOCK Out Of Stock Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor $19.95 IN STOCK Add To Cart Materials You'll need the items below for this project. If you do not have them already, grab them from the Adafruit Store: 1 x Switching Power Supply with MicroUSB 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable Add To Cart © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 4 of 33 1 x Micro USB Cable USB cable - USB A to Micro-B - 3 foot long Add To Cart 1 x Breadboard Half-size breadboard Add To Cart 1 x Wire Bundle Breadboarding wire bundle Add To Cart © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 5 of 33 Feather Wiring Make the following connections between the Feather Huzzah ESP8266 and the BME280: Feather 3V to BME280 VIN Feather GND to BME280 GND Feather SCL to BME280 SCK Feather SDA to BME280 SDI You may also want to connect a LiPo battery to the JST connector on the Feather Huzzah for wire-free logging. This one is ideal for Feathers: Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh OUT OF STOCK Out Of Stock © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 6 of 33 Adafruit IO Setup If you do not already have an Adafruit IO account set up, head over to io.adafruit.com (https://adafru.it/fH9) to link your Adafruit.com account to Adafruit IO. Navigate to the feeds page (https://adafru.it/mxC) on Adafruit IO. Then click Actions -> Create New Feed, and name this feed humidity. If you do not already know how to create a feed, head over to Adafruit IO Basics: Feeds (https://adafru.it/ioA). Then, create a temperature and pressure feed for the BME280's temperature and pressure sensors. Also, create an additional feed named status. When your Feather turns on or off, it'll broadcast its connection status to this feed. We're also going to need our Adafruit IO username and secret API key. Navigate to your profile and click the View AIO Key button to retrieve them. Write them down in a safe place, we'll need them for later. © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 7 of 33 With Adafruit IO set up, we'll move on to installing HassOS © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 8 of 33 Installing HassOS on Raspberry Pi We'll be installing Home Assistant locally on a Raspberry Pi using Hass.io (https://adafru.it/DQy), an All-in-One image which turns your Pi into a home assistant hub. The process of installing and configuring HassOS takes a while. Luckily, you only have to do it once. First, download the latest Hass.io image for your device from the home assistant downloads page. https://adafru.it/DQz https://adafru.it/DQz Then, unzip the .img.gz file. You should now have a .img file. Burn the OS image to a fresh SD card (Home Assistant's website suggests a 32GB SD card or larger). If you do not know how to install an OS onto a SD card for the Raspberry Pi, follow this page and come back when you're done (https://adafru.it/DQA). WiFi Configuration If you want to connect your Pi over WiFi, you'll need to configure Hass first. HassOS uses NetworkManager (https://adafru.it/DQB) to control the host network and defaults to ethernet. HassOS uses a USB Drive to load configuration files like WiFi onto the Pi. The capacity of the stick does not matter - we'll be adding one file to the drive. We'll be overwriting the contents of the USB Drive, so back up the contents of the drive before you proceed further. Plug the USB drive into your computer and reformat it with the following settings: Rename the drive to CONFIG Format the drive as MS-DOS (FAT32) Once reformatted, make a folder on the drive named network. © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 9 of 33 Then, create a new file called my-network inside the network folder we just created. Copy and paste the following into the file: [connection] id=hassos-network uuid=72111c67-4a5d-4d5c-925e-f8ee26efb3c3 type=802-11-wireless [802-11-wireless] mode=infrastructure ssid=MY_SSID # Uncomment below if your SSID is not broadcasted #hidden=true [802-11-wireless-security] auth-alg=open key-mgmt=wpa-psk psk=MY_WLAN_SECRET_KEY [ipv4] method=auto [ipv6] addr-gen-mode=stable-privacy method=auto In the configuration, change ssid to your network's ssid and change psk to the password of your network. If you don't want the IP address of your Pi to change on every bootup - visit this page to generate a UUID (https://adafru.it/Izf) and replace uuid in the configuration with the value from the website. Save the file to the USB drive and eject the drive from your computer. Safely eject the SD card from your computer at this time, too. HassOS Setup © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 10 of 33 Make sure the Pi is unplugged from power. Insert the SD card with HassOS into the Pi. Then, plug the USB drive into one of the Pi 3B+'s USB ports. Plug the Pi in to the power supply to power it on. Home Assistant will take from 15-20 minutes to load up on first boot. Grab a coffee and browse adafruit.com (https://adafru.it/dAR) for awhile. Once some time has passed, navigate to hassio.local:8123 (https://adafru.it/DQD). You'll eventually be greeted with a welcome screen. Set up a new user account (this is a local account on the Raspberry Pi) and click Create Account. After setup, you'll be directed to the Home Assistant login page. Remove the USB drive from the Raspberry Pi. © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 11 of 33 Next, we'll configure Home Assistant to be used with the Feather. © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 12 of 33 Configuring HassOS HassOS requires a bit of configuration before it's ready to be used with the Feather. From the Home Assistant sidebar, click on Hass.io. Home Assistant uses a YAML file named configuration.yaml (https://adafru.it/DQE) for each component used by Home Assistant. Previously, editing this file involved setting up SSH or SAMBA sharing on the Raspberry Pi. We're going to use an add-on which lets us edit this file right from our browser. From the Hass.io screen, click Add-on Store. Click Configurator. On the configurator page, click Install. The installation takes a while depending on your internet speed. Once the loading circle over installs disappears, the add-on is installed. © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 13 of 33 Next up, we need to install ESPHomeYAML. Since we're using a community project, ESPHomeYAML, we'll want to add the ESPHome repository to Hass.io. Under Repositories -> Add new repository by URL, add the ESPHome repository: https://github.com/OttoWinter/esphomeyaml (https://adafru.it/DQF) After the repository has been added, scroll down the page and click on esphomeyaml. From the esphomeyaml add-on page, click Install © Adafruit Industries https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant Page 14 of 33 Once installed, esphomeyaml should appear on the Hass.io dashboard page along with the configurator we installed earlier.