The bedside box: light, fan, blind and radio from bed

Two ESP32 boards on a home-made circuit board, with radar, speakers, four buttons and a dimmer knob, so the room runs from bed.

Difficulty
Advanced
Parts cost
Two ESP32 boards, a radar, a mic, two amps and speakers, two sensors, a 12 V plug pack and a printed case
Build time
Several evenings for the electronics and firmware, and longer again if you design your own circuit board
Skills
Soldering, ESPHome, Home Assistant, PCB design

The problem

I wanted to run the bedroom from bed. Light on and off, dim it, the fan, the blind, a bit of radio, without reaching for a phone. The box that does it now sits beside the bed: a radar that knows someone’s there, two small speakers, four buttons, one status light and a knob you can turn in the dark.

It started beside our bed. It now lives in one of the kids’ rooms, where a couple of the buttons do different jobs (more on that below).

It’s also the first build I had a proper circuit board made for. I got that board wrong in more ways than I’d like. Every one of them is in the lessons at the bottom.

Where it started: a round touchscreen

The first version was a round touchscreen puck: an ESP32-C6 board from Waveshare with a 1.43” AMOLED screen (466×466), touch, a microphone and a small speaker. No ESPHome config existed for it, so every part had to be proven from scratch.

  • The screen was black when the light was off and full white when it was on, so it doubled as a nightlight.
  • Tap anywhere to toggle the light. Swipe up for brighter, down for dimmer, 20% a swipe.
  • A wake word, heard on the device itself, for voice.

It taught me what the next one needed:

  • The C6 has one I2S port. I2S is the digital audio connection: a pair of clock wires and a data wire. With one port it can do the microphone or the speaker, not both at once. I ended up with microphone-only voice and a speaker that worked but sat unused.
  • No PSRAM (the extra memory chip) that ESPHome could use, and a single core. The screen refresh and the wake word fought over that core. More on that in the lessons.
  • The Wi-Fi was flaky at the bedside (55 to 60% packet loss) and perfect on my desk. My suspect was the wireless phone charger right next to it. No software setting fixed it.

So the new box splits the work across two boards, gives the microphone and the speakers their own audio buses, and has real buttons instead of a touchscreen. The round screen is retired, so its config isn’t in this guide.

How it works

How the bedside box works Two boards share one carrier board. The ESP32-S3 handles the microphone on one I2S bus, two amplifiers on a second I2S bus, the light and fan buttons and the dimmer knob. The ESP32-C3 handles the radar, the blind and voice buttons and the status LED. Both talk to Home Assistant over Wi-Fi, which runs the scripts for the light, the blind and the radio, and mirrors the voice stage back onto the status LED. The radio plays through the box's own speakers. Carrier board ESP32-S3 mic: I2S bus 1 2 amps: I2S bus 2 light button fan button dimmer knob ESP32-C3 radar presence spare button (blind) voice button status LED Wi-Fi, both ways Home Assistant button presses → scripts voice stage → status LED Light toggle, colour, dim Blind open or close Radio on or off The radio plays back through the box's own speakers.

There are two boards on one carrier board (the circuit board I designed for it). The ESP32-S3 (a Seeed XIAO) does audio: the microphone on one I2S bus, two amplifiers on a second I2S bus, plus the light button, the fan button, the dimmer knob and two room sensors. It also runs the wake word (“Okay Nabu”) on the board itself. The ESP32-C3 (a “SuperMini”) does the radar, the other two buttons and the status LED. Each runs ESPHome and shows up in Home Assistant as its own device. They share power and nothing else.

The boards decide very little themselves. A button press calls a Home Assistant script, so changing what a button does is a Home Assistant edit, not a reflash. That’s what made moving the box to another room easy.

The status LED is the odd one out. It’s one colour, so it shows the voice assistant’s stages by how fast it pulses: fast while it’s listening, medium while it’s thinking, a slow breathe while it talks back. The S3 knows the stage, but the S3 had no spare pin left for the LED. So the S3 publishes a “Voice Stage” text sensor, and a Home Assistant automation mirrors it onto the C3’s LED. That round trip costs about 100 to 300 ms, which you can’t see on a light that fades over 150 ms anyway.

The knob does two jobs. Normally it dims the light. While music is playing on the box it’s the volume.

What the buttons do now

In the kids’ room the buttons were re-jobbed in Home Assistant, with no firmware change:

Button What it does
Light Press: light on or off. Double press: next colour (red, orange, yellow, green, blue, indigo, violet, then back to white). Hold 2 seconds: turns presence lighting off or on, with a rising or falling chime so you know which. Home Assistant switches it back on at midnight.
Fan Starts and stops the radio on the box’s own speakers. In our room it ran the fan.
Spare Now the blind: a press opens or closes it.
Voice Press: talk to the voice assistant. Double press: the radio. Triple press: a playlist. Hold it for a second or more: cancel.
Knob Dims the room’s light, or sets the volume while music plays.

