ESPHome Install
HomeAssistant + EPSHome + ESP-Firmware配置:
- HomeAssistant:RaspberryPi运行HomeAssistant服务,收集区域内的智能设备信息,提供信息展示以及设备控制界面,并发送相应的控制命令;
- ESPHome: PC-Windows进行ESPHome,安装platformio开发环境,并完成ESPHome固件的配置、构建、下载等操作。
- ESPHome-Firmware: ESP-Devices具体的智能设备,运行固件执行设备功能。
三者相结合的方式,实现用ESP开发板,DIY自定义智能设备,接入到开放的智能家居生态系统——HomeAssistant中。
1.1. 安装ESPHome(PC-Windows):
经过多次尝试,以使用命令行手动安装方式最为方便且顺利。参考 https://esphome.io/guides/installing_esphome.html .
- 安装python
- pip install esphome
安装完成后,即可执行 esphome dashboard . ,在浏览器中输入“127.0.0.1:6053”,即可打开网页版esphome配置界面:
1.2. RaspberryPi安装ESPHome只有部分功能有效:
可以运行dashboard,可以创建新设备、编辑配置文件,但是无法编译。
由于ESPHome需要完整的编译环境,并且基于platformio,因此只能在windows、linux上执行,暂无aarch64-linux的安装。
ESPHome固件的配置与构建——基于ESP32S3开发板
安装完成之后即开始构建第一个ESPHome智能设备的固件,本次采用ESP32S3开发板。
ESPHome最开始为ESP8266以及ESP32设备开发,乐鑫推出最新的几代ESP32系列无线SoC(ESP32-C3、ESP32-S2、ESP32-S3)之后,才慢慢适配到这几个芯片平台(https://home-assistant-guide.com/2021/10/27/esphome-adds-early-support-for-esp32-s2-esp32-s3-and-esp32-c3/),但支持力度和社区成熟度(可供参考的项目例程)较少,终于花费了多次搜索之后才完成对ESP32S3开发板的配置和构建。
2.1. ESP32-S3配置
最开始的几个设置均出现错误,如:* “This board is unknown, please set the variant manually.”
- https://community.home-assistant.io/t/esp32-s3-wroom-1-board-type-for-esphome/423197/6
esp32:
board: ESP32DEV
variant: ESP32S3
framework:
type: esp-idf
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
version: 2.0.3
platform_version: 5.1.0
variant: esp32s3
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
platform_version: 4.4.0
variant: esp32s3
- https://community.home-assistant.io/t/esp32-s3-devkitc-1-v1-0/442090
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
platform_version: 4.4.0
variant: esp32s3
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
version: 2.0.3
platform_version: 5.1.0
variant: esp32s3
- https://community.home-assistant.io/t/unable-to-install-to-esp32-s3-lilygo-t-display-s3/467669
esp32:
board: esp32-s3-devkitc-1
variant: esp32s3
framework:
type: arduino
version: 2.0.3
platform_version: 5.0.0
最终设定的yaml配置文件如下:
substitutions:
hostname: test-esp32s3
wifi_update_interval: "3s"
esphome:
name: $hostname
esp32:
board: esp32-s3-devkitc-1
variant: ESP32S3
framework:
type: arduino
version: 2.0.3
platform_version: 5.1.1
logger:
level: DEBUG
api:
reboot_timeout: 0s
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: True
ap:
ssid: $hostname
password: !secret esp_fallback_wifi_password
web_server:
port: 80
auth:
username: !secret web_server_user
password: !secret web_server_password
time:
platform: homeassistant
id: homeassistant_time
switch:
- platform: restart
name: $hostname restart
id: reset
- platform: gpio
pin: 1
name: $hostname switch1
id: switch1
icon: mdi:power-socket-uk
restore_mode: RESTORE_DEFAULT_OFF
sensor:
- platform: wifi_signal
name: $hostname rssi
update_interval: $wifi_update_interval
- platform: uptime
name: Uptime Sensor
id: uptime_sensor
update_interval: $wifi_update_interval
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
text_sensor:
- platform: wifi_info
ip_address:
name: $hostname ipaddress
mac_address:
name: $hostname mac
- platform: template
name: $hostname Uptime Human Readable
id: uptime_human
icon: mdi:clock-start
随后执行编译构建,最终生成固件,然后下载到Flash中。
esphome compile test-esp32s3.yaml
esptool.exe -p COM19 -b 460800 write_flash 0x0 .\.esphome\build\test-esp32s3\.pioenvs\test-esp32s3\firmware-factory.bin
其中esphome compile会自动安装需要的platformio的platform和package:* espressif32 @ 3.5.0
- toolchain-xtensa32 @ ~2.50200.0
- framework-arduinoespressif32 @ ~3.10006.0
- tool-esptoolpy @ ~1.30100.0
- AsyncTCP-esphome @ 1.2.2
- ESPAsyncWebServer-esphome @ 2.1.0
- …
Dependency Graph* |– AsyncTCP-esphome @ 1.2.2
- |– WiFi @ 1.0
- |– FS @ 1.0
- |– Update @ 1.0
- |– ESPAsyncWebServer-esphome @ 2.1.0
- |– AsyncTCP-esphome @ 1.2.2
- |– DNSServer @ 1.1.0
- |– ESPmDNS @ 1.0
在HomeAssistant界面,可以配置各项参数、显示面板、
并控制开关量switch-1,实现对GPIO的LED亮灭状态的控制,如视频(上传到B站):
https://www.bilibili.com/video/BV1jd4y1k7jn/
在串口中即可看到输出信息: