Announcement

Collapse
No announcement yet.

Scripts with common subroutine

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

    #31
    Originally posted by B1Trash View Post
    How about using hs.RunScript or hs.RunScriptFunc

    https://homeseer.com/support/homesee...ipts_runex.htm

    https://homeseer.com/support/homesee...scriptfunc.htm

    It works for me on my Zee S2. I use it to initialize all my scripts on startup so I don't have to wait for things to compile the first use.

    -Jon
    I do this as well. Currently I have a script set to control the lights with motions (allows me to only have to create 1 event for each light). I have 2 scripts to do the work, one to control the light, and another to create the delayed event to turn the light off. I run this function and pass the parameters I need from the previous script. I have them split because I wanted to light latency to be very minimal. Works very well.

    Comment


      #32
      Well, that's one way to do it. i'll give it a try.

      Thanks
      Don

      Comment


        #33
        So, is it true that there is just no way to include common subs with each vb.net script?

        Comment


          #34
          Originally posted by joegr View Post
          So, is it true that there is just no way to include common subs with each vb.net script?
          No it is not true. One person seems to be having trouble with it, but many others are using #include script.vb successfully.

          Comment


            #35
            Not a coder, just grasping at straws, but I remember having trouble getting some of my cut-and-paste scripts to work until I got this line correct in my config.ini file. Could that be it?

            ScriptingReferences=System.Web;System.Web.dll;System.Web.Ext ensions;System.Web.Extensions.dll
            HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
            Home Assistant 2024.3
            Operating System: Microsoft Windows 11 Pro - Desktop
            Z-Wave Devices via two Z-Net G3s
            Zigbee Devices via RaspBee on RPi 3b+
            WiFi Devices via Internal Router.

            Enabled Plug-Ins
            AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

            Comment


              #36
              There may be a little confusion over what the "include" statement does. What is does is to insert the contents (the actual text) of the include file, at the spot where the include statement is.

              Say that a file x.vb constains:

              Code:
              Private Function Foo() As Boolean
                Return True
              End Function
              And your main source contains:

              Code:
              #include x.vb
              Sub Main(parms As Object)
                If Foo() Then hs.WriteLog("Foo", "Is True")
              End Sub
              It will be compiled as if the source contained:

              Code:
              Private Function Foo() As Boolean
                Return True
              End Function
              Sub Main(parms As Object)
                If Foo() Then hs.WriteLog("Foo", "Is True")
              End Sub
              Currently, there is no way to have a "compiled" object code library. You must insert (duplicate) your own common routines into each module, either by copying the source statements, or by using the #include statement.

              (Actually there are ways to have a compiled object code library, but doing so is way too complicated to describe here, and way to much trouble to do anyway).

              Comment


                #37
                As I'm the person having the #include issue, I appreciate the explanation of how it's suppose to work. I tried your example but the script errored out with 'foo not declared'. I suspect I might not have the correct scripting reference as suggested above. I'd try it, but I already have so many scripting references that it runs off the page.
                Don

                Comment


                  #38
                  Originally posted by donstephens View Post
                  As I'm the person having the #include issue, I appreciate the explanation of how it's suppose to work. I tried your example but the script errored out with 'foo not declared'. I suspect I might not have the correct scripting reference as suggested above. I'd try it, but I already have so many scripting references that it runs off the page.
                  Maybe you could show us the two files (the contents of the #include file and the contents of the script that includes it). Based on some of the previous posts in this thread, it may be as simple as misplaced text causing a syntax error (HS's vb .net is notorious for giving poor error messages).

                  Comment


                    #39
                    Originally posted by donstephens View Post
                    As I'm the person having the #include issue, I appreciate the explanation of how it's suppose to work. I tried your example but the script errored out with 'foo not declared'. I suspect I might not have the correct scripting reference as suggested above. I'd try it, but I already have so many scripting references that it runs off the page.
                    Include is not working for me either.

                    Comment


                      #40
                      Vb.net does not have an #include statement.

                      Comment


                        #41
                        Originally posted by baudi View Post
                        Vb.net does not have an #include statement.
                        I believe it was previously stated this was a HomeSeer specific feature by the HS compiler, not a generic vb.net function.

                        Comment


                          #42
                          Originally posted by aa6vh View Post

                          Maybe you could show us the two files (the contents of the #include file and the contents of the script that includes it). Based on some of the previous posts in this thread, it may be as simple as misplaced text causing a syntax error (HS's vb .net is notorious for giving poor error messages).
                          I was using the example given in post #36.
                          Don

                          Comment


                            #43
                            Originally posted by baudi View Post
                            Vb.net does not have an #include statement.
                            Not to be contrary, but #include works fine for me (using vb .net).

                            Edited to add: Standard C# does not have an #include either, but it does work in Homeseer.

                            Comment


                              #44
                              Originally posted by donstephens View Post

                              I was using the example given in post #36.
                              Okay. Now I have to ask how are you creating those script files? Directly on the Homseer server system, or through the web interface?

                              What I do using the web interface is create a dummy event (manually executed) that invokes a single script action, and then specify my "library" source stuff for that script file. (Rather than create a dummy event, you could use an existing event and simply set the "Never" option on that script action to keep it from actually running).

                              Make sure that the script files are exactly as shown, do not "embellish" them until you get it working! Create a dummy event just running script "x.vb", then another event running the main script.

                              Comment


                                #45
                                Originally posted by aa6vh View Post

                                Okay. Now I have to ask how are you creating those script files? Directly on the Homseer server system, or through the web interface?

                                I'm using notepad++ on a remote machine saving to the HomeSeer/scripts directory
                                My two files are:
                                test2.vb

                                PHP Code:
                                #include x.vb
                                Sub Main(parms As Object)
                                If 
                                Foo() Then hs.WriteLog("Foo""Is True")
                                End Sub 
                                x.vb:

                                PHP Code:
                                Sub Main(byVal Args As String)

                                End Sub

                                Private Function Foo() As Boolean
                                Return True
                                End 
                                Function 
                                What are you using for your ScriptingReferences?



                                Don

                                Comment

                                Working...
                                X