English
English
简体中文
日本語
pdf-icon

Unit Key Home Assistant Integration

This tutorial will introduce how to use the Unit Key single button input unit with the CoreS3 main controller and integrate it into Home Assistant to achieve button state acquisition and light control.

1. Preparation

  1. Hardware List
  • 1 x Unit Key
  • 1 x CoreS3
  • 1 x HY2.0-4P Grove Cable (20cm)
  • 1 x Home Assistant Host (Server, Mini PC, NAS, etc.)
  1. Software and Versions

2. Create Device

  1. Open the ESPHome Dashboard. If the initial guidance interface appears, click CONTINUE.
  1. Click the green + button in the lower right corner to start creating a new device.
  1. Click New Device Setup to enter the device creation wizard.
  1. Enter the device name and click NEXT.
  1. Select the device type, click ESP32S3.
  1. Click SKIP to skip the encryption key setup.
  1. Click EDIT to enter the YAML configuration page and customize device functionality.

3. Device Configuration

Note
1. CoreS3's PORT.B interface corresponds to LED: GPIO9, BTN: GPIO1. If using other ports, please adjust according to the actual pins.
2. CoreS3's PORT interface power is controlled by the internal power management chip. Please ensure board is set to m5stack-cores3 and framework is set to arduino for the Unit Key to function properly.

3.1 Sensor Configuration

Add the Binary Sensor component to obtain button state.

binary_sensor:
  - platform: gpio
    name: "Button"
    id: unit_key_button
    pin:
      number: GPIO8 # CoreS3 PORT.B, please adjust according to the actual connected GPIO pin
      mode:
        input: true
        pullup: true
      inverted: true
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
    on_press:
      then:
        - logger.log: "Pressed"
        - light.toggle: unit_key_led
    on_multi_click:
      - timing:
          - ON for at least 1s
        then:
          - logger.log: "Hold"
          - light.turn_off: unit_key_led

3.2 Light Configuration

Add the Light component to control the backlight RGB LED.

light:
  - platform: neopixelbus
    name: "LED"
    id: unit_key_led
    type: GRB            
    variant: SK6812
    pin: GPIO9 # CoreS3 PORT.B, please adjust according to the actual connected GPIO pin
    num_leds: 1
    method:
      type: esp32_rmt
      channel: 0
    default_transition_length: 200ms
    restore_mode: RESTORE_DEFAULT_OFF

4. Download and Flash Firmware

4.1 Compile Firmware

  1. After completing the YAML modifications, click SAVE in the upper right corner to save the configuration, then click INSTALL.
  1. Select Manual Download in the pop-up window.
  1. Wait for the firmware compilation to complete, click Download and select Factory format (Previously Modern), then save the firmware locally.

4.2 Flash Firmware

  1. Connect the CoreS3 to your computer using a USB Type-C cable. Open ESPHome Web and click CONNECT.
  1. In the serial port selection window that appears, select the correct serial port.
  1. Click INSTALL.
  1. Select the firmware file downloaded in step 3 and start flashing.
Note
After flashing is complete, the device must be reset, otherwise the firmware may not start properly.

5. Get Started

  1. In Home Assistant, click Settings > Devices & Services in sequence to enter the integration management page.
  1. Find the Unit Key device in the Discovered area, click CONFIGURE and follow the wizard to complete the configuration.
  1. After the device is added, you can see real-time information of the button state and LED light state on the device details page.
  1. Finally, add these sensor entities to the dashboard to monitor the button state and light status in real time.
On This Page