本教程将使用 M5Dial v1.1 开发板集成到 Home Assistant 中,通过其旋钮编码器、NFC 读卡器和蜂鸣器实现智能家居控制。
CONTINUE。
New Device Setup 进入设备创建向导。
NEXT。
ESP32S3。
SKIP 跳过加密密钥设置。
EDIT 打开 YAML 编辑器,自定义设备配置。
esphome:
name: m5stack-dial
friendly_name: M5Stack Dial
on_boot:
then:
- pcf8563.read_time:
platformio_options:
board_build.flash_mode: dio
esp32:
variant: esp32s3
framework:
type: esp-idf
logger:
level: DEBUG
api:
encryption:
key: "your_encryption_key"
ota:
- platform: esphome
password: "your_ota_password"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Dial Fallback Hotspot"
password: "your_fallback_password"
font:
- file: "gfonts://Roboto"
id: my_font
size: 32 主要参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
framework.type | esp-idf | 使用 ESP-IDF 框架以获得更好的性能和稳定性。 |
platformio_options | board_build.flash_mode: dio | ESP32-S3 的 Flash 模式配置。 |
on_boot | pcf8563.read_time | 启动时读取 RTC 时间以初始化系统时钟。 |
i2c:
- id: internal_i2c
sda: GPIO11
scl: GPIO12
frequency: 400kHz
scan: true
spi:
id: spi_bus
mosi_pin: GPIO5
clk_pin: GPIO6 0x51)、RC522 NFC 模块(地址 0x28)和 FT5x06 触摸控制器(地址 0x38)共享。SPI 总线驱动 GC9A01A 圆形显示屏。display:
- platform: mipi_spi
id: round_display
model: GC9A01A
cs_pin: GPIO7
reset_pin: GPIO8
dc_pin: GPIO4
invert_colors: true
data_rate: 40MHz
update_interval: 1s
auto_clear_enabled: true
lambda: |-
it.print(120, 120, id(my_font), TextAlign::CENTER, "Hello");
touchscreen:
- platform: ft5x06
id: touch
i2c_id: internal_i2c
address: 0x38 主要参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
model | GC9A01A | 圆形屏幕的 MIPI SPI 显示控制器。 |
cs_pin | GPIO7 | SPI 片选引脚。 |
reset_pin | GPIO8 | 显示屏复位引脚。 |
dc_pin | GPIO4 | 显示屏数据/命令引脚。 |
invert_colors | true | GC9A01A 正确颜色显示所需。 |
touchscreen.address | 0x38 | FT5x06 触摸控制器的 I2C 地址。 |
output:
- platform: ledc
pin: GPIO9
id: backlight_output
frequency: 1000Hz
light:
- platform: monochromatic
name: "Backlight"
output: backlight_output
id: display_backlight
default_transition_length: 0s sensor:
- platform: rotary_encoder
id: encoder
name: "Rotary Encoder"
pin_a:
number: GPIO40
mode: INPUT_PULLUP
pin_b:
number: GPIO41
mode: INPUT_PULLUP
resolution: 4
min_value: -32768
max_value: 32767
publish_initial_value: true
binary_sensor:
- platform: gpio
name: Button
id: front_button
pin:
number: GPIO42
inverted: true
mode:
input: true
pullup: true 主要参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
encoder.pin_a | GPIO40 (INPUT_PULLUP) | 编码器信号引脚 A。 |
encoder.pin_b | GPIO41 (INPUT_PULLUP) | 编码器信号引脚 B。 |
encoder.resolution | 4 | 编码器分辨率模式(每个脉冲计数 4 个边沿)。 |
front_button.pin | GPIO42(取反) | 屏下按键,开路时拉高,按下时拉低。 |
rc522_i2c:
- id: nfc_reader
i2c_id: internal_i2c
address: 0x28
update_interval: 500ms
on_tag:
- lambda: |-
ESP_LOGD("rfid", "Card detected: %s", x.c_str());
on_tag_removed:
- lambda: |-
ESP_LOGD("rfid", "Card removed: %s", x.c_str()); 主要参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
address | 0x28 | WS1850S/RC522 NFC 模块的 I2C 地址。 |
update_interval | 500ms | 标签检测的轮询间隔。 |
on_tag | — | 检测到 NFC 标签时触发。 |
on_tag_removed | — | NFC 标签被移除时触发。 |
output:
- platform: ledc
pin: GPIO3
id: buzzer
frequency: 4000Hz
rtttl:
output: buzzer
id: rtttl_player
gain: 0.6
button:
- platform: template
name: "The buzzer beeps once"
id: buzzer_button
icon: mdi:bell-ring
on_press:
- rtttl.play:
id: rtttl_player
rtttl: "beep:d=4,o=5,b=180:16e,16e" time:
- platform: pcf8563
id: rtctime
i2c_id: internal_i2c
address: 0x51
update_interval: never
text_sensor:
- platform: template
name: "Device Time"
id: current_time_str
icon: mdi:clock-outline
update_interval: 10s
lambda: |-
auto t = id(rtctime).now();
if (!t.is_valid()) return {"--:--:--"};
char buf[20];
snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d",
t.year, t.month, t.day_of_month,
t.hour, t.minute, t.second);
return {buf}; 主要参数说明:
| 参数 | 值 | 说明 |
|---|---|---|
address | 0x51 | PCF8563 / BM8563 RTC 芯片的 I2C 地址。 |
update_interval | never | 禁用自动 RTC 同步(系统时间在启动时加载)。 |
SAVE,然后点击 INSTALL。
Manual Download。
Download 并选择 Factory format (Previously Modern) 将固件文件保存到本地。
CONNECT。
INSTALL。
Settings > Devices & Services 打开集成管理页面。
Discovered 区域中找到在线设备,点击 CONFIGURE,按照提示完成添加。
