Makerprojects: Getting a toddler to automatically play music on a Sonos with NFC tags

Printing out NFC tags

After using my much loved Sonos Play:5 for a while I started thinking about how I could include it in my Smarthome project. This was before I got my hands on the Vera Lite and before my daughter Ada started crawling around. After watching her fiddle with my iPad and not really getting anywhere with it, except continously pressing the home button to exit whatever game I was trying to get her interested in. It was then I realized that however gifted one sees your own child Ada was not equipped with the motoric skills yet required to start her favourite songs for example on our livingroom Play:5 speaker. I have been itching to try a proper project with NFC tags out as I find the act of making something digital happen through physical interaction fascinating. I realized that physical NFC tags were the perfect way for her to interact with digital interfaces like starting a song she likes on the Sonos speaker. So how do you make this magic happen? Pay close attention after the break!

PS: Aren’t my self printed NFC tags awesome???

So what do you need? Actually a surprising amount of stuff.. but if you already have the Vera smart home gateway and a NFC capable phone then you’re almost there! And who doesn’t right??

Equipment list:
– NFC tags (I bought mine at www.tagstand.com)
– A NFC capable phone (HTC One X and the Samsung Galaxy SIII support this)
– A Vera smart home gateway (I have the Vera Lite)
– The apps Tasker and Homebuddy from the Google Play store.
– The Sonos plugin for the Vera.

Various NFC-tags biught from tagstand.com

Various NFC-tags biught from tagstand.com

Walkthrough:
I assume you have your Vera up and running. Download the ZIP archive all the way at the bottom of this page (It’s tiny and hard to miss but it’s right above the blue footer.
Now like the good walkthrough zombie you are do this:
1. Log into your Vera managment interface through the cp.mios.com login.
2. Click “Apps” and then click “Develop Apps”. No need to worry, the development is already done we just need to upload the plugins.
3. Click “Loop Files” and and upload all the files you downloaded (except the file D_Sonos1_UI4.json and the services subdirectory). check the Restart Luup after upload checkbox and click GO.
4. Now it’s time to create the Sonos device.
5. Click “Create Device” (It’s important that you click the create device under Develop Apps and not under the main Devices section as it will not work then.)
6. In the UpnpDevFilename input box enter D_Sonos1.xml
7. In the Description input box enter a name for the panel device, e.g. Sonos Living Room.
8. Click Create device
10. Exit the option you are now in and click on the Devices on the main link bar, here you will now see your newly created device. In the top right corner of the device click the wrench symbol to get into the settings menu for the specific device.
11. Click Advanced and enter the IP address of your Sonos Device, I added the IP address of my Play:5 speaker but I’m sure other choices will work as well. After saving you then get rewarded with a Sonos logo on the device, magic!

Before you proceed see if you can control your Sonos device through the buttons on the devicemenu.

Now we are ready to make the magic happen! What we need is that the mobile phone sends a signal to the Vera gateway when you tap a NFC-tag on it. This happens in the following way:

The NFC Task Launcher app recognizes that you have tapped a NFC tag on the phone, the NFC tag is tagged with a premade Tasker task which sends calls on the Homebuddy app to send a start scene signal to the Vera Getway. The Vera gateway then initiates the scene which in turn plays the music. All this happens in a very short time, confused?? I’ll split the next part into sections to make it simpler to follow:

Setting up the scene on the Vera Gateway:
1. Under Automation click New Scene.
2. Give the scene a name, such as Play Sonos
3. Select the [Advanced] option/tab
4. Select the Sonos device
5. Click (Add)
6. Then from the drop down options list created below, Choose PlayURI. You can now use SetURIToPlay and PlayURI callbacks to:
– load or play a Sonos playlist by its name => use URI SQ: is the name of your playlist
– load or play an audio input by its name => use URI AI: is the name of your audio input
– load or play the local audio input => use URI AI:
– load or play the local (internal) queue starting at the first track => use URI Q:
– load or play the local (internal) queue starting at the track => use URI Q:
I created a local playlist on my Sonos that I named Ada, so my PlayURI command was “SQ:Ada”. This was for testing purposes and as my project proceeds I will make separate song calls for every NFC-tag that I have.
7. Confirm Changes and then save.
8. Try your new scene from the administration panel and if successful we will now try to start it from the Homebuddy Android app.

Homebuddy:
This is the application I use on Android to remote control my Vera system. I would start with setting up this application and logging into your mios account and testing out the scene we created in the previous step, all systems go? Then it’s time to set up the Tasker app.

Tasker:
Tasker is an Android application that can automate pretty much anything you throw at it, it’s a powerful application with a user interface that is not for the feint of heart. This Youtube video explains the setup process better that words: http://www.youtube.com/watch?v=PwMQgLPRpUw You can find the scene number of the scene you created in the Vera gateway admin panel.

NFC Task Launcher:
Now that we have a tasker app that launches a Homebuddy scene we need to trigger the Tasker app with a NFC-tag. This is done with the NFC Task Launcher.
1. Open the NFC Task Launcher on your phone.
2. Click New Tag.
3. Click New Task.
4. Click Add Action.
5. At the bottom you have Tasker, click it and you will get an overview of the existing Tasker tasks that you have created. Choose the one you created in the previous step. Make sure you have followed the instruction about opening Tasker to external applications that you will receive when you add the Tasker task.
6. Finish the tutorial, write to the selected NFC-tag and you are DONE!

TEST IT OUT!

Update:
And here is my daughter trying it out:

My daughter playing music on the Sonos with NFC tags from Christian Haugen on Vimeo.

  • Tom Evans

    Hi Christian,

    That’s great stuff. I work in London and in the past for the music industry. It would be great to get a simple version/product off the ground to do this. It’s something I’ve looked into in the past. Have you planned to take it further or are you just playing around with the tech?

    All the best,

    Tom

  • Hi Tom!

    No, haven’t really planned on taking it any further. Just got a good idea and made it 🙂 Planning on making some iterations on it though, but as it is it is too complex for distribution. Has to be a lot more simple if its going to get traction. Any ideas?

    Christian

  • Rune Osnes

    HI! I just wanted to suggest another approach without the need for the Vera Lite. With the same setup, trade the Vera for an app called Macronos which lets Tasker interact directly with the Sonos trough widgets. I don’t have an NFC phone but I interact with the Sonos in all sorts of other ways. (When my alarm goes of in the morning it starts the NRK Alltid Nyheter radio station on the kitchen Sonos at 15% volume! Pretty sweet!)

    • Awesome! Was thinking about a way to do it like that when I set it up, but couldn’t find any hooks for the tasker app to communicate directly with the Sonos app, Macronos solves that issue 🙂 Will check it out, thanks for the heads up!

  • Jean-Louis

    Hi Christian, I was reading your article this morning as well (waiting for my Sonos Connect:Amp to arrive ;)) and I agree with Rune (coincidence 6 months after the post??), seems like Macronos is also a good alternative without using the Vera (and NFC is enabled in Macronos).
    But Vera is more versatile of course, nice work (and nice tags ;)).

    Cheers

    • Thanks! Looking forward to testing out the Macronos as well, seems like a simpler solution! But I am planning on having my blinds go up automatically and the lights dim up in the morning in combination with the music turning on in the kitchen so the Vera can still be a bridge for those kinds of automation projects. But if you just want to automate the Sonos then it looks like Macronos is the way to go, if I can find the time I will probably write a post about it as well 🙂