Presence lighting only turns the light on when it’s already off, so walking in doesn’t wipe the colour someone picked.

What you need

  • Seeed XIAO ESP32-S3 (audio, two buttons, the knob, the sensors). It has 8 MB of PSRAM, and the wake word needs it.
  • ESP32-C3 SuperMini (radar, two buttons, the status LED). It’s the cheaper board and does everything it needs to.
  • An LD2412 radar. A 24 GHz mmWave presence sensor (mmWave radar sees you breathing, so it knows you’re still there when you lie still). It talks to the C3 over serial.
  • An INMP441 I2S microphone (also sold as “MP441”).
  • Two MAX98357A I2S amplifier boards (the Adafruit layout), one per speaker.
  • Two 4 Ω 3 W speakers, the small sealed-box type.
  • A BME280 (temperature, humidity, pressure) and a BH1750 (light level). Both are I2C, the two-wire sensor bus.
  • A 10 kΩ linear potentiometer. Mine is a Jaycar 16 mm pot with a 6 mm splined shaft that stands 9.6 mm above the nut. Use 10 kΩ, not 1 MΩ: a 1 MΩ pot is far too high for the ESP32’s analogue input and reads noisy and uneven.
  • Four DS-228 momentary push buttons. They have four legs but are a simple on/off switch: two legs are one contact. Meter them before you solder.
  • One 3 mm LED for the status light.
  • Resistors: 10 kΩ (for the fan button, see Wiring), 68 to 100 Ω for the status LED (100 Ω is the safer pick, see Wiring), 470 kΩ (amp channel select).
  • Capacitors: a 100 µF 16 V electrolytic across the 5 V rail near the amps, and a 100 nF ceramic at each amp’s power pin. Class-D amps draw current in bursts and need them.
  • Power: a 12 V 2 A plug pack. On the carrier board it goes through a 2 A mini blade fuse and a reverse-polarity diode, then an MP1584 buck converter (a small step-down power board) makes 5 V for both ESP32s and both amps. My power budget worked out at about 1.1 A, so a 1 A fuse is too small.
  • Optional down-glow: eight 3 mm 12 V LEDs with built-in resistors (four blue, four green), two BC337 transistors, two 1 kΩ and two 10 kΩ resistors. See the C3 wiring.
  • A case. Mine is 3D printed, with the top plate held on by four M3 countersunk screws. The case files aren’t published yet.

Wiring

The S3 has no spare pins: all 11 are used. Anything new goes on the C3, which has a few free.

ESP32-S3 (XIAO)

What Pin Notes
Knob wiper D0 (GPIO1) Pot outer legs to 3.3 V and GND. The wiper is the centre leg. If it dims backwards, swap the outer legs.
Light button D1 (GPIO2) Button from 3.3 V to the pin. Internal pull-down, so pressed reads high.
Fan button D2 (GPIO3) Same, but needs an external 10 kΩ from GPIO3 to GND. See the lessons.
Mic clock (SCK) D3 (GPIO4) Microphone bus.
Mic word select (WS) D4 (GPIO5) Microphone bus.
Amp data (DIN on both amps) D5 (GPIO6) Amp data and mic data run in opposite directions, so they can’t share a pin.
I2C SDA D6 (GPIO43) BME280 at address 0x76 (some boards are 0x77), BH1750 at 0x23.
I2C SCL D7 (GPIO44)
Amp clock (BCLK on both amps) D8 (GPIO7) Speaker bus.
Amp word select (LRC on both amps) D9 (GPIO8) Speaker bus.
Mic data (the mic’s SD pin) D10 (GPIO9)

The microphone’s VDD goes to 3.3 V and its L/R pin to GND, which makes it the left channel.

ESP32-C3 (SuperMini)

What Pin Notes
Spare (blind) button GPIO0 3.3 V to the pin, internal pull-down.
Voice button GPIO1 Same.
Radar TX GPIO4 Crossover: the radar’s TX goes to the C3’s receive pin.
Radar RX GPIO3 115200 baud.
Status LED GPIO5 Through 68 to 100 Ω to the LED, then GND.
Down-glow blue / green (optional) GPIO6 / GPIO7 Each drives a BC337 base through 1 kΩ, with a 10 kΩ to GND to hold it off at boot. The transistor switches four 12 V LEDs off the 12 V rail.
Power 5V and GND only The radar takes 5 V and GND from here too. Leave the C3’s 3V3 pin unconnected.
GPIO2, 8, 9 not used Strapping pins (read at boot). Leave them floating.
GPIO20, 21 left free on purpose The serial port. On my board the USB ports face inward, so a USB-serial adapter on these two is how I read the logs with it assembled.

On the status LED resistor: 68 Ω gives about 19 mA with a red LED, right on the C3’s 20 mA per-pin limit. 100 Ω gives about 13 mA and works with any red, green or yellow LED. A blue or white LED will barely light on either.

Amplifiers. Each MAX98357A has an SD pin that also picks which channel it plays, by voltage. (Not to be confused with the microphone’s SD pin, which is its data out. Same label, different job.) On the first build both were tied straight to VIN, which makes both play the left channel. On the carrier board the left amp’s SD is still tied to +5 V, and the right amp gets a 470 kΩ pull-up to +5 V, which lands it at about 1.19 V, inside the “right channel” window. A resistor to ground can never pick right: it only drags it towards “average of both” and then shutdown. My numbers assume the 1 MΩ that the Adafruit layout already has on SD, and breakouts differ, so check the voltage on the bench with your real amp. Leave each amp’s GAIN pin floating (9 dB). The speakers wire straight to each amp’s screw terminal, either polarity.

Firmware and config

These are the two configs running on the box now, tidied up, with my names and entity ids swapped for examples. Name the devices room first and decide that before you add them to Home Assistant. Here they’re bedside-box and bedside-box-radar.

Put your Wi-Fi details in secrets.yaml as wifi_ssid and wifi_password.

The main board (ESP32-S3)

substitutions:
  name: bedside-box
  friendly_name: "Bedside Box"
  # The light this box controls, and the presence-lighting switch the
  # 2 second hold flips. Change them here, not further down.
  light_entity: light.example_light
  presence_switch: input_boolean.example_presence_lighting

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2025.5.0

esp32:
  board: seeed_xiao_esp32s3
  variant: esp32s3
  framework:
    type: esp-idf

# The wake word model and audio buffers don't fit without PSRAM.
psram:
  mode: octal
  speed: 80MHz

logger:
  hardware_uart: USB_SERIAL_JTAG
  level: INFO

api:
  # The voice button lives on the C3. Home Assistant passes its presses
  # back to these two actions, so the multi-press logic runs here.
  actions:
    - action: start_voice
      then:
        - script.execute: voice_press
    - action: stop_voice
      then:
        - script.stop: voice_press
        - lambda: 'id(voice_press_count) = 0;'
        - voice_assistant.stop:
        - text_sensor.template.publish:
            id: voice_stage
            state: "idle"

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none
  # Keep false if two access points share your Wi-Fi name. fast_connect
  # rejoins the last one it used, even when it's the far one.
  fast_connect: false
  output_power: 20dB
  ap:
    ssid: "${friendly_name} Fallback"

captive_portal:

button:
  - platform: restart
    name: "Restart"

globals:
  - id: voice_press_count
    type: int
    restore_value: false
    initial_value: '0'
  - id: last_pot_sent
    type: float
    restore_value: false
    initial_value: '-1'
  - id: pot_mode_anchor
    type: float
    restore_value: false
    initial_value: '-1'
  - id: pot_was_audio
    type: bool
    restore_value: false
    initial_value: 'false'
  # 0 = normal white, 1-7 = red to violet
  - id: rainbow_step
    type: int
    restore_value: false
    initial_value: '0'

i2c:
  sda: GPIO43     # D6
  scl: GPIO44     # D7
  scan: true
  id: bus_a

sensor:
  - platform: bme280_i2c
    address: 0x76          # some boards are 0x77: the boot scan will say
    temperature:
      name: "Temperature"
      filters:
        - offset: -6.5     # measured self-heating, see Testing
        - throttle: 60s
    humidity:
      name: "Humidity"
      filters:
        - offset: 8.1      # trust this one less, see the lessons
        - throttle: 60s
    pressure:
      name: "Pressure"
      filters:
        - throttle: 60s
    update_interval: 30s

  - platform: bh1750
    address: 0x23
    name: "Illuminance"
    update_interval: 30s
    filters:
      - throttle: 60s

  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s

  # The knob: 10k linear pot on D0
  - platform: adc
    pin: GPIO1        # D0
    id: pot_raw
    update_interval: 200ms
    attenuation: 12db
    internal: true
    filters:
      - median:
          window_size: 5
          send_every: 2
      - lambda: return x / 3.3f * 100.0f;   # 0-3.3 V to 0-100%
      - delta: 2.0                          # ignore the ADC's own noise
      - clamp:
          min_value: 0
          max_value: 100
    on_value:
      then:
        - script.execute:
            id: pot_changed
            pct: !lambda return x;

text_sensor:
  # So the 2 second hold knows which way to flip it, and which chime to play
  - platform: homeassistant
    id: presence_switch_state
    entity_id: ${presence_switch}
    internal: true

  # Mirrored onto the C3's status LED by a Home Assistant automation
  - platform: template
    name: "Voice Stage"
    id: voice_stage
    icon: mdi:waveform
    update_interval: never

binary_sensor:
  - platform: gpio
    id: btn_light
    pin:
      number: GPIO2    # D1
      mode:
        input: true
        pulldown: true
    name: "Light Button"
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_multi_click:
      # Hold 2 s: presence lighting off or on, with a chime
      - timing:
          - ON for at least 2s
        then:
          - if:
              condition:
                lambda: 'return id(presence_switch_state).state == "on";'
              then:
                - homeassistant.action:
                    action: input_boolean.turn_off
                    data:
                      entity_id: ${presence_switch}
                - rtttl.play: "off:d=8,o=5,b=180:e6,c6,g5"
              else:
                - homeassistant.action:
                    action: input_boolean.turn_on
                    data:
                      entity_id: ${presence_switch}
                - rtttl.play: "on:d=8,o=5,b=180:g5,c6,e6"
      # Double press: next colour, then back to white after violet
      - timing:
          - ON for at most 0.6s
          - OFF for at most 0.4s
          - ON for at most 0.6s
          - OFF for at least 0.1s
        then:
          - lambda: 'id(rainbow_step) = (id(rainbow_step) + 1) % 8;'
          - homeassistant.action:
              action: script.example_light_colour
              data:
                step: !lambda 'return to_string(id(rainbow_step));'
      # Single press: on or off. It waits about 0.4 s to be sure it
      # isn't the first half of a double press.
      - timing:
          - ON for at most 1s
          - OFF for at least 0.4s
        then:
          - lambda: 'id(rainbow_step) = 0;'
          - homeassistant.action:
              action: light.toggle
              data:
                entity_id: ${light_entity}

  # GPIO3 has no internal pull resistors, so pulldown: true does nothing
  # on this one pin. Fit a real 10k from GPIO3 to GND.
  - platform: gpio
    id: btn_fan
    pin:
      number: GPIO3    # D2
      mode:
        input: true
        pulldown: true
    name: "Fan Button"
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      - homeassistant.action:
          action: script.bedside_box_radio_toggle

# Two I2S buses: the mic and the speakers can't share one.
i2s_audio:
  - id: i2s_out                 # speakers
    i2s_lrclk_pin: GPIO8        # D9
    i2s_bclk_pin: GPIO7         # D8
  - id: i2s_in                  # microphone
    i2s_lrclk_pin: GPIO5        # D4
    i2s_bclk_pin: GPIO4         # D3

microphone:
  - platform: i2s_audio
    id: mic
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO9        # D10, the mic's SD pin
    adc_type: external
    pdm: false
    bits_per_sample: 32bit
    channel: left             # mic L/R pin tied to GND

speaker:
  - platform: i2s_audio
    id: spk
    i2s_audio_id: i2s_out
    dac_type: external
    i2s_dout_pin: GPIO6       # D5, to both amps' DIN
    channel: stereo           # each amp's SD pin picks its side
    bits_per_sample: 16bit

  # Voice and music each get their own source speaker, mixed into the one
  # real output. See the lessons for why.
  - platform: mixer
    id: spk_mixer
    output_speaker: spk
    source_speakers:
      - id: spk_announce
      - id: spk_media

media_player:
  - platform: speaker
    name: "Media"
    id: bedside_media
    announcement_pipeline:
      speaker: spk_announce
      format: WAV
      sample_rate: 16000
      num_channels: 1
    media_pipeline:
      speaker: spk_media
      format: FLAC
      num_channels: 2
    volume_increment: 5%
    volume_initial: 60%
    # Pause the wake word while music plays
    on_play:
      - micro_wake_word.stop:
    on_idle:
      - micro_wake_word.start:
    on_pause:
      - micro_wake_word.start:

# Chimes, played locally so there's no network delay
rtttl:
  id: chime
  speaker: spk_announce

micro_wake_word:
  id: mww
  microphone:
    microphone: mic
  models:
    - model: okay_nabu
  vad:
  on_wake_word_detected:
    - rtttl.play: "wake:d=16,o=6,b=200:c,e,g"
    - voice_assistant.start:

voice_assistant:
  id: va
  microphone:
    microphone: mic
  media_player: bedside_media
  use_wake_word: false        # micro_wake_word above does the listening
  noise_suppression_level: 2
  auto_gain: 31dBFS
  volume_multiplier: 2.0
  on_listening:
    - text_sensor.template.publish:
        id: voice_stage
        state: "listening"
    - script.execute: voice_watchdog
  on_stt_end:
    - text_sensor.template.publish:
        id: voice_stage
        state: "thinking"
  on_tts_start:
    - text_sensor.template.publish:
        id: voice_stage
        state: "speaking"
  on_end:
    - script.stop: voice_watchdog
    - text_sensor.template.publish:
        id: voice_stage
        state: "idle"
    - micro_wake_word.start:
  on_error:
    - script.stop: voice_watchdog
    - text_sensor.template.publish:
        id: voice_stage
        state: "idle"
    - micro_wake_word.start:
  on_client_connected:
    - micro_wake_word.start:
  on_client_disconnected:
    - voice_assistant.stop:
    - micro_wake_word.stop:

script:
  # Voice button: 1 press talks, 2 plays the radio, 3 plays a playlist.
  # restart mode: each press inside the window restarts the 400 ms timer.
  - id: voice_press
    mode: restart
    then:
      - lambda: 'id(voice_press_count) += 1;'
      - if:
          condition:
            lambda: 'return id(voice_press_count) == 1;'
          then:
            - voice_assistant.start:
      - delay: 400ms
      - if:
          condition:
            lambda: 'return id(voice_press_count) >= 2;'
          then:
            - voice_assistant.stop:
            - text_sensor.template.publish:
                id: voice_stage
                state: "idle"
      - if:
          condition:
            lambda: 'return id(voice_press_count) == 2;'
          then:
            - homeassistant.action:
                action: script.play_radio
                data:
                  player: media_player.bedside_box_media
      - if:
          condition:
            lambda: 'return id(voice_press_count) >= 3;'
          then:
            - homeassistant.action:
                action: script.play_playlist
                data:
                  player: media_player.bedside_box_media
      - lambda: 'id(voice_press_count) = 0;'

  # The knob: brightness normally, volume while music plays.
  # The pot reports a position, not a change. Without the guard, volume
  # would jump to wherever the dimmer was the moment music starts. So when
  # the mode flips, ignore the knob until it moves 4% from where it was.
  - id: pot_changed
    mode: single
    parameters:
      pct: float
    then:
      - lambda: |-
          const float POT_CATCH = 4.0f;
          bool audio_now = id(bedside_media).state == media_player::MEDIA_PLAYER_STATE_PLAYING;
          if (audio_now != id(pot_was_audio)) {
            id(pot_was_audio) = audio_now;
            id(pot_mode_anchor) = pct;
            return;
          }
          if (id(pot_mode_anchor) >= 0.0f) {
            if (fabsf(pct - id(pot_mode_anchor)) < POT_CATCH) return;
            id(pot_mode_anchor) = -1.0f;
          }
          if (fabsf(pct - id(last_pot_sent)) < 2.0f) return;
          id(last_pot_sent) = pct;
          if (audio_now) {
            id(bedside_media).make_call().set_volume(pct / 100.0f).perform();
          } else {
            id(pot_to_ha)->execute(pct);
          }

  - id: pot_to_ha
    mode: single
    parameters:
      pct: float
    then:
      - homeassistant.action:
          action: light.turn_on
          data:
            entity_id: ${light_entity}
            brightness_pct: !lambda return to_string((int) pct);

  # If a voice request hangs, reset after 30 s
  - id: voice_watchdog
    mode: restart
    then:
      - delay: 30s
      - logger.log: "Voice pipeline hung, resetting"
      - voice_assistant.stop:
      - text_sensor.template.publish:
          id: voice_stage
          state: "idle"
      - micro_wake_word.start:

Note the knob calls light.turn_on with a brightness. That means turning it can switch the light on from off. If you’d rather it only dims a light that’s already on, point it at a small Home Assistant script with a “light is on” condition first.

The radar board (ESP32-C3)

substitutions:
  name: bedside-box-radar
  friendly_name: "Bedside Box Radar"

esphome:
  name: ${name}
  friendly_name: ${friendly_name}

esp32:
  board: esp32-c3-devkitm-1
  variant: esp32c3
  framework:
    type: esp-idf

logger:
  # The serial port on GPIO20/21, not USB: the USB ports can't be
  # reached once it's assembled.
  hardware_uart: UART0
  level: INFO

api:

web_server:
  port: 80
  log: true

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none
  fast_connect: false
  output_power: 20dB
  ap:
    ssid: "${friendly_name} Fallback"

captive_portal:

button:
  - platform: restart
    name: "Restart"

binary_sensor:
  - platform: gpio
    id: btn_spare
    pin:
      number: GPIO0
      mode:
        input: true
        pulldown: true
    name: "Blind Button"
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      - homeassistant.action:
          action: script.example_blind_toggle

  - platform: gpio
    id: btn_voice
    pin:
      number: GPIO1
      mode:
        input: true
        pulldown: true
    name: "Voice Button"
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    # Passed to the S3's actions. The name comes from the S3's device
    # name, with the dash turned into an underscore.
    on_press:
      - homeassistant.action:
          action: esphome.bedside_box_start_voice
    on_click:
      min_length: 1000ms
      max_length: 5000ms
      then:
        - homeassistant.action:
            action: esphome.bedside_box_stop_voice

  - platform: ld2412
    has_target:
      name: "Presence"
      device_class: occupancy
    has_moving_target:
      name: "Moving"
    has_still_target:
      name: "Still"

uart:
  id: ld2412_uart
  tx_pin: GPIO3     # to the radar's RX
  rx_pin: GPIO4     # from the radar's TX
  baud_rate: 115200
  parity: NONE
  stop_bits: 1

ld2412:
  id: radar
  uart_id: ld2412_uart

# Radar settings you can change from Home Assistant.
# Set the max distance gate to the room: each gate is 0.75 m, and the
# radar sees through walls.
number:
  - platform: ld2412
    timeout:
      name: "Presence Hold Time"
    min_distance_gate:
      name: "Min Distance Gate"
    max_distance_gate:
      name: "Max Distance Gate"

select:
  - platform: ld2412
    distance_resolution:
      name: "Distance Resolution"

switch:
  - platform: ld2412
    engineering_mode:
      name: "Engineering Mode"

text_sensor:
  - platform: ld2412
    version:
      name: "Radar Firmware"

sensor:
  - platform: ld2412
    detection_distance:
      name: "Detection Distance"
      filters: &radar_filters
        - throttle: 2s
        - delta: 5.0
    moving_distance:
      name: "Moving Distance"
      filters: *radar_filters
    still_distance:
      name: "Still Distance"
      filters: *radar_filters
    moving_energy:
      name: "Move Energy"
      filters: *radar_filters
    still_energy:
      name: "Still Energy"
      filters: *radar_filters
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s

output:
  - platform: ledc
    pin: GPIO5
    id: status_led_out
  # Optional down-glow: these drive transistor bases, not the LEDs directly
  - platform: ledc
    pin: GPIO6
    id: glow_blue_out
  - platform: ledc
    pin: GPIO7
    id: glow_green_out

light:
  - platform: monochromatic
    name: "Down-glow Blue"
    output: glow_blue_out
    default_transition_length: 400ms
    restore_mode: ALWAYS_OFF

  - platform: monochromatic
    name: "Down-glow Green"
    output: glow_green_out
    default_transition_length: 400ms
    restore_mode: ALWAYS_OFF

  # One colour, so the states are told apart by pulse rate
  - platform: monochromatic
    name: "Status LED"
    id: status_led
    output: status_led_out
    default_transition_length: 150ms
    restore_mode: ALWAYS_OFF
    effects:
      - pulse:
          name: listening
          transition_length: 200ms
          update_interval: 400ms
      - pulse:
          name: thinking
          transition_length: 400ms
          update_interval: 800ms
      - pulse:
          name: speaking
          transition_length: 900ms
          update_interval: 1800ms
      - pulse:
          name: garage_open
          transition_length: 1500ms
          update_interval: 3000ms

The blue and green down-glow LEDs sit in alternating holes about 14 mm apart, so they don’t blend into one colour. That’s why they’re two separate lights in Home Assistant, not one colour light.

Home Assistant only accepts the boards’ action calls if you let it. In Settings → Devices & services → ESPHome, open each device’s options and allow it to perform Home Assistant actions. Both boards need it. New devices have it off, and the buttons just do nothing.

Home Assistant: the status LED

This automation copies the S3’s voice stage onto the C3’s LED. The slowest pulse is for “something you want to know about while nothing else is happening”. In our room that was the garage door being open. Voice always wins, and when voice goes back to idle the LED falls back to the door. Brightness drops with urgency too (100, 90, 70, 50%), a second clue in a dark room.

- alias: Bedside box - status LED
  mode: restart
  triggers:
    - trigger: state
      entity_id: sensor.bedside_box_voice_stage
    - trigger: state
      entity_id: cover.garage_door
  actions:
    - choose:
        - conditions: "{{ is_state('sensor.bedside_box_voice_stage','listening') }}"
          sequence:
            - action: light.turn_on
              target: {entity_id: light.bedside_box_radar_status_led}
              data: {brightness_pct: 100, effect: listening}
        - conditions: "{{ is_state('sensor.bedside_box_voice_stage','thinking') }}"
          sequence:
            - action: light.turn_on
              target: {entity_id: light.bedside_box_radar_status_led}
              data: {brightness_pct: 90, effect: thinking}
        - conditions: "{{ is_state('sensor.bedside_box_voice_stage','speaking') }}"
          sequence:
            - action: light.turn_on
              target: {entity_id: light.bedside_box_radar_status_led}
              data: {brightness_pct: 70, effect: speaking}
        # voice idle: fall back to the door
        - conditions: "{{ states('cover.garage_door') in ['open','opening'] }}"
          sequence:
            - action: light.turn_on
              target: {entity_id: light.bedside_box_radar_status_led}
              data: {brightness_pct: 50, effect: garage_open}
      default:
        - action: light.turn_off
          target: {entity_id: light.bedside_box_radar_status_led}

