Integrate Sonos with Google Assistant through IFTTT

I've been playing around with ways to control my Sonos speakers with voice command for a while now, see here. I recently moved from an iPhone to a Google Pixel XL which brings with it the Google Assistant.

Google Assistant is integrated with IFTTT, so you can use the Maker service to call the node-sonos-http-api running within your network. Here's how.

Sonos API with IFTTT

Ok Google, launch toddler tunes in the kitchen

You will need

  • Google Assistant enabled device
  • Sonos device (any)
  • an always on computer capable of running node.js (RasPi, NAS, Mac/PC)
  • to be comfortable with terminal/command line

    Steps

    1. Setup jishi's node-sonos-http-api on a computer on the same network as your Sonos. A RasPi is a great device for this or run this on your NAS through docker. (I have this running on a QNAP NAS).

    For this to work, computer must be always on and accessible over the web. To find out how to enable this, look for instructions here.

    When you're able to reach http://your-ip-address:5005/zones and get a response back, move to the next step.

  1. Create Favourites or Playlists in your Sonos app
  2. Log in (or sign up) to IFTTT

    • Click on My Applet > New Applet
    • Click on +this
    • Choose Google Assistant as the service
    • Choose Say a specific phrase as the trigger
    • Type in a phrase e.g. launch $ in the kitchen
    • Click on Create Trigger
    • Click on +that
    • Choose Maker as the action service
    • Choose Make a web request as the action
    • In the URL field, enter the sonos-api url as like so -http://your-ip-address:5005/kitchen/favorite/{{TextField}}
    • Choose method Get
    • Click Create Action
    • Click Finish
  3. Say "OK Google, launch classic rock in the kitchen", the favourite "classic rock" should start playing in the kitchen.
  4. You now have limited control of Sonos with Google Assistant.

The difference between this and the Echo integration, is that you can call favourite/playlist dynamically using the applet ingredient define by '$' above.

AThe URL format to follow is http://your-ip-address:5005/{room name}/favorite/{favorite name} or http://your-ip-address:5005/{room name}/playlist/{playlist name}

For other actions such as pause/play the URL format is http://your-ip-address:5005/{room name}/{action}

