Announcement

Collapse
No announcement yet.

Script Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script Help

    This has been my hobby project for a few months now and I have had some successes but I still need help.

    Here is my goal

    When the bathroom light is turned on (the trigger) the following will happen on the Sonos Play3 in the bathroom.

    If it is after dusk and before dawn play a radio station of nightime sounds (crickets) and the script will stop.

    If it is not after dusk and before dawn:

    If the master bedroom player is playing, then link to it and the script will stop.
    Otherwise
    If the kitchen player is playing, then link to it and the script will stop.
    Otherwise
    Play a radio station and the script will stop.


    What is working?
    I am able to check the other players and see if they are playing

    What is not working?
    So far I am unable to link players with a script and I'm not able to play music with a script.


    I've been working on this for a few months as a hobby and I love doing it and the Sonos plugin is my favorite. Dirk has really done an amazing job with this.

    Here is my code so far:
    Code:
    Public Sub BathroomMusic (ByVal params As String)
    	hs.writelog("BathroomMusic","Event has started")
        '*** if it is night play crickets ***
    	if isnighttime then
    		hs.writelog("BathroomMusic","It is nighttime")
    		'*** code here to play crickets radio station ***
    	else
    		'*** not night time, if the bedroom is playing link to it ***
    		hs.writelog("BathroomMusic","It is not nighttime")
    		if hs.DeviceValueByName("Sonos Master Bedroom State") = 1 then
    			hs.writelog("BathroomMusic","Master Bedroom is playing")
    			'*** code here to link to bedroom player ***
    		else
    			'*** if the kitchen is playing link to it ***
    			hs.writelog("BathroomMusic","Master Bedroom is not playing")
    			if hs.DeviceValueByName("Sonos Kitchen State") = 1 then
    				hs.writelog("BathroomMusic","Kitchen is playing")
    				'*** code here to link to kitchen player ***			
    			else
    				'*** play station ***
    				hs.writelog("BathroomMusic","Kitchen is not playing")
    				'*** code here to play rock station ***
    			end if
    		end if
    	end if
    End Sub

    #2
    Originally posted by sifuhall View Post
    This has been my hobby project for a few months now and I have had some successes but I still need help.

    Here is my goal

    When the bathroom light is turned on (the trigger) the following will happen on the Sonos Play3 in the bathroom.

    If it is after dusk and before dawn play a radio station of nightime sounds (crickets) and the script will stop.

    If it is not after dusk and before dawn:

    If the master bedroom player is playing, then link to it and the script will stop.
    Otherwise
    If the kitchen player is playing, then link to it and the script will stop.
    Otherwise
    Play a radio station and the script will stop.


    What is working?
    I am able to check the other players and see if they are playing

    What is not working?
    So far I am unable to link players with a script and I'm not able to play music with a script.


    I've been working on this for a few months as a hobby and I love doing it and the Sonos plugin is my favorite. Dirk has really done an amazing job with this.

    Here is my code so far:
    Code:
    Public Sub BathroomMusic (ByVal params As String)
        hs.writelog("BathroomMusic","Event has started")
        '*** if it is night play crickets ***
        if isnighttime then
            hs.writelog("BathroomMusic","It is nighttime")
            '*** code here to play crickets radio station ***
        else
            '*** not night time, if the bedroom is playing link to it ***
            hs.writelog("BathroomMusic","It is not nighttime")
            if hs.DeviceValueByName("Sonos Master Bedroom State") = 1 then
                hs.writelog("BathroomMusic","Master Bedroom is playing")
                '*** code here to link to bedroom player ***
            else
                '*** if the kitchen is playing link to it ***
                hs.writelog("BathroomMusic","Master Bedroom is not playing")
                if hs.DeviceValueByName("Sonos Kitchen State") = 1 then
                    hs.writelog("BathroomMusic","Kitchen is playing")
                    '*** code here to link to kitchen player ***            
                else
                    '*** play station ***
                    hs.writelog("BathroomMusic","Kitchen is not playing")
                    '*** code here to play rock station ***
                end if
            end if
        end if
    End Sub
    Does it have to be a script?

    You can do this with 4 events.

    Here is the event for nightime (just picked some track) and one checking for Kitchen playing (need to write one for other rooms)

    Dirk
    Attached Files

    Comment


      #3
      Thanks for the reply.

      If I can get the same results I will use events.

      How can I set it up to link to the bedroom if it is playing, and the same for the bedroom, but if both are playing only link to the bedroom?

      Also, only play the radio if neither are playing?

      Comment


        #4
        Originally posted by sifuhall View Post
        Thanks for the reply.

        If I can get the same results I will use events.

        How can I set it up to link to the bedroom if it is playing, and the same for the bedroom, but if both are playing only link to the bedroom?

        Also, only play the radio if neither are playing?
        You should decide which hierarchy you want to uphold. Say if Master bedroom and Kitchen are both playing, whether you make an event or code a script, you will have do decide which of the two is more important. Let's say you choose MBR as the more important. One event just has you check on MBR playing, if yes, link ... unconditional. Now the other event (because all existing events are checked against when triggers occur) you created for the Kitchen, here you would add a negative check, so it would be

        If I turn the lights on
        and it is during the fay
        and kitchen is playing
        AND MBR IS NOT PLAYING
        then do xyz

        See the logic?

        Your question on the radio would be
        If I turn the lights on
        and it is during the fay
        and kitchen ISNOT playing
        AND MBR IS NOT PLAYING
        then play radio

        Dirk

        Comment


          #5
          Thank you, I do get it now.

          One last question.

          After this event I want to stop the music when the light is turned off.

          How can I determine if I need to simply unlink or if I should stop playing?

          I don't want to stop the players in either the kitchen or the bedroom if they are playing.

          Comment


            #6
            Originally posted by sifuhall View Post
            Thank you, I do get it now.

            One last question.

            After this event I want to stop the music when the light is turned off.

            How can I determine if I need to simply unlink or if I should stop playing?

            I don't want to stop the players in either the kitchen or the bedroom if they are playing.
            Just issue an unlink command (for the bathroom player!) and a stop playing command.

            Dirk

            Comment


              #7
              Just wanted to say thanks for that tip. Works great.

              Comment


                #8
                Radio-problem

                How can I start play a radio channel on Sonos from HS3 with Sonos plugin? Can I start it with code (.net) ? No radio channel is auto find..

                Need help

                Comment


                  #9
                  Originally posted by zuuper View Post
                  How can I start play a radio channel on Sonos from HS3 with Sonos plugin? Can I start it with code (.net) ? No radio channel is auto find..

                  Need help
                  Please provide more detail, not sure I understand what help you need. Add pictures/screen shots to help show what you are trying to do.

                  What radio channels are you referring to? If you make them part of your favorites, you should be able to play them by creating an event (using Sonos Action) or "learn them" and then select them from learned radio channels (works more for Pandora channels etc)

                  Dirk

                  Comment


                    #10
                    >If you make them part of your favorites, you should be able to play them by creating an event (using Sonos Action) or "learn them" and then select them from learned radio channels (works more for Pandora channels etc)


                    I have put in to radio stations in my favorites list. See here:


                    When I click the button radiostations in the plugin so nothing happens. No radio stations come up.Nothing happens at all.


                    The logger has a failure now registered.


                    I use the BETA version of the Sonos plugin. The settings for the plugin I show here:



                    Grateful if you could help me
                    Attached Files

                    Comment


                      #11
                      Originally posted by zuuper View Post
                      >If you make them part of your favorites, you should be able to play them by creating an event (using Sonos Action) or "learn them" and then select them from learned radio channels (works more for Pandora channels etc)


                      I have put in to radio stations in my favorites list. See here:


                      When I click the button radiostations in the plugin so nothing happens. No radio stations come up.Nothing happens at all.


                      The logger has a failure now registered.


                      I use the BETA version of the Sonos plugin. The settings for the plugin I show here:



                      Grateful if you could help me
                      turn auto-update flag under music DB settings on, leave immediate update off. Your PI is not building (read copy from your Sonos system) the music DB at all. Would also recommend you read up on the help file which you can find by going to tools > help > Sonos

                      You can create a music DB on demand by going to the HS device management page, look for the Sonos Master device, click on control, then click on create music DB (syntax?).

                      Let me know that solved it or not.

                      Dirk

                      Comment

                      Working...
                      X