Groovy scripting in HomeSeer (part 1)
groovy homeseer java script

Groovy scripting in HomeSeer (part 1)

I felt like fooling around with Groovy and HomeSeer, so I started investigating what the options are. Of course you can just run a command-line groovy script from within HomeSeer, that’s not a challenge. The challenge was to let the groovy script actually connect to HomeSeer.

Requisites:

  1. HomeSeer – http://www.homeseer.com/
  2. HomeSeer Speaker Client – http://www.homeseer.com/downloads/index.htm (only needed in case you want to access HomeSeer from a remote machine)
  3. Groovy – Getting started with Groovy
  4. Scriptom – Scriptom Groovy Module

If you know your way around the HomeSeer functions, it should be rather easy. Before we can connect, let’s initialize our Active-X component, using scriptom. Make sure that the groovy classloader can actually find the scriptom classes!

// importing the necessary scriptom classes
// make sure the scriptom libraries are available on classpath (eg. put them inside the .groovy/lib folder)
import org.codehaus.groovy.scriptom.ActiveXObject

def hsi = new ActiveXObject("HomeSeer2.application")
def hs = null

// configuration to connect to the homeseer host
def host = "localhost"
def user = "default"
def password = "default"

Next, we try to connect…

// Let's try to connect
println "Connecting to HomeSeer host..." 
hsi.setHost host
def ret = hsi.connect(user, password)

if (ret?.trim().length() > 0) {
	println "Error: $ret"
} else {
	println "Connection successful."
}

Then we try to do something with our hs object :). As example I just log a message, print out the uptime and version of the host, and perform a speak action.

hs = hsi.getHSRef()
hs?.writeLog("GroovyScript", "Connection successful")
println "You should see a GroovyScript log message showing in the HomeSeer console.\n"

def version = hs?.version()
def uptime = hs?.systemUpTime()
println "The HomeSeer host has version $version installed and is running for $uptime\n"
hs?.speak "Hello HomeSeer from Groovy! Powered by a www.iHomeAutomate.eu Groovy script!"

Let’s not forget to disconnect again

println "Disconnecting..."
hsi.disconnect()

This is the result:
Hello HomeSeer from Groovy

Hello HomeSeer from Groovy

The downside of starting a (command line) script like this from homeseer is that we always need to initialize a connection to homeseer. In a next part, coming up later, I’ll create a plugin for HomeSeer executing groovy scripts at runtime, making the groovy scripts a lot faster.

Here is the full HelloHomeSeerFromGroovy script as gist: