HomeSeer can be controlled remotely from any VB6 or .NET application, as well as Windows Scripting Host. Note that any application that supports COM can be used to control HomeSeer. The transport used to control HomeSeer is .NET remoting. The functionality is located in the DLL file HomeSeer2.dll.
Controlling HomeSeer from Windows Scripting Host
Save the following to a file named "hello.vbs" then run it by double clicking on the file. See the VB6 section below for more information on the properties and methods used in this script.
Dim
hs
Set
hsi = createobject("HomeSeer2.application")
hsi.SetHost "localhost"
rval = hsi.Connect("default","default")
if rval <> "" then
msgbox rval
end if
Set hs = hsi.GetHSRef
hs.speak "Hello World"
Controlling HomeSeer from a VB 6 application
To be able to control HomeSeer remotely, a reference to the HomeSeer hsapplication class needs to be obtained. Once you have a reference to this object, you can then use any of the scripting commands described in the scripting section. The following code will connect to the running instance of HomeSeer and obtain this object. This code simply makes the connection then speaks some text.
First, in your VB6 project add a reference to "HomeSeer2". You can also call CreateObject with "HomeSeer2.application". This will obtain a reference to the HomeSeer2 DLL that interfaces with HomeSeer. The "SetHost" property allows you to set the host you are connecting to. This allows your application to run on a different PC then HomeSeer is running on. The Connect method will attempt to make the connection. Note that the Connect method takes 2 parameters, username and password. This is required for security purposes. The username/password must match a user that is configured in the HomeSeer web server settings. Note that users with Guest privileges cannot connect.
Dim
h As hsapplication
Dim hsi As HomeSeer2.application
Set hsi = New HomeSeer2.application
hsi.SetHost "localhost"
s = hsi.Connect("default", "default")
If s = "" Then
MsgBox "Connected"
Set h = hsi.GetHSRef
Else
MsgBox "Error connecting: " & s
End If
'
now access HomeSeer using any of the scripting functions
' speak something
hs.speak "hello from my application"
Controlling HomeSeer from a .NET application
Note that this example assumes you are using HomeSeer version 2.1 or later and the .NET 2.0 framework.
'Required imports:
Imports HomeSeer2
'Required globals in your class:
Public
hsinterface As HomeSeer2.application
Public hsapp As Scheduler.hsapplication
' Sample button press event that connects to HomeSeer and speaks
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
hsinterface
= New HomeSeer2.application
hsinterface.SetHost("localhost")
Dim rval As String = hsinterface.Connect("default", "default")
If
rval <> "" Then
MsgBox("Unable
to connect to HomeSeer: " & rval)
Exit
Sub
Else
MsgBox("Connected")
End
If
hsapp
= hsinterface.GetHSRef
hsapp.speak("Hello
from my application")
Catch
ex As Exception
MsgBox(ex.Message)
End
Try
End
Sub