sources/tech/20201207 Set up Home Assistant to manage your open source smart home.md
9.1 KiB
Set up Home Assistant to manage your open source smart home
Learn how to install and configure Home Assistant in the fourth article in this series on home automation.
In the first article in this series, I introduced Home Assistant and why you might be interested in it. In short, Home Assistant is an automation hub for some of the most common smart devices on the market today. It enables centralized coordination of disparate hardware. By using it, you no longer have to choose suboptimal tech from a single vendor to manage your smart home from a single app. It also means you will no longer struggle with a hundred different apps that all function slightly differently to manage all your devices. One program to rule them all… or at least that's the dream.
In the second and third articles, I looked at some of the decisions to make when developing home automation, namely local vs. cloud control, and whether to choose Zigbee, Z-Wave, or WiFi, just to hit the high points. This fourth article will be much more hands-on than the previous ones by walking you through setting up a virtual machine (VM) with the Home Assistant-provided image.
Set up the VM
I won't cover all of the methods available for installing Home Assistant (HA). I run HA in a virtualized environment, and the official installation page provides VMDK, VHDX, VDI, QCOW2, and OVA downloads. I have a libvirt-based homelab, so I chose the QCOW2 image.
Regardless of which hypervisor you use, you need to make sure that the boot type is set to UEFI instead of the traditional BIOS. In Arch Linux or Fedora, you need to install the package edk2-ovmf
to have the option available in Virt-Manager. In Ubuntu, the package is called ovmf
. After the package is installed, restart libvirt.
When you create your VM, select the HA image you downloaded. You can accept the default options that Virt-Manager selects until the confirmation screen. Make sure you check the box that says Customize configuration before install.
(Steve Ovens, CC BY-SA 4.0)
When you do this, make sure to change the firmware to UEFI:
(Steve Ovens, CC BY-SA 4.0)
Important note: You cannot change the firmware type after the VM has been created. If you choose BIOS, the VM will not boot!
If you need to expand the amount of disk available to HA's VM, shut down the VM and run:
qemu-img resize hassos_ova-4.13.qcow2 +40G
Upon boot, the new space will be automatically allocated to the appropriate partitions.
The first boot can take a significant amount of time, as HA pulls down the latest versions of software from the internet and prepares them for initial launch and configuration. To be on the safe side, walk away for 10 minutes or so before attempting to pull up the webpage for the first time. In my experience, it often requires less than five minutes, but 10 minutes is a good amount of time for the system to spin up and settle.
First-time setup
You should now be able to access the HA interface by pointing a browser to http://homeassistant.local:8123
. However, this relies on your router to support automatic DNS registration. You can also access the webpage via its IP. In my case, that's http://192.168.122.90:8123
.
(Steve Ovens, CC BY-SA 4.0)
Enter your username and password for the administrative HA account. Then it will prompt you to select a location.
(Steve Ovens, CC BY-SA 4.0)
As you can see, your location is used for "sun-based automations." This means it uses your longitude and latitude to determine sunrise and sunset times and your time zone. If, for example, you have an automation that says, "turn on desk light 20 minutes before sunrise and turn off an hour after sunrise," HA uses this location information to determine what time to activate the lights. Unfortunately, you have to use the graphical map to set this information, and it may not function properly without an active internet connection.
After you have completed this, you will see a confirmation screen.
(Steve Ovens, CC BY-SA 4.0)
Rather than setting up devices here, I prefer to click Finish and use the full UI to configure my devices. This is optional, of course. This screen may prepopulate some integrations, depending upon whether HA has automatically discovered devices on your network.
Initial user settings
After you finish the initial configuration, you will see the Overview page. HA's default interface is called Lovelace. It is a powerful YAML-described interface. This means that even if you can't choose certain user interface (UI) elements in the graphic interface, you can open the built-in YAML editor and add them yourself.
Lovelace's default view has a single card that displays the weather based on the location you entered. Click your username (stratus in this example) in the bottom-left panel.
(Steve Ovens, CC BY-SA 4.0)
This brings up another screen with several options. Find Advanced Mode and make sure it is toggled on.
(Steve Ovens, CC BY-SA 4.0)
This setting is toggled per user, so if you have other administrative users, only this one (e.g., stratus) will have advanced settings turned on. There are quite a few options exposed when toggling Advanced Mode, but the one you want is the ability to run a syntax check against the HA configuration files. To see this in action, navigate to Server Controls by clicking on the Configuration option in the bottom-left panel, and then click on Server Controls.
(Steve Ovens, CC BY-SA 4.0)
Clicking on the Check Configuration button will check all the HA configuration files for syntax errors. If it finds no errors, you will see a message in green that says Configuration Valid!
(Steve Ovens, CC BY-SA 4.0)
Looking ahead
Now that HA is set up and configured, you are ready to start really digging into it. In future articles, I will explain how to:
- Install and configure add-ons
- Create snapshots and run HA updates
- Install the Home Assistant Community Store (HACS)
- Configure entities via the built-in options
- Work with MQTT
- Create automation flows with NodeRed
And much more. If there's something else you want to learn, please share it in the comments. While I am not a Home Assistant expert, I will do my best to answer your questions about it.
via: https://opensource.com/article/20/12/home-assistant
作者:Steve Ovens 选题:lujun9972 译者:译者ID 校对:校对者ID