The dream of any smart home enthusiast is a home you can talk to, but the reality is far from that.
Amazon Echo, for example, lets you use any number of voice features, but you have to start a dialogue with a question — you can’t just ask her to announce an important message.
You you can do it with a Sonos system and a little Raspberry Pi magic. Today, I’ll show you how to set up voice notifications on your Sonos system by introducing some helpful IFTTT recipes, OpenHAB integrations, and more to make use of the notifications feature.
Please note that there is a built-in Sonos binding for OpenHAB, but it is known to cause memory issues due to a faulty uPnP library. I would suggest skipping this for now and using the method from this tutorial instead.
- Raspberry Pi 2 (older models should work, but check for specific changes in the instructions)
- At least one Sonos speaker (other audio systems are not supported, this guide is for Sonos only)
- Free account on VoiceRSS.org [больше не доступен]. Sign up, then find your API key, which we’ll need later to create voice messages.
Last installation node
Check which version of Node you have by typing:
Please note that version 6 is not supported. If you have Node 6, uninstall it first and then follow the instructions below to install v5.5.
If you don’t have v5 or get a not found error, follow these instructions to install Node. The following command assumes a Raspberry Pi 2; for older models use armv6l instead of armv7l .
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
Confirm again by typing:
And you should see v5.12 (or whatever the latest you downloaded).
Next, we have a few Node modules to install. We also need a Node Package Manager.
sudo apt-get install npm sudo npm install -g npm sudo npm install -g node-gyp
These are the prerequisites, now the fun part.
Sonos HTTP API
The Sonos HTTP API creates a web server on the local network, which allows us to ping a URL with a message to announce to Sonos (and control it remotely if you wish, although this tutorial only covers the voice announcement aspect).
git clone https://github.com/jishi/node-sonos-http-api.git sonos cd sonos npm install --production npm start
If you see a message that such and such a module was not found, just run another npm installation and module name, then try again run npm . If you are experiencing errors related to «requires C++11 compiler» fix them with the following commands:
sudo apt-get install gcc-4.8 g++-4.8 sudo update-alternatives --install/usr/bin/gccgcc/usr/bin/gcc-4.6 20 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
Eventually you should see something like this:
The server is now running, interacting with Sonos. The format of this API is simple:
http: // [IP-адрес СЕРВЕРА]: 5005 / [ИМЯ КОМНАТЫ] / [ДЕЙСТВИЕ]
Or as a specific example:
The action we are interested in is the «say» command, used as follows:
You will hear an error message when registering for an API key on VoiceRSS.org. You should already have done this, so type the following and paste in your API key as appropriate:
(Press CTRL-X, Y to save the file)
Restart the server and ping the URL again. After a few seconds, you will hear a delightful English voice (although you will change the end of the URL to en-us, if you want to). To get the Sonos HTTP API server to start again after restarting the Pi:
sudo nano /etc/rc.local
Add line before exit 0 :
sudo node /home/pi/sonos/server.js < /dev/null &
You now have the ability to create voice messages from anywhere on the local network by simply pinging a URL, so the possibilities are wide open at this stage. If you're struggling for ideas, read on for some helpful notifications I've set up.
OpenHAB event notifications
Let's look at a simple example first: motion detection. This is a common use for lights, but you might also want a voice alert if it's a motion sensor in a low traffic area, or perhaps as a direct warning that someone is walking down a garden path.
rule "Garden motion detected" when Item Garden_Motion changed then var String message = "You have a visitor" sendHttpGetRequest("http://localhost:5005/kitchen/say/"+message.encode("UTF-8")+"/en-gb") end
You should see how you can integrate these simple voice notifications into any of your rules, but let's try something more complex.