e.g.

  • Classic rock in the lounge (http://your-ip-address:5005/lounge/favorite/classicrock)
  • Pink floyd in the bedroom (http://your-ip-address:5005/bedroom/playlist/pink floyd)
  • To pause, use a phrase like "living room stop" http://your-ip-address:5005/living room/pause

Checkout node-sonos-http-api for more examples.

How well does it work?

Same conditions apply, if you have a manageable number of devices and have created favourites and playists in the Sonos app, this gives you limited voice control. Similarly, you cannot group or switch rooms as long you have the right triggers created and remember the trigger phrases.

On the plus side, you can pass the favourites/playlists dynamically.

How to integrate Amazon Echo and Sonos

Sonos is a fantastic product, the speakers sound great and no one has done multi-room audio better. Having said that, it does have a minor annoyance - the Sonos app. It does a decent job of managing the connected services and speakers, but searching for and playing music sometimes involves too many steps.

So when Sonos announced integration with Amazon Echo late 2016, I immediately bought an Echo Dot. Echo devices are not officially supported in Australia, so to setup there was some 'hackery' involved but process wasn't difficult. Since the announcement howerver, owners of these devices have been waiting for the Sonos/Echo integration without an official word on timeline.

So, if like me, you are too impatient for the beta to drop and want to control your Sonos speakers with voice commands right now, here are a few options.

Option 1: The Easy Option

You will need

  • an Amazon Echo Dot
  • Sonos Play:5
  • 3.5mm male-to-male audio cable

Steps

  1. Plug one end of the audio cable into the Play:5 and the other end into Echo Dot. For best results, keep them at-least 3ft apart, further the better.
  2. Using the Sonos app, set the Play:5 to line-in and enable AutoPlay
    • Launch the Sonos app on your phone or tablet, tap the menu in the top left corner
    • Scroll to the last option in the menu, tap on Settings, tap on Room Settings
    • On the next screen, tap the Sonos device that your Echo Dot is plugged into (for example, mine is named Kitchen)
    • Tap Line-In
    • Tap Autoplay Room and select the name of your Sonos device
  3. That's it, all audio from Echo Dot will now streams through your Sonos speaker.

How well does it work?

As long you're operating within the confines of music services supported by Amazon on the Echo, you'll be happy. Voice commands to control music only work if you have Spotify or Amazon Prime music.

You do not get control over your Sonos music integrations, so if you have Apple Music, Google Play Music or any other non supported service, this is not the best option.

You also cannot group or switch rooms.

Option 2: Sonos API with IFTTT

Alexa, trigger big beats in the kitchen

You will need

  • Amazon Echo (any)
  • Sonos device (any)
  • an always on computer capable of running node.js (RasPi, NAS, Mac/PC)
  • to be comfortable with terminal/command line

    Steps

    1. Setup jishi's node-sonos-http-api on a computer on the same network as your Sonos. A RasPi is a great device for this or run this on your NAS through docker. (I have this running on a QNAP NAS)

    For this to work, computer must be always on and accessible over the web. To find out how to enable this, look for instructions here.

    When you're able to reach http://your-ip-address:5005/zones and get a response back, move to the next step.

    1. Create Favourites or Playlists in your Sonos app
    2. Log in (or sign up) to IFTTT
      • Click on My Applet > New Applet
      • Click on +this
      • Choose Amazon Alexa as the service
      • Choose Say a specific phrase as the trigger
      • Type in a phrase e.g. big beats in the kitchen
      • Click on Create Trigger
      • Click on +that
      • Choose Maker as the action service
      • Choose Make a web request as the action
      • In the URL field, enter the sonos-api url as like so -http://your-ip-address:5005/kitchen/favorite/bigbeats
      • Choose method Get
      • Click Create Action
      • Click Finish
    3. Say "Alexa trigger big beats in the kitchen", the favourite "bigbeats" should start playing in the kitchen.
    4. You now have limited control of Sonos with Alexa.

Follow the above steps to create applets for each favourite/playlist that you want to trigger through Alexa.

The URL format to follow is http://your-ip-address:5005/{room name}/favorite/{favorite name} or http://your-ip-address:5005/{room name}/playlist/{playlist name}

For other actions such as pause/play the URL format is http://your-ip-address:5005/{room name}/{action}

e.g.

  • Classic rock in the lounge (http://your-ip-address:5005/lounge/favorite/classicrock)
  • Pink floyd in the bedroom (http://your-ip-address:5005/bedroom/playlist/pink floyd)
  • To pause, use a phrase like "living room stop" http://your-ip-address:5005/living room/pause

Checkout node-sonos-http-api for more examples.

How well does it work?

Surprisingly well, provided you have a manageable number of devices and have created favourites and playists in the Sonos app. You also cannot group or switch rooms as long you have the right triggers created and remember the trigger phrases.

The downside is that it's not dynamic, i.e. you have create a trigger for every action you want to perform which can and will get messy.

Option 3: Connecting with an Alexa Skill

Alexa, ask Sonos to play playlist history of rock

You will need

  • Amazon Echo (any)
  • Sonos device (any)
  • an always on computer capable of running node.js (RasPi, NAS, Mac/PC)
  • to be extremely comfortable with terminal/command line

Steps

This is based on Ryan Graciano’s echo-sonos repository where he has provided very clear instruction on how to set this up. But before you start, below are the steps at a high level of what you'll need to do.

  1. Setup jishi's node-sonos-http-api on an always-on computer accessible over the web.
  2. Create a free Amazon Developer account.
  3. Create an Alexa Skill (this will not be published and will remain in test mode)
  4. Configure the AWS Lambda servers to talk to the Alexa Skill and your home server running the Sonos API.
  5. You're done.

These steps above are an oversimplification, it took me over an hour to do and I know may way around the command-line. Just remember, if something doesn't seem like it's working, you can just wipe it all out and start again. When you get it working, rejoice - you've just achieved voice control over your Sonos system.

How well does it work?

Extremely well. The ability to say, “Alexa, tell Sonos to play playlist history of rock in the kitchen” or “Alexa, tell Sonos to add the lounge to the kitchen.” is pure bliss, and it mostly works.

Everything is configured dynamically, the zones, playlists, favourites and you can also group or switch rooms.

I highly recommend setting this up So, head over to rgraciano's echo-sonos repository and follow the instructions. If you run into trouble, let me know at @tchdhry, I may be able to help you out.

Starting Over, v0.1

Shipping v0.1 now, is more important than shipping v1.0 many months later.

About over a year ago, chdhry.com was a functional, sporadically updated site built on Wordpress, running a slightly customised version of Independent Publisher. I was facing some issued with my web host so decided to move, which involved transferring 5 sites across.

During the move, I never got around to restoring chdhry.com, with the assumption that I could always get back to it, I had a backup. Nope. See, I thought my files were backed up, but then I found out the mySQL database had gone missing. I had copies of the DBs of other sites, but mine was gone, I lost all my content. Not a biggie, google's cache or archive.org will have a copy, it wasn't there either. All gone!

Time to start over.

Wordpress for all it's issues, is an easy system to use. You can have websites up and running in under an hour, has a great, easy to use admin section which almost anyone, with basic wordprocessing skills can use. However, all of this comes with a massive overhead which I did not want to go deal with again.

So a flat file CMS was the way to go. I played around with a few, like Grav and Kirby but for now, have chosen to build on Pico.

It's not perfect, but Pico was the fastest I could design to my liking. Sure, there are features missing and the publishing workflow involves ftp, but it's live.

I have moved to Grav as it turns out Pico had some security vulneratbilities that I missed earlier.

It's easy to forget, but shipping v0.1 now, is more important than shipping v1.0 many months later.