Announcement

Collapse
No announcement yet.

Remote Script Gallery

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Create a desktop shortcut on a remote computer to run any HomeSeer event

    Create a desktop shortcut on a remote computer to run any HomeSeer event

    1) Save the following script as remote_runevent.cs in the HomeSeer 2\Scripts directory on the remote computer

    Code:
    void Main( object param )
    {
     string eventString = param.ToString();
     if( hs.EventExists( eventString ) )
     {
      hs.TriggerEvent( eventString );
     }
    }
    2) Right click the desktop on the remote computer
    3) Choose New - Shortcut
    4) Type the following as the shortcut target including quotes:
    "C:\Program Files\HomeSeer 2\HsScript.exe" remote_runevent.cs name the HomeSeer event

    Now you can double-click this icon to run the HomeSeer event from your remote computer.


    [EDIT] You can then assign the HomeSeer event to any Hotkey such as F12: Open the desktop shortcut property page, and set the hotkey in the shortcut tab.
    Last edited by stipus; March 28, 2009, 07:24 PM.
    --
    stipus

    Comment


      #17
      Restart HomeSeer using the Script Client

      The script needs to be started on the HS machine.... not on a remote computer...


      save this script as hs_restart.cs
      Code:
      #USING System.Diagnostics
      #USING System.Threading
      
      void Main( object param )
      {
         Process[] processArray = null;
         bool stillHereBool = true;
         bool frozenBool = false;
         int countInt = 0;
      
         // SHUTDOWN HOMESEER
         hs.ShutDown();
      
         // WAIT UNTIL PROCESS IS FINISHED OR TIMEOUT OCCURED
         while( stillHereBool && (!frozenBool) )
         {
            Thread.Sleep( 2000 );
            processArray = Process.GetProcessesByName( "HomeSeer" );
            if( processArray.Length == 0 )
            {
               stillHereBool = false;
            }
      
            // WE DID WAIT MORE THAN 150x2=300 seconds !
            countInt++;
            if( countInt > 150 )
            {
               frozenBool = true;
            }
         }
      
         // IF HOMESEER IS FROZEN, JUST KILL THE PROCESS
         if( stillHereBool && frozenBool )
         {
            processArray[0].Kill();
            Thread.Sleep( 5000 );
         }
      
         // RESTART HS PROCESS
         Process.Start( @"C:\Program Files\HomeSeer 2\HomeSeer.exe" );
      }
      Last edited by stipus; November 19, 2007, 05:17 AM.
      --
      stipus

      Comment


        #18
        Remotely turn ON/OFF computer monitors

        Here is the remote_monitor_power.cs script
        [EDIT] This script does not work under Vista

        If you have a motion detector in your room, you can easily have your computer monitor wake-up as you enter the room.

        If you invoke this script without any parameter, it will turn on the monitor.
        You can also invoke with the following parameters:
        - ON
        - OFF
        - LOW (low power mode)


        Code:
        #USING System.Runtime.InteropServices
        
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
        
        void Main( object param )
        {
         IntPtr HWND_BROADCAST = new IntPtr(0xffff);
         uint WM_SYSCOMMAND = 0x0112; 
         int SC_MONITORPOWER = 0xF170; 
        
         // WAIT TO LET DESKTOP SETTLE 
         System.Threading.Thread.Sleep( 500 );
        
         switch( param.ToString().ToUpper() )
         {
          case "ON":
           SendMessage( HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1 );
           break;
          case "OFF":
           SendMessage( HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2 );
           break;
          case "LOW":
           SendMessage( HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 1 );
           break;
          default:
           SendMessage( HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1 );
           break;
         }
        }
        Last edited by stipus; January 18, 2008, 05:04 PM.
        --
        stipus

        Comment


          #19
          Remotely Control Hitachi TV via RS232

          Here is a new script contributed by a board member.

          This script allows you to remotely control some Hitachi TVs via RS232
          It should work with Hitachi plasma and LCD tvs series LD5000 & LD7000, PD5000 & PD7000

          Hitachi RS232 control documentation (useful if you want to add oher commands):
          http://www.hitachidigitalmedia.com/p...000Chassis.exe

          Remote VB Script pdp_command.vb:

          Code:
          Dim port as System.IO.Ports.SerialPort=new System.IO.Ports.SerialPort("COM3", 9600, System.IO.Ports.Parity.None, 7, System.IO.Ports.StopBits.One)
           
          Sub Main(param as object)
            Dim resp_ok As Boolean
            Port.Open()
            resp_ok = start_byte()
            resp_ok = command_string(param)
            resp_ok = stop_byte()
            Port.Close()
            hs.WriteLog("pdp_command", param)
          End Sub
           
          Function start_byte() as boolean
            Dim tab() As Byte = {&H5}
            Port.Write(tab, 0, 1)
            System.Threading.Thread.Sleep(50)
            start_byte = True
          End Function
           
          Function stop_byte() as boolean
            Dim tab() As Byte = {&H4}
            Port.Write(tab, 0, 1)
            stop_byte = True
          End Function
           
          Function command_string(byval command_name as string) as boolean
            Select case command_name
              Case "on"
                dim tab() as byte={&H02, &H36, &H45, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H31, &H03}
                Port.Write( tab, 0, 14 )
                command_string=true
           
              Case "off"
                dim tab() as byte={&H02, &H36, &H45, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H03}
                Port.Write( tab, 0, 14 )
                command_string=true
          
              Case "mute"
                dim tab() as byte={&H02, &H32, &H39, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H30, &H31, &H03}
                Port.Write( tab, 0, 14 )
                command_string=true
          
              Case "unmute"
              Case Else
                command_string = True
            End Select
           
            System.Threading.Thread.Sleep(50)
          End Function
          Last edited by stipus; October 11, 2007, 09:38 AM.
          --
          stipus

          Comment


            #20
            Send key sequences to a remote computer

            This visual basic remote script is contributed by a board member.

            With this script, HomeSeer can control most applications on a remote computer by sending key sequences to the remote computer.

            The contributor uses this script to remote control Media Portal from HomeSeer.

            There are some comments in the script, such as how to send special keys
            ABCD --> Main( "SHIFT+a+b+c+d" )
            CTRL-S --> Main( "CONTROL+s" )

            You can even send CTRL-ALT-DEL to the remote computer --> Main("CONTROL+ALT+DELETE") !!
            Attached Files
            --
            stipus

            Comment


              #21
              New version of the script to control several lights

              This new version adds a popup slider control when you click on the device name. It's included in plugin V1.10.2.2+

              The popup slider shows current dim level, and you can change it easily by moving the slider.

              The slider only appears with devices that can dim.

              The slider checks the device type, and sends preset dim, direct dim, leviton dim, direct dim, or relative dim/bright commands.

              The script windows is semi-transparent, and always on top on your desktop. I found very useful to have it running on each computer, to control all lights in the room your computer is.
              Attached Files
              Last edited by stipus; November 21, 2007, 08:37 AM.
              --
              stipus

              Comment


                #22
                Control master volume on any XP/W2K/W2K3 remote computer

                With the attached script, you can control from HomeSeer the master volume on any remote computer running the script client.

                Unzip and copy remote_volume.cs to the remote computer HomeSeer 2\Scripts directory

                From any HomeSeer event:

                - Choose the Exec Remote Script action
                - Type the remote computer name as the target
                - Type remote_volume.cs as the script name
                - Type one of the following as the script parameter:

                VOLUP --> To increase volume by 10%
                VOLDOWN --> To decrease volume by 10%
                VOLSET 0 - 100 --> To set the volume between 0 and 100

                Example From any HomeSeer script or from HomeSeer immediate Script Command:

                &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume.cs", "VOLSET 60"

                &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume.cs", "VOLUP"

                &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume.cs", "VOLDOWN"
                Attached Files
                Last edited by stipus; December 31, 2007, 07:21 PM.
                --
                stipus

                Comment


                  #23
                  Control master volume on any VISTA remote computer

                  This script is the same as above, but it's a special version for VISTA, as the mixer API is different under vista.

                  [EDIT] The script is also compatible with Windows Seven.
                  Attached Files
                  Last edited by stipus; November 25, 2009, 06:20 PM.
                  --
                  stipus

                  Comment


                    #24
                    Wake on Lan

                    Here is a script for wake on lan.

                    This script sends the magic "wake on lan packet" for the computer mac address you specify as a script parameter.

                    This might be obvious, but I prefer to state that this script can't be run with an asleep computer as the script target. You need to run it on the HomeSeer server, or on any computer on your lan (that is not asleep).

                    The script parameter is the MAC address of the computer to wake up. You can use - or : to separate each mac address component.

                    Sample use:

                    Code:
                    C:\Program Files\HomeSeer 2>hsscript wol.cs 00:2A:57:3C:8E:A1
                    Attached Files
                    --
                    stipus

                    Comment


                      #25
                      New version of the remote Vista Volume control script. You can select Sound Card !

                      Here is a new version of the remote vista volume control script.

                      This script has an aditionnal parameter to select the sound card, if you have several installed on your system.

                      Unzip and copy remote_volume_vista_card.cs to the remote computer HomeSeer 2\Scripts directory


                      Example From any HomeSeer event:

                      - Choose the Exec Remote Script action
                      - Type the remote computer name as the target
                      - Type remote_volume_vista_card.cs as the script name
                      - The script parameter starts with the sound card index followed by volume command. It's up to you to find the right sound card indexes

                      0 VOLUP --> To increase volume by 10% on sound card #0
                      2 VOLDOWN --> To decrease volume by 10% on sound card #2
                      1 VOLSET 0 - 100 --> To set the volume between 0 and 100 on sound card #1


                      Example From any HomeSeer script or from HomeSeer immediate Script Command:

                      &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume_vista_card.cs", "0 VOLSET 60"

                      &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume_vista_card.cs", "0 VOLUP"

                      &hs.Plugin("Script Connector").ExecRemoteSub "target computer", "remote_volume_vista_card.cs", "0 VOLDOWN"


                      Example From the command line, or desktop shortcut :

                      C:\Program Files\HomeSeer 2\HSSCRIPT.EXE remote_volume_vista_card.cs 1 VOLSET 50
                      Attached Files
                      Last edited by stipus; November 20, 2008, 03:12 PM.
                      --
                      stipus

                      Comment


                        #26
                        Run or activate any application on a remote computer

                        The script parameter is the full application path
                        eg1: c:\program files\whatever\netvuobserver.exe
                        eg2: notepad.exe (already in the computer PATH)

                        If the application is already running, the application main window is brought to foreground.

                        If the application is not running, the process is started.

                        --

                        - Unzip and save remote_activateapp.cs to the HomeSeer 2\Scripts directory on your remote computer(s).
                        - From any HomeSeer event, add a "Exec Remote Script" action
                        - Type the name of the remote script client or * to execute the script on all remote computers.
                        - Enter the remote script name remote_activateapp.cs
                        - Enter the full path to the .EXE to activate as the script parameter

                        [EDIT] New script version posted.
                        Attached Files
                        Last edited by stipus; December 7, 2008, 09:24 AM.
                        --
                        stipus

                        Comment


                          #27
                          Activate a window by caption

                          The script parameter must be the caption of the Window to activate.

                          The window must be a main window... that is ... not a subwindow.
                          Attached Files
                          --
                          stipus

                          Comment


                            #28
                            Activate / Deactivate the Screen Saver on a remote computer

                            Here is a script to activate/deactivate the Windows screen saver. This can be very usefull if you don't want the screen saver to kick off at certain times...

                            The script does not kill the screen saver if it's already active. It only changes the Windows setting to activate or deactivate the screen saver.

                            The script must be called with the parameter ON or OFF

                            EG from command line:

                            HSSCRIPT remote_screensaver.cs ON
                            Attached Files
                            Last edited by stipus; February 4, 2009, 11:51 AM.
                            --
                            stipus

                            Comment


                              #29
                              Close a Window by title on a remote computer

                              You should pass the Window title as the script parameter. The spelling must be exact.

                              eg: "Google - Windows Internet Explorer"

                              remote_closewindow.cs
                              Code:
                              #USING System.Diagnostics
                              #USING System.Runtime.InteropServices
                               
                              [DllImport("user32.dll", SetLastError = true)]
                              static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
                               
                              [return: MarshalAs(UnmanagedType.Bool)]
                              [DllImport("user32.dll", SetLastError = true)]
                              static extern bool PostMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
                               
                              public static readonly uint     WM_SYSCOMMAND     = 0x0112;
                              public static readonly uint     SC_CLOSE          = 0xF060;
                               
                              void Main( object param )
                              {
                                 IntPtr hWnd = FindWindow(null,param.ToString());
                                 if( hWnd != IntPtr.Zero )
                                 {
                                    PostMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, IntPtr.Zero );
                                 }
                              }
                              --
                              stipus

                              Comment


                                #30
                                Monitor a process on a remote computer

                                (Originally posted here)

                                This script will let you monitor a process on a remote computer and pass the status of the process to a virtual device.


                                Place the followng script in the \Script folder on your rempte computer. Rename it whatever you want, I've named it "remote_procstat.vb"

                                Code:
                                Dim proc As String
                                Dim dev As String
                                
                                Sub Main(ByVal param As Object)
                                
                                    'Organizing devices
                                    Dim input() As String = param.ToString.Split(CChar(";"))
                                    If input.GetLength(0) < 1 Then
                                        hs.WriteLog("Script", "Not enough parameters")
                                        Exit Sub
                                    Else
                                        proc = input(0).ToString
                                        dev = input(1).ToString
                                    End If
                                
                                    Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(proc)
                                
                                    If p.Length = 0 Then
                                        UpdateDevice(0)
                                
                                    ElseIf p.Length > 1 Then
                                        UpdateDevice(1)
                                
                                    ElseIf p.Length = 1 Then
                                        If p(0).Responding Then
                                            UpdateDevice(2)
                                
                                        Else 'not responding
                                            UpdateDevice(3)
                                
                                        End If
                                    End If
                                
                                End Sub
                                
                                Sub UpdateDevice(ByVal status As Integer)
                                    Select Case status
                                        Case Is = 0
                                            hs.SetDeviceString(dev, proc & " is not running")
                                        Case Is = 1
                                            hs.SetDeviceString(dev, proc & " has multiple instances")
                                        Case Is = 2
                                            hs.SetDeviceString(dev, proc & " is alive and kicking")
                                        Case Is = 3
                                            hs.SetDeviceString(dev, proc & " does not respond")
                                    End Select
                                    hs.SetDeviceStatus(dev, status)
                                End Sub
                                If you are planning on having many instances of the same process running at the same time, and want to check the status of them all, then simply replace If p.Length = 0 Then [...] End if in the Main sub with this:
                                Code:
                                        Dim bolAllAreRunning As Boolean = True
                                        For Each pr As Process In p
                                            If Not pr.Responding Then bolAllAreRunning = False
                                        Next
                                        If p.Length = 0 Then
                                            UpdateDevice(0)
                                        ElseIf bolAllAreRunning Then
                                            UpdateDevice(2)
                                        Else
                                            UpdateDevice(3)
                                        End If

                                You also need to create a "Status Only" device, but I'm sure you know how to do that. And last, you need to create an event to run the remote script whenever you want to run the test. In the "Parameter" textbox be sure to enter the process name (as in "Excel", "winword", "explorer", basically the name before ".exe" I think) and then a semi colon (";") and then the code for the status device.

                                See below for my an example of script settings.




                                This script can of course be updated and made better (i.e. more tests for the process). If anyone updates the script, I'd love to see the it.
                                HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                                Running on Windows 10 (64) virtualized
                                on ESXi (Fujitsu Primergy TX150 S8).
                                WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                                Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                                Comment

                                Working...
                                X