Trigger on both entities. If it only watched the voice stage, closing the door would leave the LED pulsing until the next time you talked to it.

Home Assistant: play on the box you pressed

My radio script was written for the lounge speaker. Rather than copy it per room, it got an optional player field that defaults to the lounge, so everything already calling it keeps working and the box passes its own speaker. In scripts.yaml:

play_radio:
  alias: Play the radio
  icon: mdi:radio
  fields:
    player:
      name: Player
      description: Media player to play on. Defaults to the lounge.
      default: media_player.example_speaker
      selector:
        entity:
          domain: media_player
  sequence:
    - action: media_player.play_media
      target:
        entity_id: "{{ player | default('media_player.example_speaker', true) }}"
      data:
        media_content_id: "https://example.com/your-station.m3u8"
        media_content_type: music

The true in default(..., true) matters. Without it, a caller that passes an empty value gets an empty target instead of the default, and the script quietly does nothing.

The fan button calls a toggle script. Something like this does the job: stop the box if it’s playing, otherwise start the radio on it.

bedside_box_radio_toggle:
  alias: Bedside box radio on/off
  sequence:
    - if:
        - condition: state
          entity_id: media_player.bedside_box_media
          state: playing
      then:
        - action: media_player.media_stop
          target:
            entity_id: media_player.bedside_box_media
      else:
        - action: script.play_radio
          data:
            player: media_player.bedside_box_media

The radio stream plays on the box’s plain ESPHome media player. The playlist on the voice button’s triple press goes through Music Assistant instead, so the box has to be added as a player in Music Assistant first, or that press silently does nothing.

Step by step

  1. Pick the room names first. Name both devices room first, before adding them to Home Assistant. Renaming after means chasing entity ids through every automation.
  2. Check the pin budget against the compiled config and the real board pinout before you solder. My wiring plan was one pin short and I only found out when the config was compiled.
  3. Flash both boards over USB first, before anything is soldered. Check which board you’ve got plugged in each time: the S3 and C3 configs aren’t interchangeable.
  4. Bench test with jumper wires, in this order: the two sensors (the boot log’s I2C scan should show 0x76 and 0x23), then the buttons (a jumper from 3.3 V to each button pin should flip it in Home Assistant), the knob, the radar, the LEDs, and audio last because it’s the fiddliest. Each step stands on its own, so a failure points at one thing.
  5. Build the carrier (or hand-wire it). Fit the 10 kΩ on GPIO3, the status LED resistor and the 470 kΩ on the right amp. Leave the C3’s 3V3 pin unconnected. Put the C3 on stacked headers, not flat on the board (see the lessons).
  6. Add both to Home Assistant and allow each to perform Home Assistant actions.
  7. Add the scripts and the status LED automation above.
  8. Fit the top plate last. Leave it running, then calibrate the temperature and humidity against a thermometer.
  9. For later updates, use esphome run (it compiles, then flashes). See the lessons for why.

Testing it

  • Buttons: press each one and watch the Home Assistant log. If you see Referenced entities ... are missing, the box is calling an entity that no longer exists.
  • Radar: on the first bench test it reported presence at 151 cm. Then set Max Distance Gate to the size of the room. Untuned, it sees through the wall and picks up people in the hallway.
  • Radio, microphone, knob and LED: all worked on the first real build.
  • Amp crackle: on that first hand-wired build the amps sometimes crackled when playback restarted. Unplugging either amp cured it, so it was the two amps interacting, and the ESP32 logged nothing, so it was electrical. Both SD pins were tied straight to VIN then. The carrier board swaps that for the 470 kΩ pull-up on one amp, which is how the datasheet does it. As of mid-October I haven’t recorded a result on the crackle with the carrier build, so treat the SD wiring and the 100 µF capacitor near the amps as the first places to look if you hear it.
  • Temperature: with a thermometer beside it reading 25.3 °C and 60%, the raw sensor read 31.8 °C and 51.9%. After the offsets it read 26.2 °C and 59.1%, steady for 6 minutes. Re-measure if the case is opened, the amps are driven harder or the box moves.

Lessons learnt

The first circuit board used the wrong footprint for the C3. A footprint is the pattern of pads the part solders into. I’d drawn the board for a 14-pad XIAO C3, but the board I actually had was a 16-pad C3 SuperMini. Ten boards were made. The power pins were mirrored, so it would have put 5 V onto the 3.3 V rail. The pads I’d tied to ground as “spare” landed on live pins, including GPIO9, which forces the chip into download mode at boot if it’s grounded. I found it with the iron in my hand, asking whether to trim a leg off to make it fit. The board passed the design checker with zero errors, because that checker looks at copper spacing, not whether the footprint matches the part. Worse, my own build script had a comment saying the real part had more pins, and then talked itself out of it. Writing a problem down isn’t fixing it. Rev B was redrawn for the SuperMini, with a check that compares the footprint against the datasheet every time the board is built.

