MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Limit Sonos module to only show a specific speaker

    Scheduled Pinned Locked Moved Development
    23 Posts 3 Posters 17.4k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      dinkybluebug245
      last edited by

      I’m using MagicMirror-Sonos-Module to show what is playing on all the sonos speakers in my house.
      link here

      Does anyone know to restrict the display to only show a specific speaker in my house, rather then list them all?

      Ive had a look at the sonos.js file and I can;t work out what I need to add to only display ‘Kitchen’ speaker.

      Can anyone help me?

      strawberry 3.141S 1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
        last edited by strawberry 3.141

        @dinkybluebug245 can’t test this, because I don’t have sonos speakers, but this would be an quick an ugly solution

        $.each(data, function (i, item) {
        	if(item.coordinator.roomName === 'Kitchen'){
        		var room = item.coordinator.roomName;
        		var state = item.coordinator.state.zoneState;
        		var artist = item.coordinator.state.currentTrack.artist;
        		var track = item.coordinator.state.currentTrack.title;
        		var cover = item.coordinator.state.currentTrack.absoluteAlbumArtURI;
        		var streamInfo = item.coordinator.state.currentTrack.streamInfo;
        		if(item.members.length > 1){
        			room = '';
        			$.each(item.members, function (j, member) {
        				room += member.roomName + ', ';
        			});
        			room = room.slice(0, -2);
        		}
        		text += this.renderRoom(state, artist, track, cover, room);
        	}
        }.bind(this));
        

        personally i would fork the repository add a config option exclude: [‘LivingRoom’, ‘Bathroom’] etc. to have normal behaviour for all people updating the module without need to change the config to get their familiar result. and then i would check

        $.each(data, (i, item) => {
        	if(this.config.exclude.indexOf(item.coordinator.roomName) === -1){
        

        and then submit a pull request

        Please create a github issue if you need help, so I can keep track

        D 2 Replies Last reply Reply Quote 1
        • D Offline
          dinkybluebug245 @strawberry 3.141
          last edited by dinkybluebug245

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • D Offline
            dinkybluebug245 @strawberry 3.141
            last edited by

            @strawberry-3.141 said in Limit Sonos module to only show a specific speaker:

            if(item.coordinator.roomName === ‘Kitchen’){

            It works! hurrah! Thanks. much appreciated.

            not sure how to fork the repository - but I can research this bit.

            Thank again.

            1 Reply Last reply Reply Quote 0
            • strawberry 3.141S Offline
              strawberry 3.141 Project Sponsor Module Developer
              last edited by

              just click on fork in the top right corner of github

              Please create a github issue if you need help, so I can keep track

              D 1 Reply Last reply Reply Quote 0
              • D Offline
                dinkybluebug245 @strawberry 3.141
                last edited by

                @strawberry-3.141 Can I clarify then… would config file under the sonos module be:

                exclude: ‘Bedroom’,‘Living room’,‘Bathroom’,

                1 Reply Last reply Reply Quote 0
                • strawberry 3.141S Offline
                  strawberry 3.141 Project Sponsor Module Developer
                  last edited by strawberry 3.141

                  it will be an array so you need to put square brackets around it exclude: ['Bedroom', 'Living room', 'Bathroom']

                  you don’t put a config file in the repository, that’s what the user has to add into his config file in ~/MagicMirror/config/config.js on it’s own.

                  you would have to add the last line into defaults

                   Module.register('sonos', {
                  	defaults: {
                  		showStoppedRoom: true,
                  		showAlbumArt: true,
                  		showRoomName: true,
                  		animationSpeed: 1000,
                  		updateInterval: 0.5, // every 0.5 minutes
                  		apiBase: 'http://localhost',
                  		apiPort: 5005,
                  		apiEndpoint: 'zones',
                                  exclude: []
                  },
                  

                  Please create a github issue if you need help, so I can keep track

                  D 2 Replies Last reply Reply Quote 0
                  • D Offline
                    dinkybluebug245 @strawberry 3.141
                    last edited by

                    This post is deleted!
                    strawberry 3.141S 1 Reply Last reply Reply Quote 0
                    • D Offline
                      dinkybluebug245 @strawberry 3.141
                      last edited by

                      @strawberry-3.141 There might be a reason why this hasnt been done before.

                      If you exclude all rooms in your house leaving ‘Kitchen’ the only one included in your config file,

                      If Kitchen plays music, and then Living room is grouped in with Kitchen the code works
                      the name of the rooms displayed would be Kitchen, Living room (the order of the rooms if the order they were grouped)

                      but if you have living room playing music and then group in kitchen, then the order is different, :
                      Living room, Kitchen

                      and then the code doesnt work.

                      Im guesing the code you wrote see’s Living room is excluded and then doesnt show the rest?

                      1 Reply Last reply Reply Quote 0
                      • strawberry 3.141S Offline
                        strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
                        last edited by strawberry 3.141

                        @dinkybluebug245 you forgot to put the mentioned line in the defaults object, this will cause a problem for those who want all rooms displayed, if you add this line and make a commit your pull request will get updated automatically, and i suggest to put also an information aubout this option into the readme file

                        Edit to your new post, as i said i have no clue about the sonos system and can’t test it I think you will find a way to get around this issue

                        Please create a github issue if you need help, so I can keep track

                        D 1 Reply Last reply Reply Quote 0
                        • D Offline
                          dinkybluebug245 @strawberry 3.141
                          last edited by

                          @strawberry-3.141 Thanks for all your help.

                          Really appreciate it.

                          Marc

                          strawberry 3.141S 1 Reply Last reply Reply Quote 0
                          • strawberry 3.141S Offline
                            strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
                            last edited by

                            @dinkybluebug245 is this what you mean by nested rooms?

                            $.each(item.members, function (j, member) {
                            					room += member.roomName + ', ';
                            });
                            

                            Please create a github issue if you need help, so I can keep track

                            D 1 Reply Last reply Reply Quote 0
                            • D Offline
                              dinkybluebug245 @strawberry 3.141
                              last edited by dinkybluebug245

                              @strawberry-3.141 Yes I think so.

                              Excluding all rooms but ‘Kitchen’,

                              Nested rooms "Living rioom, Kitchen’ - shows nothing
                              Nested rooms "Kitchen, Living room’ shows info

                              strawberry 3.141S 1 Reply Last reply Reply Quote 0
                              • strawberry 3.141S Offline
                                strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
                                last edited by strawberry 3.141

                                @dinkybluebug245 can you give this a try?

                                $.each(data, (i, item) => {
                                    if(this.config.exclude.indexOf(item.coordinator.roomName) === -1 || item.members.length > 1){
                                        var room = item.coordinator.roomName;
                                        var state = item.coordinator.state.zoneState;
                                        var artist = item.coordinator.state.currentTrack.artist;
                                        var track = item.coordinator.state.currentTrack.title;
                                        var cover = item.coordinator.state.currentTrack.absoluteAlbumArtURI;
                                        var streamInfo = item.coordinator.state.currentTrack.streamInfo;
                                        if(item.members.length > 1){
                                            room = '';
                                            $.each(item.members, (j, member) => {
                                                if(this.config.exclude.indexOf(member.roomName) === -1){
                                                    room += member.roomName + ', ';
                                                }
                                            });
                                            room = room.slice(0, -2);
                                        }
                                        text += this.renderRoom(state, artist, track, cover, room);
                                    }
                                }.bind(this));
                                

                                Please create a github issue if you need help, so I can keep track

                                D 1 Reply Last reply Reply Quote 0
                                • D Offline
                                  dinkybluebug245 @strawberry 3.141
                                  last edited by

                                  @strawberry-3.141 shouldnt the first line have ‘function’ in it?

                                  	$.each(data, function (i, item) {
                                  
                                  strawberry 3.141S 1 Reply Last reply Reply Quote 0
                                  • strawberry 3.141S Offline
                                    strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
                                    last edited by strawberry 3.141

                                    @dinkybluebug245 then you will change the scope of this, that’s why I prefer to use big arrow functions () => {} is the same as function(){} but you keep the scope

                                    Please create a github issue if you need help, so I can keep track

                                    D 2 Replies Last reply Reply Quote 0
                                    • D Offline
                                      dinkybluebug245 @strawberry 3.141
                                      last edited by

                                      @strawberry-3.141 I love how you think I know what that means. Ha! I’ll take your word on that and give it a go

                                      1 Reply Last reply Reply Quote 0
                                      • strawberry 3.141S Offline
                                        strawberry 3.141 Project Sponsor Module Developer
                                        last edited by strawberry 3.141

                                        a lot of people are doing this by saving the scope into a variable like

                                        var self = this;
                                        setTimeout(function(){
                                                doSomething();
                                                self.sendSocketNotification('NOTIFICATION');
                                        }, 1000);
                                        

                                        but I like this cleaner way

                                        setTimeout(() => {
                                                doSomething();
                                                this.sendSocketNotification('NOTIFICATION');
                                        }, 1000);
                                        

                                        Please create a github issue if you need help, so I can keep track

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          dinkybluebug245 @strawberry 3.141
                                          last edited by

                                          @strawberry-3.141 That doesnt work. Kitchen is the only room NOT excluded in my config.js

                                          Kitchen, then group in Living room - shows info.

                                          Living room, then grouping in Kitchen - doesnt show.

                                          strawberry 3.141S 1 Reply Last reply Reply Quote 0
                                          • strawberry 3.141S Offline
                                            strawberry 3.141 Project Sponsor Module Developer @dinkybluebug245
                                            last edited by

                                            @dinkybluebug245 sry then you have to figure it out on your own or ask some person with sonos speakers for help

                                            Please create a github issue if you need help, so I can keep track

                                            D 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy