This is a continuation of Part 3. Here we'll delve into the details about how to Integrate the SiriProxy with a Home Automation System.

Executing a Shell Script/Command from Ruby

Dead easy:

    puts %x{UNIX COMMAND}

For example: (be careful with the path if using rvmsudo, as ~ may resolve to /home/root)

    puts %x{/home/siri/SiriProxy/TriggerEvent.sh LivingRoomLightsOn} 

Sending Message over IP

Equally simple.

    echo "message" | socat - tcp4:192.168.168.254:6969

To Install

    sudo apt-get install socat

This can be tested with the following once a listener is setup (or by running two sessions on same Linux host).

I created a script called TriggerEvent.sh to send messages. (See below)

TriggerEvent.sh

Create (or download) TriggerEvent.sh (IP and Port should match settings in listener). (I put in my SiriProxy dir, but you may want to put somewhere in search path). If you copy the file from Windows use dos2unix to fix line endings.

To create the script

    cd ~/SiriProxy
    sudo nano TriggerEvent.sh 

enter the two lines below, then save and exit. (The IP should be HomeSeer server's, and the port number should match the host in IP and Serial Plug-in. The default is 6969, so use that for now)

    #! /bin/sh
    echo "$@" | socat - tcp:192.168.168.254:6969 

Give execute permission owner and group (adjust to suit)

    chmod 774 TriggerEvent.sh

HomeSeer Configuration

  1. Download drule’s IP and Serial Plug-in: http://forums.homeseer.com/showpost.php?p=1027987&postcount=1
  2. Uncompress
  3. Copy to your HomeSeer directory (e.g. C:\Program Files (x86)\HomeSeer HSPRO)
  4. Restart HomeSeer
  5. Goto HomeSeer web -> Setup -> Interfaces . Enable the interface and Save.
  6. Click Config and setup a TCP listener

On HomeSeer, I set up a connection for my Linux server as a TCP Host. (I’m using a vbscript to process the messages, but you could setup events to handle each message if you don’t want to write a script. Just leave the script dropdown empty.)

When messages are received, the vb.net script “Siri.vb” will be executed. This checks if the message matches an event name. If it does it runs it.

Siri.vb

 1 Public Sub Main(ByVal Params As Object)
 2   Dim EventName As String = Params.ToString
 3   hs.writelog( "SiriProxy", "Data Received: " & chr(34) & EventName & chr(34))
 4     If hs.eventexists(EventName) = True Then
 5       hs.triggerevent(EventName)
 6       hs.writelog( "SiriProxy", "Triggered Event: " & chr(34) & EventName & chr(34))	
 7     Else
 8       hs.writelog( "SiriProxy", "No Event Matching " & chr(34) & EventName & chr(34) & " Exists")
 9     End If ' Event Exists
10 End Sub

Test communications

On Linux (assuming TriggerEvent.sh is installed in SiriProxy diretory), run the following command (Use your own event name). Everything after the space will be sent as a single message.

    ~/SiriProxy/TriggerEvent.sh Living Room Lights On

SiriProxy Configuration

Simple example

In this example, I send a message “Bedtime” (case sensitive) and it runs an event called “Bedtime” in HomeSeer. Note: I could match on the phrase “I’m going to bed” and send the message “Bedtime”, so you don’t need to speak actual event names.

Matching Multiple Phrases

In this example, I use an expression. This allows me to say “Basement On” or “Basement Lights On” (I’m not sure if parenthesis is required.)

Conditional Logic

In this example, Siri asks for confirmation and then acts according to the response.

Further Conditional Logic

Here, Siri asks me to choose something (e.g. arm mode) and then runs a specific event based on my choice.

After making changes, stop the server, update, and restart the server.

    siriproxy update .
    rvmsudo siriproxy server
Return to Part 3