MagicMirror icon indicating copy to clipboard operation
MagicMirror copied to clipboard

Sonos integration

Open moenchmeier opened this issue 10 years ago • 34 comments

Idea: Display Album art, Titel etc. of the currently playing song on the rooms Sonos speaker.

moenchmeier avatar Feb 29 '16 12:02 moenchmeier

Well, since I don't have a magic mirror (yet!) and don't really have time to do it, I think it would be fairly easy to implement it.

Looking at this library: https://github.com/jishi/node-sonos-http-api Maybe with this (when done): #76

It would be pretty darn useful and nice!

anned20 avatar Mar 01 '16 17:03 anned20

I started playing with the Sonos api yesterday and got it to work. It did not take much to get the rooms and the current playing song.

Now I just need to make it work with module system, #80

And add some styling.

The only thing that bothers me is that a separate service needs to run in the background.

Vaggan avatar Mar 09 '16 10:03 Vaggan

That would be Awesome!! How would it work with multiple zones? Would I need to specify which zones zone the mirror is in?

mrmichaelfowler avatar Mar 21 '16 18:03 mrmichaelfowler

I did not think about that you might have a mirror in each zone. I display all zones and the current song playing. With the option to hide zones that are not currently playing any song. I haven't been working on this in a while. How is the module system progressing?

Vaggan avatar Mar 21 '16 20:03 Vaggan

@Vaggan could you share the sonos coding, I also would like to display the current playing song. A separate module would be great.

CFenner avatar Mar 22 '16 19:03 CFenner

Hi @CFenner I created a branch called sonos-module in my fork. Look in the modules folder. I´m new to github so I think I screwed up my commit (I´ll fix it later) but i think you will find the code there. It might work out of the box. If not, I might have changed a line or two in controllers/modules.php file in my main branch.

Edit: I created a separate repo for my sonos-module

Vaggan avatar Mar 24 '16 08:03 Vaggan

looks good, but you call http://localhost:5005/zones and i think you didn't commit this service.

CFenner avatar Mar 24 '16 12:03 CFenner

Sorry, I forgot to tell you that I´m using node-sonos-http-api as mentioned above. So you need to have that running in order to get this to work. Maybe in a future version we can integrate this in to the module in some way.

Vaggan avatar Mar 24 '16 13:03 Vaggan

Good idea, I suppose as you are just using /zones we should be able to cut down the service to a small part.

CFenner avatar Mar 24 '16 13:03 CFenner

Yes, but I have been looking at #76 (Voice recognition) as well. And I have implemented it for the Sonos system. I can control the volume, play/paus music and send voice messages. And for this I need the API. Do you have any suggestion for how to implement these separate modules using the API without duplication the Sonso API in the modules. I think it is easier to just use the existing API.

Vaggan avatar Mar 24 '16 13:03 Vaggan

Maybe you could just create a "sonos-connection-module" which does basically nothing on the mirror but enables the api calls. Then you can create a "sonos-display-module" which displays the zone info calling the service provided by the "sonos-connection-module". For the voice controll you could create another module which again calls the service provided by the "sonos-connection-module".

@MichMich is working on a new module system and I think I read something about event handling, this could simplify inter module communication.

CFenner avatar Mar 24 '16 13:03 CFenner

Sound good. I really appreciate the feedback.

Vaggan avatar Mar 24 '16 13:03 Vaggan

Great idea! A few days ago I bought a sonos play 1. Actually I try to get this module working, but I have a few problems. I installed the SONOS HTTP API (copy all files to /home/pi; following the "usage" points). After that I copied the sonos folder from (https://github.com/Vaggan/MagicMirror/tree/sonos-module) in my modules folder. Did I forgot something? My programming skills are not the best, I understand most, but I've not so much experience in it.

Perhaps anybody can help? Thanks :+1:

djsunrise19 avatar Mar 25 '16 12:03 djsunrise19

Hi @djsunrise19 You only need to copy the sonos-module folder from this folder. I will try to create a new repo and add a readme with som more info when i got the time.

Did you get the SONOS HTTP API working by 'npm install --production' and 'npm start'? You need to run 'npm start' and have the API running i order to get the module to work.

Tell me if you do not get it to work and I'll see if I can help.

Edit: I created a separate repo for my sonos-module

Vaggan avatar Mar 25 '16 15:03 Vaggan

Hi @Vaggan,

thanks for answering :). I copied the "sonos-module" folder in my "modules" folder.

If I type npm install --productions I get this: http://prntscr.com/ajw1io Where I have to copy the files from SONOS HTTP API?

Thanks for your help, i really appreciate it.

Regards Maurice

djsunrise19 avatar Mar 25 '16 15:03 djsunrise19

I´m not sure but it looks like you are in your home folder when running the command. You need to be inside the "node-sonos-http-api" folder. In this folder there should be a file called package.json. It is this one that NPM is looking for when you run npm install --production

This is where you should be when running npm start as well.

Vaggan avatar Mar 25 '16 17:03 Vaggan

Oh, I see! That looks way better: http://prntscr.com/ajxvjf But as you can see I have a message with "{ [Error: Cannot find module './settings.json'] code: 'MODULE_NOT_FOUND' }". Is that a Problem?

How can I start the server on every reboot? @reboot command in crontab -e?

Regards Maurice

Edit: After a reboot (and ´npm start´ again), no sonos informations on the interface, mh... .

djsunrise19 avatar Mar 25 '16 18:03 djsunrise19

I don´t think it matters. It will use the default settings. You can just test the api by entering http://localhost:5005/zones in the browser. if you are not on the PI change "localhost" to the IP-address of your PI (looks like 192.168.0.33).

If it does not work you can try to create a settings.json file in the root directory. My file only contains the voicerss settting and my specific key. It is only used for the say command so it is not mandatory.

Vaggan avatar Mar 25 '16 19:03 Vaggan

I don´t know about the reboot stuff but i found a blog post (Check out nr.5) that looks like it fixes what you are after.

Vaggan avatar Mar 25 '16 19:03 Vaggan

did you encounter cross origin resource sharing issues?

can't access localhost:5005 with JS, works in browser with localhost:5005/zones. Any ideas?

CFenner avatar Mar 25 '16 22:03 CFenner