Announcement

Collapse
No announcement yet.

Using Random Phrase items as input to hs.TriggerEvent Issue

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

    Using Random Phrase items as input to hs.TriggerEvent Issue

    In HS2 I had a little script program that would call a randomly selected event and I would like to do the same in HS3 but I am having trouble. Could you give me any help.


    HS2 Script:
    The old HS2 randomizing program was called "ROC-Rnd" and it had a list category called "Music" which had 9 selections in it (Music01, Music02...Music08, Music09).
    I had 9 events that were called Music01, Music02...Music08, Music09 which had different playlists in them.
    The random program would select one of them (Music01, Music02...Music08, Music09) and the hs.triggerevent would start that one up.

    Here is the old HS2 script:
    Sub Main
    hs.TriggerEvent hs.plugin("ROC-Rnd").random("Music")
    End Sub


    HS3 Script:
    The new HS3 randomizer program is called "Random" and I have sent up a list category within Random called "Music" which has 9 selections in it (Script Music01, Script Music02...Script Music08, Script Music09).
    I have 9 events in an event category called "Script." The events are called Music01, Music02...Music08, Music09. Each has a different playlists in them.

    If I do the following script, the music is selected correctly and plays

    Sub Main
    hs.TriggerEvent ("Script Music01")
    End Sub

    So I know that the triggerevent is able to call and execute the event "Scirpt Music0#" correctly


    Now in the Random program I can select the a list (Random Phrase Category) called "Music" and the program gives me the following

    Script Usage:
    sVar = hs.PluginFunction("Random","","random", new Object(){"Music",False})

    Scripts Music07

    Opening up the Random Phrase Category multiple times give me different "Scripts Music0#" so I know the sVar = hs.PluginFunction("Random","","random", new Object(){"Music",False}) is give me randomly selected text back.


    So I created the following script

    Sub Main
    sVar = hs.PluginFunction("Random","","random", new Object(){"Music",False})
    hs.TriggerEvent ("sVar")
    End Sub

    But instead of running I get:

    Jan-03 1:59:23 PM Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/light_test.txt1025:Expected end of statement in line 2 More info: Expected end of statement


    Can you help me with this?

    Bill

    Current Date/Time: 1/4/2018 10:17:45 AM
    HomeSeer Version: HS3 Standard Edition 3.0.0.368
    Operating System: Microsoft Windows 10 Home - Work Station
    System Uptime: 1 Day 18 Hours 30 Minutes 59 Seconds
    IP Address: 192.168.2.101
    Number of Devices: 418
    Number of Events: 284
    Available Threads: 400

    Enabled Plug-Ins
    3.0.14.0: BLMediaPlayer
    2.0.22.0: BLUPS
    3.4.1.0: Caddx
    3.0.0.1: Random
    3.0.0.14: RCSStat
    1.0.0.5: Restart
    3.0.6542.35207: UltraWeatherWU3
    3.0.0.40: UPBSpud
    3.0.1.130: Z-Wave

    #2
    Try running the following script as a VB.NET script (call it light_test.vb)

    Does that error?

    Code:
        Sub Main(ByVal Parm As Object)
            Dim sVar As String = ""
            sVar = hs.PluginFunction("Random", "", "random", New Object() {"Music", False})
            If hs.EventExists(sVar) Then
                hs.TriggerEvent("sVar")
            Else
                hs.WriteLog("Random", "Event '" & sVar & "' does not exist!")
            End If
        End Sub
    Jon

    Comment


      #3
      I inputted the script as follows:

      Sub Main(ByVal Parm As Object)
      Dim sVar As String = ""
      sVar = hs.PluginFunction("Random", "", "random", New Object() {"Music", False})
      If hs.EventExists(sVar) Then
      hs.TriggerEvent("sVar")
      Else
      hs.WriteLog("Random", "Event '" & sVar & "' does not exist!")
      End If
      End Sub

      But got the error:

      Jan-08 4:51:23 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\light_test.vb: compiler initialization failed unexpectedly: The system cannot find the file specified.
      Jan-08 4:51:23 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\light_test.vb: could not find library 'Scheduler.dll'

      What is missing?

      Comment


        #4
        Is there a way to write this as a .txt file instead of a .vb file?

        Comment


          #5
          The point of going to vb was to see if this line worked correctly:

          sVar = hs.PluginFunction("Random", "", "random", New Object() {"Music", False})

          I cannot see how you got that error if you selected the script via a Homeseer event?
          Jon

          Comment


            #6
            I am total new to vb. Okay - clueless. Can you direct me to a easy tutorial on how to compile a vb file? I have vb studio 2017 on my homeseer machine. I have tried to play around with it to no avail. From the error above it looks like the Scheduler.dll location isn't in the vb file.

            Comment


              #7
              No need to compile. You just copy the code in a text editor, save it as light_test.vb in your Homeseer scripts directory and then select the script to run via a Homeseer event.
              Jon

              Comment


                #8
                So here is what is driving me nuts.

                I created a file called Working_Trigger_Event.txt ... it has one line

                hs.TriggerEvent ("Scripts Music07")

                Put it in a script event and it works every time. I do get an error running script I get the following in the log file:

                Jan-10 2:44:26 PM Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/Working_Trigger_Event.txt0: in line 0 More info: Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
                Jan-10 2:44:26 PM BLMediaPlayer Info Player volume level was set to 10!
                Jan-10 2:44:26 PM Event Event Trigger "Scripts Music07"
                Jan-10 2:44:26 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/Working_Trigger_Event.txt
                Jan-10 2:44:26 PM Event Event Trigger "Scripts Scripts test Random"
                Jan-10 2:44:26 PM Event Event Scripts Scripts test Random triggered by the event page 'Run' button.


                I take the same working txt file and call it vb and it doesn't work at all (with or without Sub Main/End Sub around it. Why can't it find the Scheduler.dll? Is that the reason the compiler fails? Here is the log:


                Jan-10 2:45:34 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Working_Trigger_Event.vb: compiler initialization failed unexpectedly: The system cannot find the file specified.
                Jan-10 2:45:34 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Working_Trigger_Event.vb: could not find library 'Scheduler.dll'
                Jan-10 2:45:34 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/Working_Trigger_Event.vb
                Jan-10 2:45:34 PM Event Event Trigger "Scripts Scripts test Random"
                Jan-10 2:45:34 PM Event Event Scripts Scripts test Random triggered by the event page 'Run' button.


                Any thoughts?

                Comment


                  #9
                  I'm unsure why you are getting the Scheduler.dll error but you must wrap code as a sub i.e.


                  For .txt scripts:

                  Code:
                  Sub main()
                  hs.TriggerEvent "Scripts Music07"
                  End sub
                  For .vb scripts:

                  Code:
                  Sub Main(ByVal Parm as Object)
                  hs.TriggerEvent ("Scripts Music07")
                  End sub
                  I'm not sure what text editor you are using but try using Notepad to copy and save to your scripts directory.
                  Jon

                  Comment


                    #10
                    Success - both the txt and the vb files work. Also I fixed the scheduler.dll issue by adding a cd c:\pathtoHS3directory\ to the batch file that starts HS3.exe.

                    Now for the hard part.

                    So I redid the script you gave me:

                    Sub Main(ByVal Parm As Object)
                    Dim sVar As String = ""
                    sVar = hs.PluginFunction("Random", "", "random", New Object() {"Music", False})
                    If hs.EventExists(sVar) Then
                    hs.TriggerEvent("sVar")
                    Else
                    hs.WriteLog("Random", "Event '" & sVar & "' does not exist!")
                    End If
                    End Sub

                    as a vb file and got the following:

                    Jan-11 1:31:03 PM Random Get phrase between 0 and 8
                    Jan-11 1:31:03 PM Random Array Rows: 8, Cols: 3
                    Jan-11 1:31:03 PM Random SQL=SELECT phraseID, phraseText, categoryID, phraseVoice FROM phrases WHERE isActive = 1 AND categoryID IN (SELECT categoryID FROM Category WHERE lCase(categoryText) = 'music' ) ORDER BY phraseID desc
                    Jan-11 1:31:03 PM Random Function: random
                    Jan-11 1:31:02 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/RandomPick.vb
                    Jan-11 1:31:02 PM Event Event Trigger "Scripts Scripts test Random"
                    Jan-11 1:31:02 PM Event Event Scripts Scripts test Random triggered by the event page 'Run' button.


                    So it looks like most of the script executed but I don't see what the output from the random PluginFunction is. Do you?

                    It stopped executing and doesn't appear to have gotten to the TriggerEvent line. Is that how you read it?

                    Comment


                      #11
                      After the line:

                      sVar = hs.PluginFunction("Random", "", "random", New Object() {"Music", False})

                      Add:

                      hs.Writelog("Random","Result: " & sVar)

                      That will show the result in the log. Other than that, you need to take this up with the Plugin author.
                      Jon

                      Comment


                        #12
                        Thank you, that worked. For the record:

                        Here is the vb file. I added the hs.TriggerEvent to it and it to work:

                        Sub Main(ByVal Parm As Object)
                        Dim sVar As String = ""
                        sVar = hs.PluginFunction("Random","","random",New Object() {"Music",False})
                        hs.WriteLog("Random","Result: " & sVar)
                        hs.TriggerEvent(sVar)
                        End Sub

                        It is selecting different items from the music category and putting them in the TriggerEvent() statement and the TriggerEvent is firing them off correctly too.

                        The log file created looks like:

                        Jan-12 10:34:23 AM Event Event Trigger "Scripts Music01"
                        Jan-12 10:34:23 AM Random Result: Scripts Music01
                        Jan-12 10:34:23 AM Random Get phrase between 0 and 8
                        Jan-12 10:34:23 AM Random Array Rows: 8, Cols: 3
                        Jan-12 10:34:23 AM Random SQL=SELECT phraseID, phraseText, categoryID, phraseVoice FROM phrases WHERE isActive = 1 AND categoryID IN (SELECT categoryID FROM Category WHERE lCase(categoryText) = 'music' ) ORDER BY phraseID desc
                        Jan-12 10:34:23 AM Random Function: random
                        Jan-12 10:34:23 AM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/RandomPick2.vb
                        Jan-12 10:34:23 AM Event Event Trigger "Scripts Scripts test Random"

                        Comment

                        Working...
                        X