本教程将介绍如何使用 Unit Step16 16 位旋转编码器控制单元集成至 Home Assistant,实现旋钮数值与灯光控制。
在本教程中,固件使用 ESPHome 2026.1.2 进行编译和上传。如果遇到编译 / 上传问题,请考虑将 ESPHome 切换到此版本。
CONTINUE。
New Device Setup。
NEXT。
ESP32。
SKIP。
EDIT。我们可以通过 YAML 文件自定义设备功能。
以下是代码的核心部分。下面提供了相关的参考和说明。
添加 External 组件:
external_components:
- source: github://m5stack/esphome-yaml/components
components: unit_step16
refresh: 0s
unit_step16:
id: my_step16
i2c_id: bsp_iic
address: 0x48 i2c:
- id: bsp_iic
scl: GPIO32
sda: GPIO26
scan: True 添加 Sensor 组件:
sensor:
- platform: unit_step16
unit_step16_id: my_step16
name: "Encoder Value"
update_interval: 100ms
on_value:
then:
- logger.log:
format: "Encoder value changed to: %.0f"
args: ["x"] 添加 Output 组件:
output:
- platform: unit_step16
id: led_brightness_output
unit_step16_id: my_step16
channel: led_brightness
- platform: unit_step16
id: rgb_brightness_output
unit_step16_id: my_step16
channel: rgb_brightness
- platform: unit_step16
id: rgb_red_output
unit_step16_id: my_step16
channel: rgb_red
- platform: unit_step16
id: rgb_green_output
unit_step16_id: my_step16
channel: rgb_green
- platform: unit_step16
id: rgb_blue_output
unit_step16_id: my_step16
channel: rgb_blue 添加 Light 组件:
light:
- platform: rgb
id: step16_rgb_light
name: "Step16 RGB Light"
red: rgb_red_output
green: rgb_green_output
blue: rgb_blue_output
restore_mode: ALWAYS_ON
default_transition_length: 0s
- platform: monochromatic
id: step16_led_display
name: "Step16 LED Display"
output: led_brightness_output
restore_mode: ALWAYS_ON
default_transition_length: 0s 添加 Number 组件:
number:
- platform: template
name: "RGB Brightness"
min_value: 0
max_value: 100
step: 1
optimistic: true
initial_value: 50
on_value:
then:
- output.set_level:
id: rgb_brightness_output
level: !lambda "return x / 100.0;" SAVE 和 INSTALL,然后在弹出窗口中选择 Manual Download。
Factory format (Previously Modern)。
CONNECT 连接设备。
INSTALL。
INSTALL进行上传。
Settings -> Device & services 检查设备。
Discover 部分找到相应的设备。