Contents
Preface
I started playing with smart home when Xiaomi first launched it. I should be considered one of the earliest people to play with smart home. I bought whatever was released (I replaced the regular switches of the lights at home with remote control ones, but they broke down in less than 3 years...), so there are a lot of Xiaomi smart and automated products at home:
Then we started to build the Apple ecosystem:
Although Xiaomi's smart phone can be directly added to Siri in Mi Home:
But it's not very convenient, and I've now switched to Siri and don't want to call Xiao Ai anymore, so how can I connect Xiaomi devices with the Apple ecosystem? At this time, I remembered Home Assistant (HA). I had no motivation to study it before, but now I finally found a reason to try it out.
Deploy Home Assistant
Installation options
Home Assistant provides four different installation modes (HA OS, HA container, HA Supervised, and HA Core). The official recommendation is to use HA OS.
Experienced users can also choose other methods according to their specific needs, for example, running HA in a virtual environment (such as Proxmox) or running HA on top of an existing operating system (such as Windows, macOS, Linux).
Note: While these installation styles can provide some flexibility for advanced users, they can also have some significant limitations. For example, add-ons and other important Home Assistant features may not be available:
Because I have a ready-made PVE environment, I deployed HA OS on PVE. You can choose the most suitable method according to your actual environment.
Create a virtual machine for Home Assistant OS
Download the latest version of Home Assistant OS qcow2 file suitable for installation on PVE from the following link:
https://github.com/home-assistant/operating-system/releases.
The latest version I downloaded was 12.2.rc1. After decompression, upload the qcow2 file to the /root directory of pve.
Note: This was when the backdoor of xz-utils was first exposed. Please note that the xz version should not be 5.6.0 or 5.6.1.
Create a new virtual machine on PVE and remember its VM id number (here I use 108 on my PVE as an example).
For the detailed process of creating a new virtual machine, please refer to my other article:OpenWrt soft router series PVE deployment OpenWrt (23.05.2) detailed tutorial,The only difference is that after the creation is completed, you need to change the BIOS type to OVMF (UEFI) in the hardware:
Import the downloaded qcow2 hard disk into the virtual machine:
qm importdisk 108 /root/haos_ova-12.2.rc1.qcow2 local-lvm
Add the imported disk:
To modify the boot order of a virtual machine:
Enable the virtual machine:
Startup completed:
The IP shown in the red box in the above picture is the IP address of Home Assistant OS, and the port is 8123.
Initialize Home Assistant
usehttp://homeassistant.local:8123
Log in to Home Assistant OS.
When you first access Home Assistant OS, it will do some preparation:
Note 1: This step would require the blessing of science or magic. If it is based on the normal domestic network environment, I don’t know how long I would have to wait. Anyway, I was stuck at .675 for a long time and got angry. I let HAOS’s IP address go directly to science, and then I skipped 675 and went on. The initialization was completed in less than 10 minutes.
Note 2: If the network environment where HAOS is deployed has an IPv6 public address and scientific methods, it is recommended not to assign an IPv6 address to HAOS. At this stage, IPv6 addresses are not very compatible with some scientific methods. If you want to use IPv6, it is recommended to disable AAAA records in DNS resolution.
After the preparation is completed, enter the welcome page:
Create username and password:
Home Assistant will then discover compatible devices on the same network segment:
After clicking Finish, you will enter the formal interface:
Key functions realized
Existing Xiaomi devices are configured in batches into Home Assistant
It is obviously unrealistic to configure one by one, so it is necessary to introduce the existing products of the same platform into HA in batches through the integration function. The following will take Xiaomi devices as an example to demonstrate how to use the "Xiaomi Miot Auto" plug-in to introduce Xiaomi devices in my home into HA in batches. Since there is no "Xiaomi Miot Auto" in the default integration of HA OS (in fact, it comes with another plug-in "Xiaomi Miio", but it keeps reporting errors when logging into the Xiaomi cloud platform during the configuration process. It is said that this is because the host accessing HA is not in the same LAN as HA. This is possible because my HA host is scientific, but my host accessing HA is not scientific, but I am too lazy to study it, so I just change it to Xiaomi Miot Auto), so we need to install "Xiaomi Miot Auto" first in the following way.
Go to "Configuration" - "Add-ons":
Click on "Add-on Store" in the red box in the lower right corner:
Install "Terminal&SSH" in the red box:
After the installation is complete, enter and click "Open WEB UI" in the red box in the lower right corner:
Install HACS (Home Assistant Community Store):
The command is as follows:
wget -O - https://get.hacs.vip | DOMAIN=xiaomi_miot bash -
Note: In fact, in HA deployed in other ways, this command is used to install HACS (a third-party application store). After the installation is complete, a HACS option should appear in the lower left menu of the HA page, similar to the following:
But I don't know why there is no response after I installed it, except for an additional "Xiaomi Miot Auto" integration. Is it related to the HA OS version I installed (or some functions of HACS are integrated into the latest version of the add-on store)? I don't understand. You can research it yourself. I'm too lazy to spend energy.
Restart Home Assistant:
Then go back to "Devices & Services" and click "Add Integration" in the lower right corner:
You will find "Xiaomi Miot Auto" added:
After clicking enter, the following interface appears. I chose account integration, which will associate all devices in my Xiaomi account together:
Just keep the device connection mode in "automatic mode":
After submission, an error will be reported and the following interface will appear:
In fact, I also got a similar error when using the "Xiaomi Miio" plug-in, but there was no "Click here" option to continue. After selecting "Click here" to continue, the following interface appeared, just click "Yes":
The following interface selects the range of Xiaomi devices to be connected, which is equivalent to a blacklist or whitelist. If Exclude is left blank, all devices will be connected:
You can see that all Xiaomi devices under my Xiaomi account have been automatically configured:
Now go back to the overview and you can see all my Xiaomi devices:
In the "Developer Tools" menu, there are options related to YAML:
The YAML here actually refers to a key configuration file in HA: "configuration.yaml". Many custom functions are implemented by directly editing it and adding content. Its default path is:
/root/config/configuration.yaml
You can edit it directly in the cli interface using the following command through the "Terminal&SSH" we installed earlier:
vim /root/config/configuration.yaml
However, this method is a little troublesome, after all, it requires vim, which some friends may not be familiar with, so I will use another simpler and more accustomed method in this section, that is, the add-on "Samba share", which can directly create a shared folder in the /root directory. Still in the "Add-on Store":
Click to install "Samba share":
After the installation is complete, configure it first:
Then start the service:
If it is a Windows system, directly use //HAOS IP address to access in "Run", enter the username and password configured above, and then use the resource manager to access:
In the above picture, addons is used to manually install plug-ins, and config is where "configuration.yaml" is located. You can directly edit "configuration.yaml" using a text editor on Windows.
Connect Xiaomi devices to HomeKit
Generally speaking, we mostly add devices from other platforms to HA through integration functions. However, sometimes there are reverse requirements, for example, adding Xiaomi devices that have joined HA to Apple's Home app through HomeKit. I believe that many Apple fans have this requirement. After all, compared with smart devices that directly support HomeKit, Xiaomi devices are much cheaper. At this time, HA is actually used as a bridge device. The steps to add are as follows:
Select "HomeKit Bridge":
Note: The "HomeKit Bridge" in the above picture is to add HA devices to Homekit, while the "HomeKit Device" is to add devices in Apple HomeKit to HA. The functions are completely different, so don't make the wrong choice.
Then select the domains to include, which is actually to select which devices on HA to add to Homekit:
This is still necessary. I have so many Xiaomi devices at home (48 devices, 157 entities), and it is a bit overwhelming to import all of them into HomeKit. I checked the binary sensor based on the default value (I made a mistake, I checked the binary sensor, and it killed me when I added it in the Home app later. I suggest that you don’t check it at the beginning, and you can add it and modify the option to achieve it if necessary):
Then you can see a lot more HomeKit pairings in the HA notification:
Open the "Home" app on your iPhone, click the + sign in the upper right corner, and select the first option "Add or Scan Accessories":
Scan the devices that need to scan the QR code in the notification one by one. The last one is HomeKit Bridge. After adding it, the information of Xiaomi devices will come (adding it makes me dead...). Finally, the content of the Home app is as follows:
And in "Devices and Services", "HomeKit Brideg" has been added to the configuration:
The contents are as follows (the previous domain options can also be modified in the "HASS Bridge" options in the figure below):
Other functions
If you want to add an automation scenario, add it in "Automation and Scenario":
For example, I want to create an automation so that whenever I turn on my Marantz amplifier, the TV wall lights turn on:
The function is so powerful, you can study it slowly on your own.
Home Assistant OS also supports additional features through the "Add-ons" store:
You can flexibly choose according to the hardware performance of your HA OS deployment and your own needs. I personally don't like this hodgepodge usage. I advocate the "specific" use of equipment. If a hodgepodge is needed, use a virtualization solution to carry out refined "specification".
Afterword
HA supports a lot of smart device brands. If you are interested in building a smart home, HA is worth studying. If you have higher requirements, you can also use special idle hardware to build dedicated devices. It depends on your needs.
After changing the uefi boot, it prompts uefi interactive shell v2.2 and cannot be started. My system is pve 8.2.2
My PVE is 7.9.x, does 8.2.2 still have this problem? I searched the keywords "pve 8 uefi interactive shell v2.2" on the Internet and didn't see any similar messages. It seems that this is not a problem unique to PVE 8. I can only look for any points in the operation process that I have not noticed.
After searching the entire Internet, there are basically a few solutions: 1. Turn off secure boot, which works for another ros system, but not for ha. 2. Modifying the startup items given by the official website is still useless. Finally, I found a mirror made by someone else. I don’t know if this is an exception.
I often have to admit that I have an ugly face.