安装 Home Assistant
docker run -d \
-<span class="ruby">-name homeassistant \
</span> -<span class="ruby">-privileged \
</span> -<span class="ruby">-restart=<span class="hljs-keyword">unless</span>-stopped \
</span> -<span class="ruby">e TZ=MY_TIME_ZONE \
</span> -<span class="ruby">v /<span class="hljs-symbol">PATH_TO_YOUR_CONFIG:</span>/config \
</span> -<span class="ruby">v /run/<span class="hljs-symbol">dbus:</span>/run/<span class="hljs-symbol">dbus:</span>ro \
</span> -<span class="ruby">-network=host \
</span> ghcr.io/home-assistant/home-assistant:stable
From home-assistant.io/installation/linux
IP:8123
这里省略初始化过程,简单点击几个按钮即可
安装 HACS
docker exec -it homeassistant bash
wget -O - https:<span class="hljs-regexp">//g</span>et.hacs.xyz | bash -
<span class="hljs-keyword">exit</span>
reboot
点击右下角的齿轮图标,选择 设备与服务,然后点击 添加集成 在弹出的页面中搜索 HACS,并选择进行安装。 按提示输入 GitHub 授权码完成登录。
安装 Xiaomi Miot Atuo
在左侧菜单中点击 HACS,搜索 Xiaomi Miot Auto,然后选择下载安装 下载完成后,重启 Home Assistant
接入米家设备
点击左下角的齿轮图标,选择 设备与服务,然后点击 设备 点击添加设备,搜索 Xiaomi Miot Auto,并选择 Add devices using Mi Account 进行账号集成。 输入小米账号(即米家 APP 我的页面顶部的数字) 和密码。 在设备连接模式下,选择 Auto
验证
回到设备页面,随便点击一个米家设备 中间的控制菜单必须有等于或多余 1 个控制项
安装 ESPHome
这里以 ESP32+DHT11 温湿度传感器为例 于使用 Docker 部署,无法直接通过 Home Assistant 添加插件
docker <span class="hljs-built_in">run</span> -d --name=<span class="hljs-string">"ESPHome"</span> -e TZ=Asia/Shanghai -v /<span class="hljs-built_in">home</span>/esphome:/<span class="hljs-built_in">config</span> -v /<span class="hljs-built_in">run</span>/udev:/<span class="hljs-built_in">run</span>/udev --privileged --restart=always --net=host esphome/esphome
IP:6052
安装 ESPHome 到 ESP32
点击右下角的 NEW DEVICE,然后点击 OPEN ESPHOME WEB 在新页面中选择 CONNECT,选择 ESP32,并点击 INSTALL 进行安装, 安装完成后,进行 WIFI 配置,注意 ESP32 只支持 2.4GHz 的 WIFI 回到 ESPHome 页面,点击 ADOPT 当出现安装页面时,直接点击右下角的 STOP,我们将使用另一种更快的方法
接线
DHT11(有孔那面,由左到右) VCC DATA NC GND
VCC > 3.3V DATA > D2 NC GND > GND P.S: 这里需要注意,必须在 VCC 与 DATA 中串一个 4.7kΩ的电阻
编译固件
以下配置基于我的需求,请根据实际情况进行相应修改
<span class="hljs-attr">substitutions:</span>
<span class="hljs-attr"> name:</span> esphome-web-xxxxxx
<span class="hljs-attr"> friendly_name:</span> ESPHome Web xxxxxx
<span class="hljs-attr">esphome:</span>
<span class="hljs-attr"> name:</span> ${name}
<span class="hljs-attr"> friendly_name:</span> ${friendly_name}
<span class="hljs-attr"> min_version:</span> <span class="hljs-number">2024.6</span><span class="hljs-number">.0</span>
<span class="hljs-attr"> name_add_mac_suffix:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr"> project:</span>
<span class="hljs-attr"> name:</span> esphome.web
<span class="hljs-attr"> version:</span> dev
<span class="hljs-attr">esp32:</span>
<span class="hljs-attr"> board:</span> esp32dev
<span class="hljs-attr"> framework:</span>
<span class="hljs-attr"> type:</span> arduino
<span class="hljs-comment"># Enable logging</span>
<span class="hljs-attr">logger:</span>
<span class="hljs-comment"># Enable Home Assistant API</span>
<span class="hljs-attr">api:</span>
<span class="hljs-comment"># Allow Over-The-Air updates</span>
<span class="hljs-attr">ota:</span>
<span class="hljs-attr">- platform:</span> esphome
<span class="hljs-comment"># Allow provisioning Wi-Fi via serial</span>
<span class="hljs-attr">improv_serial:</span>
<span class="hljs-attr">wifi:</span>
<span class="hljs-comment"># Set up a wifi access point</span>
<span class="hljs-attr"> ap:</span> {}
<span class="hljs-comment"># In combination with the `ap` this allows the user</span>
<span class="hljs-comment"># to provision wifi credentials to the device via WiFi AP.</span>
<span class="hljs-attr">captive_portal:</span>
<span class="hljs-attr">dashboard_import:</span>
<span class="hljs-attr"> package_import_url:</span> github://esphome/example-configs/esphome-web/esp32.yaml@main
<span class="hljs-attr"> import_full_config:</span> <span class="hljs-literal">true</span>
<span class="hljs-comment"># Sets up Bluetooth LE (Only on ESP32) to allow the user</span>
<span class="hljs-comment"># to provision wifi credentials to the device.</span>
<span class="hljs-attr">esp32_improv:</span>
<span class="hljs-attr"> authorizer:</span> none
<span class="hljs-comment"># To have a "next url" for improv serial</span>
<span class="hljs-attr">web_server:</span>
<span class="hljs-comment"># Example configuration entry</span>
<span class="hljs-attr">sensor:</span>
<span class="hljs-attr"> - platform:</span> dht
<span class="hljs-attr"> pin:</span> GPIO2
<span class="hljs-attr"> temperature:</span>
<span class="hljs-attr"> name:</span> <span class="hljs-string">"Temperature"</span>
<span class="hljs-attr"> humidity:</span>
<span class="hljs-attr"> name:</span> <span class="hljs-string">"Humidity"</span>
<span class="hljs-attr"> update_interval:</span> <span class="hljs-number">60</span>s
pip <span class="hljs-keyword">install</span> esphome
esphome compile <span class="hljs-number">0</span>.yaml <span class="hljs-comment">#修改成上方的 yaml 文件</span>
编译后的固件位于.pioenvs\esphome-web-8ffb98\firmware.bin
ESP32 的 IP:80 OTA Update>选择 firmware.bin 文件>Update
接入 ESPHome
点击左下角的齿轮图标,选择 设备与服务,然后点击设备 点击添加设备,选择 ESPHome,并在主机字段中输入 ESP32 的 IP 地址(注意:这里输入的是 ESP32 的 IP,而非 ESPHome 服务端的 IP) 再后回到设备页面,应该会看到设备名为 ESPHome Web xxxxxx