Family Encyclopedia >> Home & Garden

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

As a home automation expert with years of experience building smart systems, I've seen the frustration many face: devices like Amazon Echo respond brilliantly to voice commands but can't proactively announce messages. That's where Sonos speakers shine, especially when paired with a Raspberry Pi. In this guide, I'll walk you through setting up reliable voice notifications on your Sonos system using proven tools like IFTTT recipes and OpenHAB integrations.

Note: The native Sonos binding for OpenHAB can cause memory leaks due to a faulty UPnP library. Skip it and follow this battle-tested method instead.

This setup works best on a Raspberry Pi running Raspbian (though any Linux server should suffice). I'm using a Pi also hosting OpenHAB, our go-to open-source home automation platform. For details, see our Introduction to OpenHAB Home Automation on Raspberry Pi. Assume you have SSH access; learn how in our Setting up your Raspberry Pi for headless use with SSH guide.

What You'll Need

  • Raspberry Pi 2 (older models work with minor tweaks)
  • At least one Sonos speaker (Sonos-only; other systems unsupported)
  • Free VoiceRSS.org account (grab your API key for text-to-speech)

Install Node.js (v5.12)

Check your Node version:

node -v

Version 6 is unsupported. Uninstall it first if present. If no v5.x or errors occur, install as follows (use armv6l for older Pis):

wget https://nodejs.org/download/release/latest-v5.x/node-v5.12.0-linux-armv7l.tar.gz
tar -xvf node-v5.12.0-linux-armv7l.tar.gz
cd node-v5.12.0-linux-armv7l
sudo cp -R * /usr/local/

Verify:

node -v

Install NPM and dependencies:

sudo apt-get install npm
sudo npm install -g npm
sudo npm install -g node-gyp

Sonos HTTP API

This tool runs a local web server for controlling Sonos via simple HTTP calls, perfect for voice announcements.

git clone https://github.com/jishi/node-sonos-http-api.git sonos
cd sonos
npm install --production
npm start

Missing modules? Run npm install [module] and retry. C++11 errors? Fix with:

sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternative --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternative --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternative --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternative --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

Success looks like:

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

API format: https://[SERVER_IP]:5005/[ROOM]/[ACTION]
Example: https://192.168.1.99:5005/kitchen/playlist/chillout

For announcements: https://192.168.1.99:5005/kitchen/say/make%20use%20of%20is%20awesome/en-gb

First try prompts for VoiceRSS key. Edit nano settings.json and add:

"voicerss": "YOURAPIKEY"

(CTRL+X, Y to save.) Restart and test. Use en-us for US English.

Auto-start on boot: sudo nano /etc/rc.local, add before exit 0:

node /home/pi/sonos/server.js </dev/null &

Now ping URLs from anywhere on your LAN for instant announcements.

OpenHAB Motion Notifications

Example: Announce garden motion.

rule "Motion detected in garden"
when
    Item Garden_Motion changed
then
    var String message = "You have a visitor"
    sendHttpGetRequest("https://localhost:5005/kitchen/say/" + message.encode("UTF-8") + "/en-gb")
end

Integrate into any rule effortlessly.

Daily Weather Report: IFTTT to OpenHAB to Sonos

Enable My.OpenHAB for secure external access (setup in our OpenHAB guide).

Create OpenHAB string item Todays_Weather. Initialize: https://raspberrypi.local:8080/CMD?Todays_Weather=Sunny (adjust host/IP).

Verify in My.OpenHAB Items list.

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

In IFTTT: Weather trigger (set location/time), My.OpenHAB action updating Todays_Weather.

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

OpenHAB rule:

rule "Announce daily weather"
when
    Item Todays_Weather received update
then
    sendHttpGetRequest("https://localhost:5005/kitchen/say/" + Todays_Weather.state.toString.encode("UTF-8") + "/en-gb")
end

Test: https://raspberrypi.local:8080/CMD?Todays_Weather="Cloudy with a chance of meatballs."

Direct IFTTT Integration with If-This-Then-Node

For public IFTTT access without OpenHAB: Use dynamic DNS (e.g., DuckDNS or router's). Forward port 80 to Pi's 1337. Reserve Pi's IP.

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

git clone https://github.com/sebauer/if-this-then-node.git
cd if-this-then-node
npm install
node server.js

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

Edit config.js, restart.

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

Test: [DDNS]/ifttn/ shows uptime. Auto-start: Add to /etc/rc.local node /home/pi/if-this-then-node/server.js </dev/null &.

Custom Sonos plugin:

cd plugins
wget https://gist.githubusercontent.com/jamesabruce/4af8db24ba3452b94877/raw/d11c1cff3aa44dbb6a738eeb15202f3db461de75/sonos.js
npm install request

Restart server. Plugin uses /sayall/ for all speakers or target specific.

Test via IFTTT Maker:

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

URL: [DDNS]/ifttn/, POST JSON:

{
  "action": "sonos",
  "user": "YOURUSER",
  "pw": "YOURPASSWORD",
  "message": "Dinner is ready!"
}

Expect log scans; normal internet noise.

How to Set Up Voice Announcements on Sonos Speakers Using Raspberry Pi

Next Steps

With 350 daily VoiceRSS requests (~1 every 4 mins), unleash endless announcements. Share your recipes in comments!