Link Search Menu Expand Document

Getting started

Using sonos2mqtt is really easy.

  1. Prerequisites
  2. Run sonos2mqtt in docker
    1. Docker-compose
  3. Local installation
  4. Configuration
    1. Configuration by json file


  • (local) mqtt server
  • always on (single board) computer

Run sonos2mqtt in docker

Using this library in docker is the preferred way.

  1. Create an .env file with the following settings.
  2. Set the required values.
  3. Run docker run --env-file .env -p 6329:6329 svrooij/sonos2mqtt
# Set the IP of one known sonos speaker (device discovery doesnt always work inside docker.)
# Set the mqtt connection string
# Publish distinct if your want
# Set the IP of the docker host (so node-sonos-ts knows where the events should be send to)
# Set text-to-speech endpoint (optional)

See configuration for additional settings.

This app makes heavy use of events, so you’ll have to make sure they still work. That is why you need to expose the listening port (6329), changing the port will cause problems. The library will automaticcally subscribe to events from the sonos device, but because you’re running in docker it cannot figure out the IP by itself. You set the IP of the docker host in the SONOS_LISTENER_HOST environment variable. This is how the events flow.

================              ===============              ==============
| Sonos Device |  == HTTP =>  | Docker host |  == HTTP =>  | sonos2mqtt |
================              ===============              ==============

We automatically build a multi-architecture image for amd64, arm64, armv7 and i386. This means you can run sonos2mqtt in docker on almost any device.


version: "3.7"
    image: svrooij/sonos2mqtt
    restart: unless-stopped
      - "6329:6329"
      - SONOS2MQTT_DEVICE= # Service discovery doesn't work very well inside docker, so start with one device.
      - SONOS2MQTT_MQTT=mqtt://emqx:1883 # EMQX is a nice mqtt broker
      # - SONOS2MQTT_DISTINCT=true # if your want distinct topics
      - SONOS_LISTENER_HOST= # Docker host IP
      - SONOS_TTS_ENDPOINT=http://sonos-tts:5601/api/generate # If you deployed the TTS with the same docker-compose
      - emqx

# You can skip the TTS server if you want. See
# Set the amazon keys to your own
# Set the SONOS_TTS_CACHE_URI to http://[ip_of_docker_host]:5601/cache
    image: svrooij/sonos-tts-polly
      - "5601:5601"
      - SONOS_TTS_AMAZON_KEY=your_key_id_here
      - SONOS_TTS_AMAZON_SECRET=your_secret_access_token_here
      - SONOS_TTS_AMAZON_REGION=eu-west-1

# Optional MQTT server (I like emqx over mosquitto)
    image: emqx/emqx
    restart: unless-stopped
      - "1883:1883"
      - "18083:18083"

Local installation

You can also use sonos2mqtt on every device that has node installed. The latest LTS (long-time-support) version is always recommended, but it should run on v10 or higher. When creating an issue please verify that you’re on the latest LTS (v12 for now) or higher.

sudo npm install -g sonos2mqtt

You have to make sure it runs in the background yourself. You could check out PM2 for a node process manager (for auto restarts in case of crash).


Every setting of this library can be set with environment variables prefixed with SONOS2MQTT_. Like SONOS2MQTT_PREFIX=music to change the topic prefix to music.

sonos2mqtt 0.0.0-development
A smarthome bridge between your sonos system and a mqtt server.

Usage: index.js [options]

  --prefix           instance name. used as prefix for all topics
                                                              [default: "sonos"]
  --mqtt             mqtt broker url. See
                                                   [default: "mqtt://"]
  --clientid         Specify the client id to be used
  --log              Set the loglevel
           [choices: "warning", "information", "debug"] [default: "information"]
  -d, --distinct     Publish distinct track states    [boolean] [default: false]
  -h, --help         Show help                                         [boolean]
  --ttslang          Default TTS language                     [default: "en-US"]
  --ttsendpoint      Default endpoint for text-to-speech
  --device           Start with one known IP instead of device discovery.
  --discovery        Emit retained auto-discovery messages for each player.
  --discoveryprefix  The prefix for the discovery messages
                                                      [default: "homeassistant"]
  --friendlynames    Use device name or uuid in topics (except the united topic,
                     always uuid)                      [choices: "name", "uuid"]
  --version          Show version number                               [boolean]

You can configure the mqtt url by setting a supported URL.

Most used format is mqtt(s)://[user]:[password]@[host]:[port] like mqtt://user:password@hostname:1883, or mqtts://user:password@hostname:8883 for a mqtt server supporting TLS.

Configuration by json file

Some systems don’t like the preferred docker way of configuration (which is environment settings), so it will also check for a json file when starting up.

  • Default path: /data/config.json
  • Override by setting: CONFIG_PATH

Sample file:

  "mqtt": "",
  "prefix": "sonos",
  "distinct": false,
  "device": "192.168.x.x",
  "ttslang": "en-US",
  "ttsendpoint": "",
  "discovery": false,
  "discoveryprefix": "homeassistant",
  "log": "information",
  "clientid": "",
  "friendlynames": "name"