Introduction

This tutorial guides you through integrating the A02YYUW Waterproof Ultrasonic Sensor into HomeAssistant to monitor detection distances in real time.

Tutorial

Preparation

Wiring Diagram

Adding a New Device in ESPHome

  1. Click the NEW DEVICE button on the ESPHome homepage

  2. Click CONTINUE

  3. Enter your device name and click NEXT

  4. Select your development board model

  5. Save the device's Encryption key and click SKIP

  6. Click EDIT on the device card in ESPHome to view the auto-generated default program

Modifying the Code

Append the following code to the end of the auto-generated program, maintaining proper indentation and line breaks:

uart:
  tx_pin: GPIO16
  rx_pin: GPIO17
  baud_rate: 9600
  id: uart_a

sensor:
  - platform: "a02yyuw"
    name: "A02YYUW Distance"
    uart_id: uart_a

Code explanation reference: Link

First Firmware Installation

  1. After modifying the code, click INSTALL

  2. For the first installation, select Plug into this computer. Subsequent updates can use Wirelessly (OTA).

  3. After compilation completes, click Download project

  4. Select Factory format (Previously Modern) to download the firmware locally

  5. Connect the development board to your computer and click Open ESPHome Web

  6. Select your device's serial port:

  7. Select the firmware and flash:

  8. Wait for the flashing process to complete

Connecting to HomeAssistant

Go to the HomeAssistant homepage and navigate to Settings > Devices & services to view your device information:

Click Add to complete integration (you may need to enter the Encryption key):

Sensor data will now appear in HomeAssistant's Overview page: