Announcement

Collapse
No announcement yet.

Run a Script or Script Command

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

    Run a Script or Script Command

    This Action will run a script or an immediate script. When the Action is selected, you may be are presented with a number of options. As in many other Event Actions, there will be a Basic (standard) Editing Mode or Advanced Editing mode. You can tell what mode the Event Group is in by the 3rd icon at the top.

    Standard is represented by a blue bird. Clicking on the icon will cause it to toggle into the other mode.

    Click image for larger version

Name:	Standard.png
Views:	1025
Size:	8.6 KB
ID:	1270292
    Advanced is represented by a red airplane

    Click image for larger version

Name:	Advanced1.png
Views:	1008
Size:	9.5 KB
ID:	1270293

    If you are in Basic Editing Mode and select the Action, you will see minimal options

    Click image for larger version

Name:	standard1.png
Views:	1027
Size:	27.6 KB
ID:	1270294
    Click on the red airplane and the Event will toggle into the Advanced Editing Mode

    Click image for larger version

Name:	RunAScript1.PNG
Views:	1169
Size:	33.7 KB
ID:	1270287
    • Wait for script to finish before continuing will suspend further processing of actions until the script is completed
    • Only allow a single instance to run at a time will prevent the script from being launched again if it is currently running
    • Immediate script command allows running a single line scripting function. That will be covered below
    When running a script use the Edit button to open a file browser to the /Scripts directory under the HomeSeer root

    Click image for larger version

Name:	RunAScript2.png
Views:	1075
Size:	76.7 KB
ID:	1270288

    Here you can select a script to use. After selecting one and clicking on Submit, you will see the script in an editing window.

    Click image for larger version

Name:	RunAScript3.PNG
Views:	1053
Size:	57.6 KB
ID:	1270289

    Here you can edit the script or leave it alone. If you do edit it, you must click on Save Script Edits to commit the changes to the script. There are also two windows, one to select a Subroutine or Function and the second to pass Parameters to the script. Both of these have pop-up editing boxes like most Event entries. In the script above there is only one Sub so it need not be named and two parameters can be passed - the Reference ID of a dimmer and the percentage (+-) to dim the device. Here it will increase the level of device 1234 by 10%. The parameters are passed to the script and the "Main" subroutine will be run.

    Click image for larger version

Name:	RunAScript7.PNG
Views:	1042
Size:	39.2 KB
ID:	1270295

    You can also choose to run an Immediate Script Command. This is a single line scripting function that you can enter to be run with the action

    Click image for larger version

Name:	RunAScript4.PNG
Views:	1012
Size:	30.9 KB
ID:	1270290

    Here is the hs.writelog command creating a single log entry with the Type "Trace" and the message "This is a test log entry.

    Click image for larger version

Name:	RunAScript5.PNG
Views:	1030
Size:	32.8 KB
ID:	1270291

    This will simply create a log entry

    Dec-28 12:34:46 PM Trace This is a test log entry

    Creating scripts is beyond the scope of these threads, but this should allow you to run your own scripts or those form other authors. All scripts must be in the \HomeSeer HS3\scripts directory.


    #2
    Regarding this:

    "Only allow a single instance to run at a time will prevent the script from being launched again if it is currently running"

    This has never been clear to me... Found some old threads, but for HS2....
    Does this apply to the script or the event? What's not clear to me is: if the same script is called by event A, and event B calls the script before event A is finished calling the script, will two instances of the script be running at the same time? Or it will run for event A but not B? Or A then B?

    Comment


      #3
      It won’t allow multiple copies of the script to run, even if they are called from different events.
      HS 3.0.0.548: 1990 Devices 1172 Events
      Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

      Comment


        #4
        Question: Does the second event pause waiting for the first event to finish running that script, or does the second event just skip it?

        Comment


          #5
          Originally posted by aa6vh View Post
          Question: Does the second event pause waiting for the first event to finish running that script, or does the second event just skip it?
          By my experience, it skips it.

          Very recent example:
          Feb-27 7:46:16 AM Warning Not running script since its already running: C:/Program Files (x86)/HomeSeer HS3/scripts/IR-UDP-SEND.vb Single instance option enabled in event properties

          Comment


            #6
            Originally posted by aa6vh View Post
            Question: Does the second event pause waiting for the first event to finish running that script, or does the second event just skip it?
            It skips it.
            HS 3.0.0.548: 1990 Devices 1172 Events
            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

            Comment


              #7
              Thanks for the clarifications!

              Comment


                #8
                Thanks guys. I was too lazy to see for myself. And wow. I was actually expecting it to wait. Perhaps this needs to be made more clear in documentation, as not having a script run (sometimes) can be a source of confusion to a newby trying to figure out what is going wrong (newby's don't always read logs...)

                Comment


                  #9
                  Neither (wait till finish nor allow only one) of the solutions are great ones.
                  On some events, there is feedback so the event can just trigger again after a few seconds until it works. In other cases, I use immediate scripts where I can so that two events aren't trying to run the same script (even if each immediate is doing the same thing, more or less).

                  Comment


                    #10
                    You could also just create a second/third/etc. copy of the same script with a slightly different name, but if you have a good reason to check that box (i.e. you are modifying devices and don't want conflicts there), then that does not help. I tend to write small scripts that execute fast so rarely run into an issue with that limitation.
                    HS 3.0.0.548: 1990 Devices 1172 Events
                    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                    Comment


                      #11
                      Or you could use a global variable (or counter) as a semiphore: The script checks the global, and if on, sleeps then loops back to check. If off, set it, do its business, and reset it when done.

                      Comment


                        #12
                        What is the syntax for doing an event immediate script command to write a device value (by ref) and/or a device string to the HS log?
                        I can write comments with no problem, but haven't been able to add writing a DeviceValue to the info to be logged.
                        e.g.: &hs.WriteLogEX "*******","Diagnostic - OfcDuctFan s/b ON (Winter) XXXXXXXXXXXXX", "#EA58D5"

                        Comment


                          #13
                          Originally posted by Jayhawk View Post
                          What is the syntax for doing an event immediate script command to write a device value (by ref) and/or a device string to the HS log?
                          I can write comments with no problem, but haven't been able to add writing a DeviceValue to the info to be logged.
                          e.g.: &hs.WriteLogEX "*******","Diagnostic - OfcDuctFan s/b ON (Winter) XXXXXXXXXXXXX", "#EA58D5"
                          If I understand your question....
                          &hs.WriteLogEX "*******","Some Device is " & hs.DeviceValueByName("Some Device"), "#EA58D5"

                          Comment


                            #14
                            Thanks... missed putting quote marks around ref num.

                            Comment

                            Working...
                            X