Creating Scripts
HomeSeer Scripts
One of the most powerful features of the HomeSeer product is the ability to write
scripts to control the home automation environment. Since version 2.0, HomeSeer
has been based upon the Microsoft .NET Framework version 2.0. Scripts can (and should) now be developed using VB.NET instead of the vBasic
scripting language.
Each HomeSeer .NET script is contained in it's own file with an extension of
.vb. These script files are stored in the HomeSeer script folder:
\Program Files\Homeseer 2\Scripts\. When you want HomeSeer to run a
script, usually via a HomeSeer Event, you specify the script file to run and the
subroutine (method) within the file to execute. If you do not specify a
method to run, the default is Main. Here is a typical HomeSeer
Event definition that runs a script that uses the default method of Main:
If you want to pass a parameter to the script, you must specify the method along
with the parameter. Here is a typical HomeSeer Event defintion that passes
a parameter to the method Main:
HomeSeer only supports passing a single parameter to a script method, and this
parameter is always of type String. A workaround is to pass multiple
parameters in a single string, with each parameter seperated from each other
with a defined character (typically " | "). The script must then
parse the string to seperate the individual parameters (easy to do). Here
is a typical HomeSeer Event that passes multiple parameters to the method Main:
The following shows the script SpeakAndLogMultipleParms.vb from the HomeSeer
script folder opened in Notepad:
Note how easy it is to parse out the two individual parameters that were passed
to the script.
A typical HomeSeer script contains a single method that is executed when the
script is invoked. The default method's name is Main.
However, a single script can actually have many methods, each of which can be
called from a HomeSeer Event. The Event specifies both the filename (.vb)
and the entry point (usually Main), as well as any parameters to be
passed to the method.
Creating tenScripting Scripts
tenScripting is distributed with two files of sample scripts:
SimpleSamples.vb and ComplexSamples.vb. You must add your
scripts to the project to run and debug them. You can store all of your
scripts in a single .vb file, or any number of .vb files. Do
not add your scripts to the existing sample files. To add a new script
file to the project, click on the menu item Project and then Add New
Item. A dialog will open. Click on the icon for Class, change
the Class name, and then click Add. A new .vb file has now been
added to your project. You edit this file to add your script definitions.
You can add any number of scripts to a single .vb file in tenScripting,
each of these scripts containing one or more methods that can be called from
HomeSeer Events. However, each script in HomeSeer resides in a separate .vb
file. The individual scripts within the tenScripting .vb file are
identified by wrapping Class Name and Class End
statements around each script definition. When you export a script from
tenScripting to the HomeSeer script folder, each script is placed into a
separate file (with the name from it's Class statement) and the Class
Name and Class End statements are removed. Following is
a sample tenScripting file containing three scripts:
If you were to export all three of these scripts to the HomeSeer script folder,
three separate files would be created: SpeakAndLogNoParms.vb,
SpeakAndLogOneParm.vb, and SpeadkAndLogMultipleParms.vb. Note
that each of these scripts are run with the default method of Main.
While most scripts contain a single method, usually Main, scripts can contain
multiple entry points: A single HomeSeer .vb file containing a
single script, but with multiple SUBs defined. This would be defined as a
single Class with multiple SUBs in tenScripting. In the
tenScripting
example below, a single script TwoMethods is defined with two callable methods:
ToggleFrontPorch and ToggleBackPorch. Each of these methods uses the same
Private method ToggleDevice. If two separate scripts were
used instead of a single script with two methods, then the method
ToggleDevice would have to be copied into each script.
Two HomeSeer Events are shown below that call the two methods from above: