Announcement

Collapse
No announcement yet.

How to start and stop speaker client when HS starts or is shutdown.

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

  • How to start and stop speaker client when HS starts or is shutdown.

    Rather than have to manually start the speaker client, and better than having it in the startup menu of windows, it can be started from the HomeSeer startup script. If you use this method it is also advisable to have HomeSeer shut the speaker client down when it does, this is done in the shutdown script.

    First lets start a single speaker client on the HomeSeer host computer.
    Code:
    sub main()
     
     if not hs.IsApplicationRunning("Speaker") then
          hs.launch hs.getapppath & "\speaker.exe","Main", , 0
     end if
     
    end sub
    Alternatively this will do the same.
    Code:
    sub main()
     
    if not hs.IsApplicationRunning("Speaker") then
    lRet = hs.Launch(hs.GetAppPath & "\speaker.exe","Main",,1)
    end if
     
    end sub
    The first line if not hs.IsApplicationRunning("Speaker") then is checking to see if the speaker client is running, and if it is not HomeSeer will start it.

    in the script the line hs.GetAppPath & "\speaker.exe","Main",,1 the word Main is the name of the speaker client. It is what you specify in speak commands as to which speaker client you wish to do the announcement, this comes into play if you have more than one speaker client.

    The ,,1) is the windows priority you wish speaker client to run at. 0 is normal, 1 is above normal, ie. it takes a bit more priority when running, and memory.

    To start multiple instances of Speaker Client is basically multiplication of above.
    Code:
    sub main()
     
     if not hs.IsApplicationRunning("Speaker") then
          hs.launch hs.getapppath & "\speaker.exe","Main", , 0
          hs.Launch hs.getapppath & "\speaker.exe","HomePC", , 0
        end if
     
    end sub
    or
    Code:
    sub main()
     
    if not hs.IsApplicationRunning("Speaker") then
    lRet = hs.Launch(hs.GetAppPath & "\speaker.exe","Livingroom",,1)
    hs.waitSecs 60
    lRet = hs.Launch(hs.GetAppPath & "\speaker.exe","Kitchen",,1)
     
    end sub
    You will notice that there is a delay in the second example, that is not required, but may help if you have problems with the speaker clients loading. It can also be used in the first example.

    If you use these methods, although the script is checking to see if speaker client is running, I would recommend you also have HomeSeer shut them down when HomeSeer is shut down. They do not shut down automatically.

    The way to do this is in the HomeSeer shutdown script, called amazingly shutdown.txt
    Code:
    sub main()
     
    strComputer = "." 
              Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
              Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Speaker.exe'") 
              For Each objProcess in colProcessList 
                 objProcess.Terminate() 
            Next 
     
    end sub
    That will shutdown all the speaker clients running on the HomeSeer computer.

    Both those scripts are located in the script directory and you can add whatever else you wish to those scripts.

    That is the basic way to do it, however.

    If you wish HomeSeer to say "Hi I am up and running" and include it at the end of this script, it will not say it as the speaker clients have not yet started by the time the script gets to that phrase.

    Here is a way to do it.

    In the startup.txt you have.
    Code:
    sub main()
     
    dim T
    T=dateadd ("N",+2,NOW)
    hs.NewTimeEvent "Speakers",T,"",1,1,1,1,1,1,1,"",1,"Start Speakers.txt","System"
     
    end sub
    This will create an event called Speakers which will run in 2 minutes and the event will run a script called Start Speakers.txt. The System bit at the end creates it in that category.

    The script it is calling is exactly the same as all startup examples above, just has a different name. The difference is that you are giving HomeSeer two minutes to get started before firing up the speaker clients.

    Note: hs.NewTimeEvent "Speakers",T,"",1,1,1,1,1,1,1,"",1,"Start Speakers.txt","System" may appear as two lines, it is all one line.

    If you wish to change the time delay it is done in this line T=dateadd ("N",+2,NOW) The delay is set by the +2, set it to whatever you wish. BTW if you set it to -2 it will create and event which will fire tomorrow 2 mins before this script ran.
    sigpic
    A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"
    HomeSeer 3 V 3.0.0.318 with ALEXA (AKA Amazon Echo)
    BL Radar V2.0.217; BLRF V2.0.85.0; HS Touch V3.0.0.1034 X10 V3.0.0.42; PHLocation V3.0.0.38; Zwave V3.0.1.110; X10 V3.0.0.42
    BLBackup V2.0.39;ImperiHome3.0.0.20 All on Windows XP Pro
Working...
X