Skip to content

Home Assistant ​

The speaker joins Home Assistant through Home Assistant's built-in ESPHome integration. Nothing has to be installed in Home Assistant: the agent speaks ESPHome's native API, so Home Assistant discovers and controls the speaker as if it ran ESPHome firmware.

It is off until the owner turns it on.

Adding the speaker ​

  1. Open Settings on the speaker's web interface. Under Home Assistant, turn on Let Home Assistant control the speaker. The speaker now waits two minutes for Home Assistant.
  2. In Home Assistant, open Settings → Devices & services. The speaker shows up as a discovered ESPHome device under its Bluetooth name. Choose Add, then Submit.
  3. Home Assistant adds the speaker and gives it an encryption key of its own. The speaker's page now says Connected.

If the speaker is not discovered (mDNS does not cross every network), add the ESPHome integration by hand with host boombox.local (or the speaker's IP address) and port 6053, while the speaker is waiting.

The window closes after two minutes. Let Home Assistant add the speaker opens it again. While it is open, whichever device on the network connects first adopts the speaker; the page then names the address it was added from, so a stranger's adoption shows (Forget Home Assistant… undoes it).

What Home Assistant gets ​

EntityTypeWhat it does
(the speaker's name)Media playerState of the phone's playback; volume and mute of the speaker itself (the same as Settings → Audio, capped by the volume limit); play, pause, stop; text to speech, announcements and media URLs.
Next track, Previous trackButtonSkip on the connected phone.
Title, Artist, AlbumSensorWhat the phone plays. Unknown without a phone.
Playing fromSensorThe phone that plays, or the connected ones.
CoverSensorThe address of the playing song's cover on the speaker (http://boombox.local/cover/….jpg), while the speaker looks covers up (Settings → Recording → Song covers). Unknown otherwise.
Position, DurationSensor (seconds)How far into the song, and how long it is. Position counts on every second while a phone plays.
Bluetooth pairingSwitch (configuration)Opens the pairing window for two minutes; off closes it.
Audio outputSelect (configuration)Built-in amplifier, HDMI, USB.
Listen onSelect (configuration)Speakers, or headphones and line out (amplifier off). Needs the amplifier enable line.
Maximum volumeNumber (configuration)The volume limit, 10–100 %.
RestartButton (configuration)Restarts the speaker.
ScreenSwitch (configuration)The TV picture and HDMI port. Off sleeps them until something plays; on wakes them.

The volume is the speaker's own, so Home Assistant controls it whether a phone is connected or not. Bluetooth has no "stop", so stop pauses the phone.

Showing the song on a dashboard ​

ESPHome's media player carries only its state, volume and mute, so Home Assistant cannot show the title in the speaker's media player card. The song arrives as the Title, Artist, Album and Playing from sensors. Home Assistant's universal media player does not help here: it can override state and volume, but takes title, artist and album only from its child.

A card that puts the sensors above the controls does it. For previous and next in the card, wrap the speaker in a universal media player first, in configuration.yaml (restart Home Assistant afterwards):

yaml
media_player:
  - platform: universal
    name: Boombox Wohnzimmer Jochen
    children:
      - media_player.boombox
    attributes:
      state: media_player.boombox
      volume_level: media_player.boombox|volume_level
      is_volume_muted: media_player.boombox|is_volume_muted
    commands:
      media_play_pause:
        action: media_player.media_play_pause
        target: { entity_id: media_player.boombox }
      media_next_track:
        action: button.press
        target: { entity_id: button.boombox_next_track }
      media_previous_track:
        action: button.press
        target: { entity_id: button.boombox_previous_track }
      volume_set:
        action: media_player.volume_set
        target: { entity_id: media_player.boombox }
        data: { volume_level: "{{ volume_level }}" }

Then, on the dashboard, a manual card. It shows the song, a bar with the time like the speaker's own page, and the controls:

yaml
type: vertical-stack
cards:
  - type: markdown
    content: >
      {% set title = states('sensor.boombox_title') %}
      {% if title not in ['unknown', 'unavailable', '', 'None'] %}
      {% set cover = states('sensor.boombox_cover') %}
      {% if cover.startswith('http') %}<img src="{{ cover }}" alt="" width="160">{% endif %}

      ## {{ title }}
      {{ states('sensor.boombox_artist') }}{% if states('sensor.boombox_album') not in ['unknown', 'unavailable', ''] %} · {{ states('sensor.boombox_album') }}{% endif %}

      {% set position = states('sensor.boombox_position') | int(0) %}
      {% set duration = states('sensor.boombox_duration') | int(0) %}
      {% if duration > 0 %}
      {% set filled = (position * 30 / duration) | int %}
      `{{ '━' * filled }}{{ '─' * (30 - filled) }}`
      {{ '%d:%02d' | format(position // 60, position % 60) }} / {{ '%d:%02d' | format(duration // 60, duration % 60) }}
      {% endif %}

      <small>from {{ states('sensor.boombox_playing_from') }}</small>
      {% else %}
      Nothing playing
      {% endif %}
  - type: media-control
    entity: media_player.boombox_wohnzimmer_jochen

Home Assistant's own media-control card draws its bar from the media player's position, which ESPHome cannot send; hence the bar above it.

The cover comes from the speaker itself, without a login: its name is a hash of artist and album. If Home Assistant runs on HTTPS, the browser refuses a picture from the speaker's plain http:// address; open the dashboard over HTTP on the LAN, or leave the picture out.

The position changes every second while a phone plays. To keep it out of Home Assistant's history database, add to configuration.yaml:

yaml
recorder:
  exclude:
    entities:
      - sensor.boombox_position

The entity IDs follow the names in Home Assistant (here "Boombox" and "Boombox Wohnzimmer Jochen"); check them under Settings → Devices & services → Entities if yours differ.

Announcements and text to speech ​

tts.speak, media_player.play_media and announcements work. Home Assistant converts whatever it plays to WAV at 48 kHz, 16-bit stereo, which the speaker asks for, so the speaker needs no decoder. The agent downloads the stream with curl and plays it with aplay into boombox_direct, beside the phones: the volume and the limit apply, both are mixed, and the stream is never recorded.

An announcement pauses a playing phone and resumes it afterwards. Other media leaves the phone paused. While Home Assistant's media plays, the media player shows announcing or playing, and pause or stop ends it.

Security ​

  • The API listens on TCP 6053 only while the setting is on.
  • Adoption works like Bluetooth pairing, and like ESPHome's own provisioning. Inside the window, Home Assistant may connect without a key and hand over a key it generated.
    • The key is only accepted through a Noise session under the well-known all-zero key, never in plain text. That stops eavesdropping, but not someone active on the network during those minutes. That is why the window is short and only the owner opens it.
    • A session without the key may only read the entities and hand over a key. It cannot command the speaker: no pairing, no restart, no URLs.
    • Such sessions end when the window closes, and on adoption, forget and switching off.
  • After adoption the speaker only accepts Noise sessions (Noise_NNpsk0_25519_ChaChaPoly_SHA256) under that key. Plaintext connections and other keys are refused. Outside the window, a speaker without a key turns every connection away after its hello.
  • Forget Home Assistant drops the key and every session, and opens a new window. Use it when Home Assistant was reinstalled. A factory reset forgets the key too.
  • Show key reveals the key to the owner only. It is never part of the state pages receive live. /var/lib/boombox/config.json is root-only.
  • Limits keep a misbehaving client on the LAN from tying up the agent, and with it the music:
    • 8 connections, 4 per address;
    • 10 s to say hello, at most 4 messages before it, and no device information before it;
    • a client that stops reading is cut off once 64 KB of answers wait for it;
    • a disconnected client gets 2 s to leave.
  • Media URLs:
    • Only http and https, to another machine: localhost, loopback, link-local and "this host" addresses are refused, in any spelling curl understands. Host names are resolved by curl; the check covers addresses written into the URL.
    • curl runs as nobody, reads no .curlrc and follows no redirects.
    • At most one stream starts per second.
  • Long-running tools (curl, aplay, the monitors) do not inherit the agent's sockets, so a dropped client really is disconnected.

How it works ​

PartWhere
Protobuf codec, plaintext and Noise framing, the NNpsk0 handshake on ext-sodiumpackages/boombox-agent/src/EspHome/{Protobuf,Transport,Noise}
One connection: hello, device info, entities, states, commands, key provisioningEspHome/ApiConnection.php
TCP server, pushing changed statesEspHome/ApiServer.php
The setting, the adoption window, the key, the MACService/HomeAssistantService.php
The entities and the media playerService/SpeakerEntities.php, Service/SpeakerMediaPlayer.php
StreamsService/StreamService.php, AudioBackend::playStream()
mDNSBackend/Linux/AvahiAnnouncer.php writes /etc/avahi/services/boombox-esphome.service

The implementation follows ESPHome's API 1.17 (ESPHome 2026.9): message numbers from aioesphomeapi's api.proto, the frame layout and handshake prologue from the firmware's api_frame_helper_noise.cpp, and the provisioning rules from api_connection.cpp. The speaker reports Boombox.Bluetooth Speaker as its project, which Home Assistant shows as manufacturer and model, and links its web interface on port 80.

Home Assistant identifies the speaker by MAC address. The agent keeps the first one it sees, the Wi-Fi interface's, in /var/lib/boombox/config.json, so the speaker keeps its identity.

Testing against Home Assistant's client ​

packages/boombox-agent/tests/Interop/run.sh starts a throwaway simulated agent and drives it with aioesphomeapi, the library Home Assistant's integration uses. It covers discovery, adoption, key-only access, every kind of entity, live state pushes, an announcement, the closed window and switching off. It needs PHP with ext-sodium and uv (or Python with venv), so it runs on the host rather than in DDEV:

bash
packages/boombox-agent/tests/Interop/run.sh

In DDEV the agent listens on port 6053 inside the web container, without mDNS. The Playwright spec homeassistant.spec.ts covers the page; it adopts the speaker through ddev boombox-sim homeassistant_adopt.

Troubleshooting ​

SymptomCause and fix
Home Assistant does not discover the speakermDNS does not reach Home Assistant (VLANs, Docker without host networking). Add it by hand: ESPHome, host and port 6053. Check /etc/avahi/services/boombox-esphome.service exists.
"Provisioning closed" or the dialog failsThe window closed. Open it again on the speaker's page, then retry in Home Assistant.
Home Assistant asks for an encryption keyThe speaker was adopted before. Either paste the key from Show key, or Forget Home Assistant and add it again.
"Invalid encryption key" after reinstalling Home AssistantThe new Home Assistant does not know the old key. Forget Home Assistant on the speaker, then add it again.
"The port is in use"Something else listens on 6053. sudo ss -ltnp 'sport = :6053'.
Announcements are silentjournalctl -u boombox-agent shows curl's or aplay's error. The speaker must reach Home Assistant's URL (its internal URL setting).