Announcement

Collapse
No announcement yet.

Need help with Loops

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

  • Need help with Loops

    I have a simple script I am using to change the display of my Russound Keypads to cycle thru the artist and the title of the song that is being played. What I was wanting to do is have it display each for 10 seconds, which does seem to happen when the script initially starts. But eventually it gets out of sync and starts going haywire. Am I doing something wrong here?

    Code:
    Sub Main(ByVal parm As Object)
    DiM Title as string
    Dim Artist as string
    Dim Is_Music_Playing as integer = hs.devicevalue(614)
        If Is_Music_Playing = 1 then
            Do
                Title = (hs.DeviceString(624))
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,2,Title,"Left",0})
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,3,Title,"Left",0})
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,4,Title,"Left",0})
                hs.waitsecs(10)
                Artist = (hs.deviceString(622))
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,2,Artist,"Left",0})
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,3,Artist,"Left",0})
                hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,4,Artist,"Left",0})
                hs.waitsecs(10)
                'hs.writelog("Russound Script", "In Loop")
                Is_Music_Playing = hs.devicevalue(614)
            Loop Until Is_Music_Playing = 2
            'hs.writelog("Russound Script", "Loop Ending")
            hs.runScript("Russound_Time.vb",False,False)
        Else
            'Do Nothing
            'hs.writelog("Russound Script", "Music isn't on, exiting script.")
        End If
    End Sub

  • #2
    Script looks ok to me. If you comment out the BLRussound calls, and just write the title and artist to the HS logs, does it work as expected?

    Cheers
    Al
    HS 3.0.0.532: 1963 Devices 1141 Events
    Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

    Comment


    • #3
      Hey Al, thanks for looking. It seems when I send to the logs, its sending it twice, every 10 seconds. I am wondering if this is what is confusing my Russound unit. (Don't judge me on the music )
      Attached Files

      Comment


      • #4
        And actually it just went crazy and the time does not match what I want in the script. Could this be an issue with using HS to time things vs an actual VB function to handle time?
        Attached Files

        Comment


        • #5
          It's not good practice to keep a script running continually like this. It may be better if you create a recurring event for 20 seconds (to run the script) and remove the loop.
          Jon

          Comment


          • #6
            Originally posted by waynehead99 View Post
            Hey Al, thanks for looking. It seems when I send to the logs, its sending it twice, every 10 seconds. I am wondering if this is what is confusing my Russound unit. (Don't judge me on the music )
            LOL. Must be the wife's music right?

            Can you post the revised script that writes to the log?

            Cheers
            Al

            PS +1 to what Jon said. Although I do have some scripts that run continually myself.
            HS 3.0.0.532: 1963 Devices 1141 Events
            Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

            Comment


            • #7
              Here is the script, I reverted everything back and just commented out the tests sent to the logs. I can do the event thing if that is what is needed, but I was really hoping and have been trying to stay away from events when things like this just seem so easy to do in a quick script...

              Honestly, the way my brain works, I want to just figure out why this is broken.

              Code:
              Sub Main(ByVal parm As Object)
              DiM Title as string
              Dim Artist as string
              Dim Is_Music_Playing as integer = hs.devicevalue(614)
                  If Is_Music_Playing = 1 then
                      Do
                          Title = (hs.DeviceString(624))
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,2,Title,"Left",0})
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,3,Title,"Left",0})
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,4,Title,"Left",0})
                          'hs.writelog("Russound Script", Title)
                          hs.waitsecs(10)
                          Artist = (hs.deviceString(622))
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,2,Artist,"Left",0})
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,3,Artist,"Left",0})
                          hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,4,Artist,"Left",0})
                          'hs.writelog("Russound Script", Artist)            
                          hs.waitsecs(10)
                          'hs.writelog("Russound Script", "In Loop")
                          Is_Music_Playing = hs.devicevalue(614)
                      Loop Until Is_Music_Playing = 2
                      'hs.writelog("Russound Script", "Loop Ending")
                      hs.runScript("Russound_Time.vb",False,False)
                  Else
                      'Do Nothing
                      'hs.writelog("Russound Script", "Music isn't on, exiting script.")
                  End If
              End Sub

              Comment


              • #8
                Is there a possibility that the script is running twice? Maybe add

                Code:
                hs.writelog("Russound Script", hs.ScriptsRunning)
                to the code and confirm.

                What does the Russound_Time.vb script do?

                Cheers
                Al
                HS 3.0.0.532: 1963 Devices 1141 Events
                Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                Comment


                • #9
                  Just tried it here with just the log writes and modified to get the info from one of my Squeezebox players and it behaves as expected:

                  Code:
                  Jan-03 5:10:07 PM	 	Russound Script	Loop Ending
                  Jan-03 5:10:07 PM	 	Russound Script	In Loop
                  Jan-03 5:09:57 PM	 	Russound Script	N.I.B.
                  Jan-03 5:09:47 PM	 	Russound Script	Black Sabbath
                  Jan-03 5:09:47 PM	 	Russound Script	In Loop
                  Jan-03 5:09:37 PM	 	Russound Script	N.I.B.
                  Jan-03 5:09:27 PM	 	Russound Script	Black Sabbath
                  Jan-03 5:09:27 PM	 	Russound Script	In Loop
                  Jan-03 5:09:17 PM	 	Russound Script	N.I.B.
                  Jan-03 5:09:07 PM	 	Russound Script	Black Sabbath
                  Jan-03 5:09:07 PM	 	Russound Script	In Loop
                  Jan-03 5:08:57 PM	 	Russound Script	N.I.B.
                  Jan-03 5:08:47 PM	 	Russound Script	Black Sabbath
                  Jan-03 5:08:47 PM	 	Russound Script	In Loop
                  Jan-03 5:08:37 PM	 	Russound Script	N.I.B.
                  Jan-03 5:08:27 PM	 	Russound Script	Black Sabbath
                  Jan-03 5:08:27 PM	 	Event	Running script in background: C:/program files (x86)/homeseer hs3/scripts/russoundtest.vb
                  Code:
                  Sub Main(ByVal parm As Object)
                  DiM Title as string
                  Dim Artist as string
                  Dim Is_Music_Playing as integer = hs.devicevalue(1387)
                      If Is_Music_Playing = 1 then
                          Do
                              Title = (hs.DeviceString(1395))
                              hs.writelog("Russound Script", Title)
                              hs.waitsecs(10)
                              Artist = (hs.deviceString(1397))
                              hs.writelog("Russound Script", Artist)            
                              hs.waitsecs(10)
                              hs.writelog("Russound Script", "In Loop")
                              Is_Music_Playing = hs.devicevalue(1387)
                          Loop Until Is_Music_Playing <> 1
                          hs.writelog("Russound Script", "Loop Ending")
                      Else
                          'Do Nothing
                          hs.writelog("Russound Script", "Music isn't on, exiting script.")
                      End If
                  End Sub
                  Cheers
                  Al

                  PS Don't judge me on the music
                  HS 3.0.0.532: 1963 Devices 1141 Events
                  Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                  Comment


                  • #10
                    Originally posted by sparkman View Post
                    Is there a possibility that the script is running twice? Maybe add



                    Code:
                    hs.writelog("Russound Script", hs.ScriptsRunning)


                    to the code and confirm.



                    What does the Russound_Time.vb script do?



                    Cheers

                    Al


                    I will check to see if it's running twice, as I guess that is possible with the way I have things running. The russound_time.vb is a script I have to display the time on the keypads when they are off (normally called by an event) but this forces it to display once turned off immediately and not wait for the event... but again I guess I could just add that to the event as well. Looking at the script now, I think I have that in the wrong place. Think I am just rambling now. Thanks Al, you have me some direction.

                    Comment


                    • #11
                      Al,
                      Thanks again for your help. I figured out the issue on this and though my resolution may not be clean, it is working. You were right, that the script was running multiple times... I figured this out when I saw HS a couple days ago startup too many scripts and locked out HS until reboot. I had the event set to run on device changes for the title which worked perfectly before when I had the script only displaying that data, but moving to a loop, this didn't work so well and explains why the screen would go crazy. What I did is set it to only allow one instance of the script to run, and though I get the warning in the logs that its already running each time the song changes, it is working as expected now.

                      Thanks again.
                      Attached Files

                      Comment


                      • #12
                        Originally posted by waynehead99 View Post
                        Al,
                        Thanks again for your help. I figured out the issue on this and though my resolution may not be clean, it is working. You were right, that the script was running multiple times... I figured this out when I saw HS a couple days ago startup too many scripts and locked out HS until reboot. I had the event set to run on device changes for the title which worked perfectly before when I had the script only displaying that data, but moving to a loop, this didn't work so well and explains why the screen would go crazy. What I did is set it to only allow one instance of the script to run, and though I get the warning in the logs that its already running each time the song changes, it is working as expected now.

                        Thanks again.
                        You're welcome, and glad you got it resolved!

                        Cheers
                        Al
                        HS 3.0.0.532: 1963 Devices 1141 Events
                        Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                        Comment

                        Working...
                        X