Eight LEDs on rev B were drawn backwards. In the KiCad LED footprint I used, pad 1 is the cathode. My script put the positive supply on pad 1. A second, independent look at the board caught it before the order, along with three other faults: the C3’s 3.3 V pin tied to the S3’s 3.3 V (two regulators fighting each other), a resistor to ground that can’t select the right channel on a MAX98357A (it needs a pull-up instead), and every track drawn 0.4 mm wide, power included.

The fuse holder didn’t fit. The footprint had two holes. The real holder has four prongs, two per clip. I fitted it by cutting the two inner prongs off. The corrected footprint has four smaller holes and has to go on the next board.

The C3 wouldn’t join Wi-Fi sitting flat on the board. It joined fine lifted off the board or on flying leads, and failed every time it sat flat. Signal strength was -29 dBm on two-inch leads and -54 to -58 dBm seated. I spent a long time chasing power supply theories, and the failure code sent me the wrong way: AUTH_EXPIRE sounds like a password problem, but it means the access point never heard the C3’s first transmission. Receive worked, transmit didn’t. The cause was the C3’s chip antenna sitting over solid ground copper on both layers of my board, which detunes it. That’s confirmed: a fresh C3 on stacked headers, about 12 mm above the board, works perfectly, and the extra height also made both USB ports reachable. The next board gets no copper under the antenna (and at least 5 mm past it), or the antenna hanging off the board edge, or a C3 with an external antenna socket, and the serial port moves off GPIO20/21, which are pads at the antenna end. If you’re chasing a Wi-Fi fault, write down where the module physically sat in every test. That one detail was missing for three sessions.

The pin plan was one short. On paper every S3 pin was used, and the amps’ data out still had nowhere to go. Mic data in and amp data out can’t share a pin. The fix was moving the LED to the C3, which is why the status light goes through Home Assistant.

The mic and the speakers can’t share one I2S bus. ESPHome locks a bus for whoever is using it, and the wake word holds the mic open all the time. On one bus the speaker never got a turn: the log said Parent bus is busy once a second and no sound ever came out. The S3 has two I2S ports, so the mic got its own. The two pins for its clocks came from moving the spare and voice buttons to the C3.

Music played for a few seconds, then stopped. With only an announcement pipeline, music was being played as an announcement, which is built to play a short clip and stop. It also ran at 16 kHz, a speech rate, which made music scratchy. Music needs the media_pipeline. ESPHome won’t let two pipelines share one speaker, or two speakers share one pin, so the mixer speaker gives each pipeline its own source and mixes them into the one real output.

Music broke up at random while the wake word was running. The wake word runs a small model on every scrap of audio, and decoding a music stream at the same time starved it. The log filled with Not enough free bytes in ring buffer. You can’t say the wake word over loud music anyway, so the box stops listening while music plays and starts again when it stops.

Phantom fan presses waiting to happen. GPIO3 on the S3 is a strapping pin with no internal pull resistors. pulldown: true is silently ignored. Without an external 10 kΩ it floats and gives random presses: horrible to find once the case is closed.

The box runs 6.5 °C hot. I’d guessed 1 to 3 °C of self-heating and put in -1.5 as a placeholder. It was badly wrong. Trust the humidity offset less: the case is partly sealed and holds its own moisture, so that offset only holds near the humidity it was calibrated at.

esphome upload flashed a week-old build and said it worked. upload sends the last compiled file. It doesn’t compile. It reported “OTA successful” and my change wasn’t in it. Use esphome run, or compile first.

A renamed light killed two controls silently. I renamed a bulb in Home Assistant and the light button and knob went dead. The box was still calling the old name. Nothing on the box complained, only a line in the Home Assistant log. When you rename a light, search your ESPHome files for it too.

The round screen crashed every time it heard the wake word. When voice started, the single core was streaming the mic and refreshing the screen at the same time, and it fell over. It wasn’t Wi-Fi: it crashed on USB power with no packet loss too. The fix was to stop the screen refreshing while it listens and start it again when the voice request ends or errors. Slowing the idle refresh from 200 ms to 1 second also cleared the wake word warnings. Its USB serial console was silent too, so I read its logs from the device’s web page or through Home Assistant instead.

Questions and comments

Loading comments…

    Your name and comment show publicly. To stop spam, a scrambled code made from your internet address is kept, never the address itself. Comments with links wait for a quick check before they show. Be decent: I'll remove anything that isn't.