Skip to content

MQTT ​

The speaker can announce itself on an MQTT broker the way ESPHome devices do. Home Assistant's MQTT integration then finds it with its controls, and anything else on the broker (Node-RED, openHAB, scripts) can read and set them. It works next to the ESPHome API or instead of it.

It is off until the owner turns it on.

Connecting ​

  1. Open Settings on the speaker's web interface. Under MQTT, enter the Broker (host name or IP address) and Port: 1883, or 8883 with Encrypted (TLS).
  2. Enter User name and Password if the broker wants them. For Home Assistant's Mosquitto add-on, create a Home Assistant user for the speaker and use it.
  3. Choose Save, then turn on Announce the speaker on an MQTT broker. The part shows Connected once the broker took the speaker.

In Home Assistant the speaker shows up under Settings → Devices & services → MQTT with its entities. Nothing has to be confirmed.

If the speaker cannot connect, the part says why (wrong password, name not found, refused) and the speaker tries again, waiting longer each time, up to a minute between attempts.

What the broker gets ​

TopicContents
<prefix>/statusonline, or offline when the speaker switches MQTT off or disappears (the broker's last will). Retained.
<prefix>/<component>/<object_id>/stateThe entity's state. Retained.
<prefix>/<component>/<object_id>/commandCommands, from Home Assistant or anyone allowed to publish there.
<discovery>/<component>/boombox_<mac>/<object_id>/configHome Assistant's discovery. Retained.

<prefix> is the speaker's network name (boombox) unless you choose a Topic prefix; it follows a rename, like ESPHome's. <discovery> is homeassistant unless you changed Home Assistant's discovery prefix.

EntityComponentStateCommands
Playbacksensorplaying, paused, announcing, idle
Volumenumber0–100, the speaker's own volume, capped by the limita number
MuteswitchON, OFFON, OFF
Play, Pause, Stop, Next track, Previous trackbuttonPRESS
Coversensorthe cover's address on the speaker, None without one
Position, Durationsensorseconds
Title, Artist, Album, Playing fromsensorthe text, None without a phone
Audio output, Listen onselectthe option's labela label
Maximum volumenumber10–100a number
ScreenswitchON, OFFON, OFF

Home Assistant has no MQTT media player, so the speaker's player appears as what it is made of: the playback sensor, volume, mute and the buttons. Text to speech, announcements and media URLs stay with the ESPHome API, and so do Restart and Bluetooth pairing: anyone who may publish on the broker could otherwise restart the speaker, or open it to pairing with any device in range. An update clears their old announcements, so Home Assistant drops them from the MQTT device.

Switching MQTT off on the speaker removes the entities from Home Assistant (empty retained discovery messages) and sets the status to offline. Changing the discovery prefix moves them.

Example, from any machine with the Mosquitto clients:

bash
mosquitto_sub -h broker.lan -u user -P pass -v -t 'boombox/#'
mosquitto_pub -h broker.lan -u user -P pass -t boombox/number/volume/command -m 30
mosquitto_pub -h broker.lan -u user -P pass -t boombox/button/pause/command -m PRESS

Security ​

  • Whoever may publish to <prefix>/+/+/command on the broker controls what it plays, its volume and output. Give the speaker a broker user of its own and restrict the topics with the broker's ACLs.
  • Without TLS the password and every message cross the network in plain text. With TLS the speaker checks the broker's certificate against the system's authorities, so a self-signed certificate is refused.
  • The password stays in /var/lib/boombox/config.json (root only). Pages only learn whether one is saved; Remove password deletes it.
  • The TV's account neither sees nor changes these settings, at any access level.
  • Packets larger than 64 KB end the connection, and a broker that stops reading is left after ten seconds: neither can hold up the music.

How it works ​

PartWhere
MQTT 3.1.1 packetspackages/boombox-agent/src/Mqtt/Packet.php, PacketReader.php
The connection: keep-alive, last will, reconnectsMqtt/MqttClient.php
Discovery, states, commandsMqtt/Discovery.php; the entities' mqtt*() methods in EspHome/Entity/
Settings and lifecycleService/MqttService.php

States go out at QoS 0 and retained; all of them are sent again after every connect. Commands at QoS 1 are acknowledged.

Development ​

DDEV runs a Mosquitto broker as mosquitto:1883, anonymous:

bash
ddev boombox-agent client mqtt.settings.set '{"enabled":true,"host":"mosquitto"}'
ddev exec -s mosquitto mosquitto_sub -v -t '#'
ddev exec -s mosquitto mosquitto_pub -t boombox/switch/mute/command -m ON

The Playwright spec mqtt.spec.ts connects to it.

Troubleshooting ​

SymptomCause and fix
"Wrong user name or password"Check the credentials; with Home Assistant's Mosquitto add-on, a Home Assistant user.
"The broker refused the connection"Nothing listens there: host and port, and whether the broker runs.
"TLS failed"The certificate is self-signed or for another name. Use one from a public authority, or plain MQTT inside the LAN.
Connected, but nothing in Home AssistantHome Assistant's MQTT integration uses another discovery prefix, or another broker. Compare Discovery prefix.
Entities show "Unavailable"<prefix>/status is offline: the speaker lost the broker. The MQTT part on its Settings page says why.